Name | milksnake JSON |
Version |
0.1.6
JSON |
| download |
home_page | |
Summary | A python library that extends setuptools for binary extensions. |
upload_time | 2023-10-12 11:34:39 |
maintainer | |
docs_url | None |
author | Armin Ronacher |
requires_python | |
license | Apache License 2.0 |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Milksnake
<a href="https://pypi.python.org/pypi/milksnake"><img src="https://img.shields.io/pypi/v/milksnake.svg" alt=""></a>
<a href="https://travis-ci.org/getsentry/milksnake"><img src="https://travis-ci.org/getsentry/milksnake.svg?branch=master" alt=""></a>
<a href="https://github.com/getsentry/milksnake/blob/master/LICENSE"><img src="https://img.shields.io/pypi/l/milksnake.svg" alt=""></a>
Milksnake is an extension for setuptools that allows you to distribute
dynamic linked libraries in Python wheels in the most portable way imaginable.
It gives you a hook to invoke your own build process and to then take the
resulting dynamic linked library.
## Why?
There are already other projects that make Python and native libraries play
along but this one is different. Unlike other projects that build Python
extension modules the goal of this project is to build regular native libraries
that are then loaded with CFFI at runtime. Why not just use CFFI? Because
CFFI's setuptools support alone does not properly work with such wheels (it
does not provide a way to build and properly tag wheels for shared libraries) and
it does not provide a good way to invoke an external build process (like a
makefile, cargo to build rust binaries etc.)
In particular you will most likely only need two wheels for Linux, one for macs
and soon one for Windows independently of how many Python interpreters you want
to target.
## What is supported?
* Platforms: Linux, Mac, Windows
* setuptools commands: `bdist_wheel`, `build`, `build_ext`, `develop`
* `pip install --editable .`
* Universal wheels (`PACKAGE-py2.py3-none-PLATFORM.whl`); this can be disabled
with `milksnake_universal=False` in `setup()` in case the package also contains
stuff that does link against libpython.
## How?
This example shows how to build a rust project with it:
This is what a `setup.py` file looks like:
```python
from setuptools import setup
def build_native(spec):
# build an example rust library
build = spec.add_external_build(
cmd=['cargo', 'build', '--release'],
path='./rust'
)
spec.add_cffi_module(
module_path='example._native',
dylib=lambda: build.find_dylib('example', in_path='target/release'),
header_filename=lambda: build.find_header('example.h', in_path='target'),
rtld_flags=['NOW', 'NODELETE']
)
setup(
name='example',
version='0.0.1',
packages=['example'],
zip_safe=False,
platforms='any',
setup_requires=['milksnake'],
install_requires=['milksnake'],
milksnake_tasks=[
build_native
]
)
```
You then need a `rust/` folder that has a Rust library (with a crate type
of `cdylib`) and a `example/` python package.
Example `example/__init__.py` file:
```python
from example._native import ffi, lib
def test():
return lib.a_function_from_rust()
```
And a `rust/src/lib.rs`:
```rust
#[no_mangle]
pub unsafe extern "C" fn a_function_from_rust() -> i32 {
42
}
```
And the `rust/Cargo.toml`:
```toml
[package]
name = "example"
version = "0.1.0"
build = "build.rs"
[lib]
name = "example"
crate-type = ["cdylib"]
[build-dependencies]
cbindgen = "0.4"
```
And finally the build.rs file:
```rust
extern crate cbindgen;
use std::env;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let mut config: cbindgen::Config = Default::default();
config.language = cbindgen::Language::C;
cbindgen::generate_with_config(&crate_dir, config)
.unwrap()
.write_to_file("target/example.h");
}
```
Raw data
{
"_id": null,
"home_page": "",
"name": "milksnake",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Armin Ronacher",
"author_email": "armin.ronacher@active-4.com",
"download_url": "https://files.pythonhosted.org/packages/37/9c/100deced3999e748500dda3027e2a19b0074199ba27cdc5a6988d22919b8/milksnake-0.1.6.tar.gz",
"platform": "any",
"description": "# Milksnake\n\n<a href=\"https://pypi.python.org/pypi/milksnake\"><img src=\"https://img.shields.io/pypi/v/milksnake.svg\" alt=\"\"></a>\n<a href=\"https://travis-ci.org/getsentry/milksnake\"><img src=\"https://travis-ci.org/getsentry/milksnake.svg?branch=master\" alt=\"\"></a>\n<a href=\"https://github.com/getsentry/milksnake/blob/master/LICENSE\"><img src=\"https://img.shields.io/pypi/l/milksnake.svg\" alt=\"\"></a>\n\n\nMilksnake is an extension for setuptools that allows you to distribute\ndynamic linked libraries in Python wheels in the most portable way imaginable.\n\nIt gives you a hook to invoke your own build process and to then take the\nresulting dynamic linked library.\n\n## Why?\n\nThere are already other projects that make Python and native libraries play\nalong but this one is different. Unlike other projects that build Python\nextension modules the goal of this project is to build regular native libraries\nthat are then loaded with CFFI at runtime. Why not just use CFFI? Because\nCFFI's setuptools support alone does not properly work with such wheels (it\ndoes not provide a way to build and properly tag wheels for shared libraries) and\nit does not provide a good way to invoke an external build process (like a\nmakefile, cargo to build rust binaries etc.)\n\nIn particular you will most likely only need two wheels for Linux, one for macs\nand soon one for Windows independently of how many Python interpreters you want\nto target.\n\n## What is supported?\n\n* Platforms: Linux, Mac, Windows\n* setuptools commands: `bdist_wheel`, `build`, `build_ext`, `develop`\n* `pip install --editable .`\n* Universal wheels (`PACKAGE-py2.py3-none-PLATFORM.whl`); this can be disabled\n with `milksnake_universal=False` in `setup()` in case the package also contains\n stuff that does link against libpython.\n\n## How?\n\nThis example shows how to build a rust project with it:\n\nThis is what a `setup.py` file looks like:\n\n```python\nfrom setuptools import setup\n\ndef build_native(spec):\n # build an example rust library\n build = spec.add_external_build(\n cmd=['cargo', 'build', '--release'],\n path='./rust'\n )\n\n spec.add_cffi_module(\n module_path='example._native',\n dylib=lambda: build.find_dylib('example', in_path='target/release'),\n header_filename=lambda: build.find_header('example.h', in_path='target'),\n rtld_flags=['NOW', 'NODELETE']\n )\n\nsetup(\n name='example',\n version='0.0.1',\n packages=['example'],\n zip_safe=False,\n platforms='any',\n setup_requires=['milksnake'],\n install_requires=['milksnake'],\n milksnake_tasks=[\n build_native\n ]\n)\n```\n\nYou then need a `rust/` folder that has a Rust library (with a crate type\nof `cdylib`) and a `example/` python package.\n\nExample `example/__init__.py` file:\n\n```python\nfrom example._native import ffi, lib\n\n\ndef test():\n return lib.a_function_from_rust()\n```\n\nAnd a `rust/src/lib.rs`:\n\n```rust\n#[no_mangle]\npub unsafe extern \"C\" fn a_function_from_rust() -> i32 {\n 42\n}\n```\n\nAnd the `rust/Cargo.toml`:\n\n```toml\n[package]\nname = \"example\"\nversion = \"0.1.0\"\nbuild = \"build.rs\"\n\n[lib]\nname = \"example\"\ncrate-type = [\"cdylib\"]\n\n[build-dependencies]\ncbindgen = \"0.4\"\n```\n\nAnd finally the build.rs file:\n\n```rust\nextern crate cbindgen;\n\nuse std::env;\n\nfn main() {\n let crate_dir = env::var(\"CARGO_MANIFEST_DIR\").unwrap();\n let mut config: cbindgen::Config = Default::default();\n config.language = cbindgen::Language::C;\n cbindgen::generate_with_config(&crate_dir, config)\n .unwrap()\n .write_to_file(\"target/example.h\");\n}\n```\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "A python library that extends setuptools for binary extensions.",
"version": "0.1.6",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6d5b1688cbd7244f039a2c1a762e246f04f7fc3eff07932776ac9944da3ea208",
"md5": "c375b5c0a964b07406c883f2f19cf21d",
"sha256": "31e3eafaf2a48e177bb4b2dacef2c7ae8c5b2147a19c6d626209b819490e6f1d"
},
"downloads": -1,
"filename": "milksnake-0.1.6-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "c375b5c0a964b07406c883f2f19cf21d",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 11136,
"upload_time": "2023-10-12T11:34:37",
"upload_time_iso_8601": "2023-10-12T11:34:37.927704Z",
"url": "https://files.pythonhosted.org/packages/6d/5b/1688cbd7244f039a2c1a762e246f04f7fc3eff07932776ac9944da3ea208/milksnake-0.1.6-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "379c100deced3999e748500dda3027e2a19b0074199ba27cdc5a6988d22919b8",
"md5": "58e06ff52117122412efb579da3e9803",
"sha256": "0198f8932b4e136c29c0d0d490ff1bac03f82c3a7b2ee6f666e3683b64314fd9"
},
"downloads": -1,
"filename": "milksnake-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "58e06ff52117122412efb579da3e9803",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10483,
"upload_time": "2023-10-12T11:34:39",
"upload_time_iso_8601": "2023-10-12T11:34:39.781307Z",
"url": "https://files.pythonhosted.org/packages/37/9c/100deced3999e748500dda3027e2a19b0074199ba27cdc5a6988d22919b8/milksnake-0.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-12 11:34:39",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "milksnake"
}