Skip to main content

PDM Build Hook for Polylith

A plugin for PDM and the Polylith Architecture.

This build hook will look for Polylith bricks in pyproject.toml and optionally re-write the imports made in the source code.

Installation

[build-system]
requires = ["pdm-backend", "pdm-polylith-bricks"]
build-backend = "pdm.backend"

The main usage of the build hook is to identify the included Polylith bricks from the pyproject.toml, and hand them over to the PDM build process. Bricks are added to a project with relative paths, from the bases and components folders in a Polylith Workspace. The hook will copy the bricks into the temporary .pdm-build folder that is created by the pdm build command. This will make the built wheel and sdist include proper paths to the source code.

Polylith Bricks are defined in the tool.polylith.bricks section of the pyproject.toml:

[tool.polylith.bricks]
"../../bases/my_namespace/my_base" = "my_namespace/my_base"
"../../components/my_namespace/my_component" = "my_namespace/my_component

Polylith documentation

the Python tools for the Polylith Architecture

The build hook also add support for building Python libraries by re-writing source code with a custom top namespace.

Why re-write code?

Building libraries is supported in the Python tools for the Polylith Architecture, but you will need to consider that code will share the same top namespace with any other library built from the same monorepo.

This can be a problem when more than one of your libraries are installed into the same virtual environment. Python libraries by default are installed in a "flat" folder structure, two libraries with the same top namespace will collide.

A Solution: add a custom top namespace during packaging of the library with PDM and this build hook.

How is this done?

The code in this repo uses AST (Abstract Syntax Tree) parsing to modify source code. The Python built-in ast module is used to parse and un-parse Python code.

What's the output from this plugin?

Without any custom namespace in the configuration: no changes in the code. Building and packaging as-is.

With a Top Namespace configuration

[tool.polylith.build]
top-namespace = "my_custom_namespace"
my_custom_namespace/
    my_namespace/
        /my_package
           __init__.py
           my_module.py

Before:

from my_namespace.my_package import my_function

After:

from my_custom_namespace.my_namespace.my_package import my_function

Polylith Documentation

the Python tools for the Polylith Architecture

Metadata

Release files for pdm-polylith-bricks 1.4.0

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-polylith-bricks 1.4.0
File Size Uploaded Provenance Actions
pdm_polylith_bricks-1.4.0.tar.gz 9.4 kB Without provenance Details for pdm_polylith_bricks-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pdm-polylith-bricks 1.4.0
File Interpreter ABI Platform Actions
pdm_polylith_bricks-1.4.0-py3-none-any.whl Python 3 none any Details for pdm_polylith_bricks-1.4.0-py3-none-any.whl

Total release size: 25.2 kB

Release files / pdm_polylith_bricks-1.4.0.tar.gz

Download URL pdm_polylith_bricks-1.4.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
376943df9e298fa967d423c40cfc3aff61cf064daf79251e2ef1568c4d98b19e
BLAKE2b-256 checksum
How to use checksums
839d7e0a977e19a74a89a76c8079b15fe4d20f7a8ba98bfefc8bb9e1f26219df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / pdm_polylith_bricks-1.4.0-py3-none-any.whl

Download URL pdm_polylith_bricks-1.4.0-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51a6e0ac44087e567e96b8f93baf6fd29be12e429b0b0dd45a90634c9be6c8f0
BLAKE2b-256 checksum
How to use checksums
d3530ed7d0fdb70ce0f682b0768e061035d641ef8d91d23c8211a906ecf6a7a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for pdm-polylith-bricks 1.4.0

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.4.0 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