Skip to main content

PDM-PEP517

This project has been renamed and re-published as pdm-backend

Yet another PEP 517 backend.

PyPI Tests pre-commit.ci status pdm-managed

This is the backend for PDM projects, while you can also use it alone. It reads the metadata of PEP 621 format and coverts it to Core metadata.

Use as PEP 517 build backend

Edit your pyproject.toml as follows:

[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"

Tool specific settings

Besides of the standard fields specified in PEP 621, PDM-PEP517 honors some other settings to change the build behavior. They should be defined under [tool.pdm.build] table:

[tool.pdm.build]
# Specify where the Python packages live.
package-dir = "src"
# File patterns to include, the paths are relative to the project root.
includes = []
# File patterns to exclude, the paths are relative to the project root.
excludes = []
# File patterns to include in source distribution and exclude in wheel distribution.
source-includes = []
# An extra script to populate the arguments of `setup()`, one can build C extensions with this script. Or a custom build() function to generate files.
setup-script = "build.py"
# If true, the setup-script will run in a generated `setup.py` file.
run-setuptools = false
# Override the Is-Purelib value in the wheel.
is-purelib = true
# Change the editable-backend: path(default) or editables
editable-backend = "editables"

You don't have to specify all of them, PDM-PEP517 can also derive these fields smartly, based on some best practices of Python packaging.

Dynamic project version

pdm-pep517 can also determine the version of the project dynamically. To do this, you need to leave the version field out from your pyproject.toml and add dynamic = ["version"]:

[project]
...
- version = "0.1.0" remove this line
+ dynamic = ["version"]

Then in [tool.pdm.version] table, specify how to get the version info. There are two ways supported:

  1. Read from a static string in the given file path:
[tool.pdm.version]
source = "file"
path = "mypackage/__init__.py"

In this way, the file MUST contain a line like:

__version__ = "0.1.0" # Single quotes and double quotes are both OK, comments are allowed.
  1. Read from SCM tag, supporting git and hg:
[tool.pdm.version]
source = "scm"

When building from a source tree where SCM is not available, you can use the env var PDM_PEP517_SCM_VERSION to pretend the version is set.

PDM_PEP517_SCM_VERSION=0.1.0 python -m build

Writing SCM version to file

You can instruct PDM-PEP517 to write back the dynamic version fetched from SCM to a file:

[tool.pdm.version]
source = "scm"
write_to = "foo/version.txt"

By default, PDM-PEP517 will just write the SCM version itself. You can provide a template as a Python-formatted string to create a syntactically correct Python assignment:

[tool.pdm.version]
source = "scm"
write_to = "foo/_version.py"
write_template = "__version__ = '{}'"

Note that PDM-PEP517 will rewrite the whole file each time, so you can't have additional contents in that file.

Custom Build Script

With custom build script, you can call other tools to generates files to be included in the wheel. Just set the setup-script field under [tool.pdm.build] table to the path of the script.

In the script, you expose a function named build, which takes two arguments:

  • src(str): the path of the source directory
  • dst(str): the path of the destination directory

Example:

def build(src, dst):
    with open(os.path.join(dst, "myfile.txt"), "w") as f:
        # Put a file in the wheel
        f.write("Hello World!")

Note that the generated file hierarchy will be preserved in the wheel: $dst/myfile.txt -> $wheel_root/myfile.txt.

When run-setuptools is true, the build function will be called in a generated setup.py file, with the setup parameters as the only argument.

Example:

def build(setup_params):
    # add ext_modules to the setup() arguments
    setup_parms.update(ext_modules=[Extension("myextension", ["myextension.c"])])

The will result in a setup() call like following:

setup(
    name="mypackage",
    # Other metadata fields
    ext_modules=[Extension("myextension", ["myextension.c"])],
)

By default, when setup-script is set, the resulted wheel will be platform-specific, but you can override this behavior by setting is-purelib to false

Supported config settings

pdm-pep517 allows passing config_settings to modify the build behavior. It use the same option convention as python setup.py bdist_wheel.

--python-tag
    Override the python implementation compatibility tag(e.g. cp37, py3, pp3)
--py-limited-api
    Python tag (cp32|cp33|cpNN) for abi3 wheel tag
--plat-name
    Override the platform name(e.g. win_amd64, manylinux2010_x86_64)

For example, you can supply these options with build:

python -m build --sdist --wheel --outdir dist/ --config-setting="--python-tag=cp37" --config-setting="--plat-name=win_amd64"

pip doesn't support passing config_settings yet, please stick to build as the recommended frontend.

License

This project is licensed under MIT license.

Metadata

Release files for pdm-pep517 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdm-pep517 1.1.4
File Size Uploaded Provenance Actions
pdm-pep517-1.1.4.tar.gz 211.7 kB Without provenance Details for pdm-pep517-1.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pdm-pep517 1.1.4
File Interpreter ABI Platform Actions
pdm_pep517-1.1.4-py3-none-any.whl Python 3 none any Details for pdm_pep517-1.1.4-py3-none-any.whl

Total release size: 428.0 kB

Release files / pdm-pep517-1.1.4.tar.gz

Download URL pdm-pep517-1.1.4.tar.gz
Size 211.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7f49121e70b42dca296fac962210dd2da07a39575fc5673137ad661633b2cf3f
BLAKE2b-256 checksum
How to use checksums
43425c8818b70fc4b25c99e56aeeb3484ede076114c8a0772675b44a3b7891cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / pdm_pep517-1.1.4-py3-none-any.whl

Download URL pdm_pep517-1.1.4-py3-none-any.whl
Size 216.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9fe65d06cf193f864ac2b38372a355450ff7f847aefc9b59e89fe2cf19f32b9
BLAKE2b-256 checksum
How to use checksums
4a873289690941662b7c77a11b68adf4c8668c1e29f17fb676fd83148efe18c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Security for pdm-pep517 1.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page