Skip to content

API Reference#

pdm.backend.hooks.base #

BuildHookInterface #

Bases: Protocol

The interface definition for build hooks.

Custom hooks can implement part of the methods to provide corresponding abilities.

pdm_build_clean(context) #

An optional clean step which will be called before the build starts

Parameters:

Name Type Description Default
context Context

The context for this build

required

pdm_build_finalize(context, artifact) #

This hook will be called after the build is done, the artifact is the path to the built artifact.

Parameters:

Name Type Description Default
context Context

The context for this build

required
artifact Path

The path to the built artifact

required

pdm_build_hook_enabled(context) #

Return True if the hook is enabled for the current build and context

Parameters:

Name Type Description Default
context Context

The context for this build

required

pdm_build_initialize(context) #

This hook will be called before the build starts, any updates to the context object will be seen by the following processes. It is recommended to modify the metadata in this hook.

Parameters:

Name Type Description Default
context Context

The context for this build

required

pdm_build_update_files(context, files) #

Passed in the current file mapping of {relpath: path} for hooks to update.

Parameters:

Name Type Description Default
context Context

The context for this build

required
files dict[str, Path]

The file mapping to be included in the build artifact, where the key is the relpath inside the artifact(wheel or tarball) and the value is the local path to the file.

required

pdm_build_update_setup_kwargs(context, kwargs) #

Passed in the setup kwargs for hooks to update.

Parameters:

Name Type Description Default
context Context

The context for this build

required
kwargs dict[str, Any]

The arguments to be passed to the setup() function

required
Note

This hook will be called in the subprocess of running setup.py. Any changes made to the context won't be written back.

Context dataclass #

The context object for the build hook, which contains useful information about the building process. Custom hooks can also change the values of attributes or assign arbitrary attributes to this object.

Attributes:

Name Type Description
build_dir Path

The build directory for storing files generated during the build

dist_dir Path

The directory to store the built artifacts

kwargs dict[str, Any]

The extra args passed to the build method

builder Builder

The builder associated with this build context

config: Config property #

The parsed pyproject.toml as a Config object

config_settings: dict[str, str] property #

The config settings passed to the hook

root: Path property #

The project root directory

target: Target property #

The target to build, one of 'sdist', 'wheel', 'editable'

ensure_build_dir() #

Return the build dir and create if it doesn't exist

pdm.backend.config #

BuildConfig #

Bases: Table

The [tool.pdm.build] table

custom_hook: str | None property #

The relative path to the custom hook or None if not exists

editable_backend: str property #

Currently only two backends are supported: - editables: Proxy modules via editables - path: the legacy .pth file method(default)

excludes: list[str] property #

The excludes setting

includes: list[str] property #

The includes setting

is_purelib: bool property #

If not explicitly set, the project is considered to be non-pure if build exists.

package_dir: str property #

A directory that will be used to looking for packages.

run_setuptools: bool property #

Whether to run setuptools

source_includes: list[str] property #

The source-includes setting

wheel_data: dict[str, list[DataSpec]] property #

The wheel data configuration

Config #

The project config object for pdm backend.

Parameters:

Name Type Description Default
root Path

The root directory of the project

required
data dict[str, Any]

The parsed pyproject.toml data

required

Attributes:

Name Type Description
metadata Metadata

The project metadata from the project table

build_config BuildConfig

The build config from the tool.pdm.build table

convert_package_paths() #

Return a {package_dir, packages, package_data, exclude_package_data} dict.

for_hook(name) #

Return the config data for the given hook.

from_pyproject(root) classmethod #

Load the pyproject.toml file from the given project root.

to_coremetadata() #

Return the metadata as a Core Metadata string.

validate(data, root) classmethod #

Validate the pyproject.toml data.

write_to(path) #

Write the pyproject.toml file to the given path.

Metadata #

Bases: Table

The project metadata table

entry_points: dict[str, dict[str, str]] property #

The entry points mapping

license_files: dict[str, list[str]] property #

The license files configuration

readme_file: str | None property #

The readme file path, if not exists, returns None