Poetry Bundle Local Dependencies Plugin
SonarCloud Status
Poetry plugin to bundle local dependencies (only path, not supported git or url) into a single package.
Motivation
Poetry is a great tool to manage Python dependencies, and works perfectly when there only one pyproject in the repository, however, for many reasons, you may want to have multiple pyproject files in the same repository, and have local shared dependencies to avoid code duplication, however, when you want to distribute your package, the poetry build command generates the dist package referencing the local path, which does not work in other environments.
In some cases, you don't want to publish all the auxiliary packages, or if you are deploying your application to a Docker or an AWS Lambda, you also don't want to deal with resolving the local dependencies by yourself.
This plugin aims to solve this problem by intercepting the poetry build command and generating the dist package with the local dependencies and their dependencies bundled into a single package.
This plugin is lightweight version of @nxlv/python Nx monorepo plugin.
How it works
- Intercept the
poetry buildcommand. - Create a temporary directory.
- Copy all the project files to the temporary directory.
- Read the
pyproject.tomland find the local dependencies. - For each local dependency, copy the
pyproject.toml::tool.poetry.packagesto the temporary directory, (recursively if necessary). - Let Poetry build continue as usual (pointing to the temporary directory).
- After the build is done, copy the generated dist package to the original directory.
- Remove the temporary directory.
Example
package/a/pyproject.toml
[tool.poetry]
name = "a"
version = "0.1.0"
description = ""
[[tool.poetry.packages]]
include = "a"
[tool.poetry.dependencies]
python = "^3.12"
b = { path = "../b", develop = true }
package/b/pyproject.toml
[tool.poetry]
name = "b"
version = "0.1.0"
description = ""
[[tool.poetry.packages]]
include = "b"
[tool.poetry.dependencies]
python = "^3.12"
requests = "^2.32.3"
The standard behavior of poetry build would generate the following dist package:
a-0.1.0.dist-info/METADATA
Metadata-Version: 2.1
Name: a
Version: 0.1.0
Summary:
Requires-Python: >=3.12,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: b @ file:///Users/lucasvieira/Projects/poetry-bundle-local-deps-plugin-demo/packages/b
a-0.1.0/
- a/*.py
- PKG-INFO
- pyproject.toml
Which would not work if you try to install it in another environment.
With this plugin, the dist package would be:
a-0.1.0.dist-info/METADATA
Metadata-Version: 2.1
Name: a
Version: 0.1.0
Summary:
Requires-Python: >=3.12,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: requests (>=2.32.3,<3.0.0)
a-0.1.0/
- a/*.py
- b/*.py
- PKG-INFO
- pyproject.toml
Which would work in any environment, because all the dependencies are bundled into a single package.
Install
poetry self add poetry-bundle-local-deps-plugin
Usage
Enable the plugin in the pyproject.toml:
[tool.bundle_local_deps_config]
enabled = true
Run the poetry build command as usual.
Contributing
- See our Contributing Guide
Change Log
- See our Change Log
Metadata
Release files for poetry-bundle-local-deps-plugin 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| poetry_bundle_local_deps_plugin-0.2.1.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| poetry_bundle_local_deps_plugin-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / poetry_bundle_local_deps_plugin-0.2.1.tar.gz
| Download URL | poetry_bundle_local_deps_plugin-0.2.1.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c776d916546ee86e3649bb6ba4588169b891a58aec9d62a5cbe5a7c26f4f535
|
|
BLAKE2b-256 checksum How to use checksums |
20211c80643d5c5403b2961920e7a9d240d6fe7149f9179404cd28ee4eb04d4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / poetry_bundle_local_deps_plugin-0.2.1-py3-none-any.whl
| Download URL | poetry_bundle_local_deps_plugin-0.2.1-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e93ce8a9ff11eb4f7a69e4c43dfd9cc01a96f9b1b1ea0be0e70adf051a84ea7
|
|
BLAKE2b-256 checksum How to use checksums |
a8a5aa3f9812280f516fe64207fbcc84fd7eaa0df5f8ddd7c6cc9f1e129e7e8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|