Skip to main content

A Python build backend designed to wrap Python package generators into a PEP 517 compatible source tree

Project description

py-generator-build-backend

A Python build backend designed to wrap Python package generators (such as openapi-python-client) into a PEP 517 compatible source tree.

Demo

Create a new directory with a pyproject.toml:

[project]
name = "tictactoe-client"
dynamic = [
    "version",
    "dependencies",
]

[build-system]
requires = [
    "py-generator-build-backend",
]
build-backend = "py_generator_build_backend"

[tools.py-generator-build-backend]
generator = "openapi-python-client generate --url https://raw.githubusercontent.com/OAI/learn.openapis.org/refs/heads/main/examples/v3.1/tictactoe.json --output-path $GENERATOR_OUT_PATH"

The tools.py-generator-build-backend.generator is the key to making this work: this command must produce a valid PEP 517 source tree in the (not-yet-existent) directory specified by the $GENERATOR_OUT_PATH environment variable. You can interpolate other environment variables in generator if you need to.

Note: you are responsible for making sure the command you want to run is available on the PATH.

Now try to build the package: python -m build .. This should fail to build, with instructions about the build requirements you need to add to your build-system.requires. Add them and confirm that you are now able to build the package.

Congratulations, you've got a Python package! See Packaging Python Projects for possible next steps.

Notes

For performance reasons, the output of the generator is cached in platformdirs.user_cache_dir. We compute the cache entry by hashing together the contents of the entire project directory, along with all environment variables. This does a pretty good job of capturing all the "inputs" that go into generating the package, but it's not perfect: the generator could be non-deterministic, or packages could be updated in the PATH. If you care about things like this, consider adopting a hermetic build tool like nix.

(Ideally we'd have access to a scratch space that only lives as long as the build frontend is invoking this build backend, but as far as I can tell, there's no standardized mechanism for that.)

Development

Releasing

Edit version in pyproject.toml:

  • uv build
  • uv publish

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

py_generator_build_backend-1.0.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_generator_build_backend-1.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file py_generator_build_backend-1.0.1.tar.gz.

File metadata

File hashes

Hashes for py_generator_build_backend-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d05882cf20a9cec1f5cc1418a2b1e566decf7126280d54783361930b7a7f7279
MD5 5bed203436fead190926724d4556ca43
BLAKE2b-256 7e12fdcb501ae7c6d716552574609f118cbcde7e7ad003e9be280e8dc7bcb9d8

See more details on using hashes here.

File details

Details for the file py_generator_build_backend-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for py_generator_build_backend-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a53d632c7f653a88f6806797818ed4a4fd23a8a85f6e041e932611021e2176ce
MD5 f3362e65b01897e4aeb78d2ef40c175c
BLAKE2b-256 cbe217629994896d12de1b9c92e9b7cceeb7dfc1b0754e42e413603659b21866

See more details on using hashes here.

Supported by

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