Skip to main content

Setuptools Rust Tomlgen extension plugin

Project description

Setuptools plugin for generating Rust Cargo.toml Files

github actions pypi package code style: black

setuptools-rust-tomlgen is a plugin for setuptools and setuptools-rust. It adds the tomlgen_rust command which generates Rust Cargo.toml files from the contents of setup.py.

Usage

Install from pip:

$ pip install setuptools-rust-tomlgen

Create a project which contains both a setup.py file and some Rust .rs files, such as the example project.

Generate Cargo.toml files via setup.py:

$ python setup.py tomlgen_rust

Metadata

The package name will be generated from the position of the extension within the Python package. The same version is used as the one declared in setup.py or setup.cfg.

The authors list is generated after the author and author_email options from setup.py / setup.cfg, but can also be overriden using the authors key in the [tomlgen_rust] section of setup.cfg:

[tomlgen_rust]
authors =
  Jane Doe <jane@doe.name>
  John Doe <john@doe.name>

The library name is a slugified variant of the extension package name, to avoid name collisions within the build directory.

As a safety, publish = false is added to the [package] section (you wouldn't publish an automatically generated package, would you ?!).

Options

Use --force (or add force = true to the [tomlgen_rust] section of setup.cfg) to force generating a manifest even when one already exists.

Use --create-workspace to create a virtual manifest at the root of your project (next to the setup.py file) which registers all of the extensions. This way, generic cargo commands can be run without leaving the root of the project.

If --create-workspace is enabled, a .cargo/config file will also be created to force cargo to build to the temporary build directory. Use --no-config to disable.

Dependencies

To specify dependencies for all extensions, add them to the [tomlgen_rust.dependencies] section of your setuptools configuration file (setup.cfg), as you would normally in your Cargo.toml file. Here is probably a good place to add pyo3 as a dependency.

To specify per-extension dependency, create a section for each extension ([tomlgen_rust.dependencies.<DOTTEDPATH>], where <DOTTEDPATH> is the complete Python path to the extension (e.g. hello-english). Extension specific dependencies are added after global dependencies.

Note that, since all projects are built in the same directory, you can also declare all dependencies in the [tomlgen_rust.dependencies], as they will be built only once anyway.

Automatic generation at each build

If you intend to regenerate manifests everytime the library is built, you can add Cargo.toml and Cargo.lock to your .gitignore file.

Then, make sure tomlgen_rust is run before build_rust everytime by adding aliases to your setup.cfg file:

[aliases]
build_rust = tomlgen_rust -f build_rust
clean_rust = tomlgen_rust -f clean_rust
build = tomlgen_rust -f build
clean = clean_rust -f clean

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

setuptools-rust-tomlgen-1.0.0.tar.gz (11.1 kB view hashes)

Uploaded Source

Built Distribution

setuptools_rust_tomlgen-1.0.0-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page