Poetry Plugin for Bundling Local Dependencies
Project description
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 build
command. - Create a temporary directory.
- Copy all the project files to the temporary directory.
- Read the
pyproject.toml
and find the local dependencies. - For each local dependency, copy the
pyproject.toml::tool.poetry.packages
to 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file poetry_bundle_local_deps_plugin-0.2.1.tar.gz
.
File metadata
- Download URL: poetry_bundle_local_deps_plugin-0.2.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c776d916546ee86e3649bb6ba4588169b891a58aec9d62a5cbe5a7c26f4f535 |
|
MD5 | f2b74f0202d1283b69bf1db6aef6df2f |
|
BLAKE2b-256 | 20211c80643d5c5403b2961920e7a9d240d6fe7149f9179404cd28ee4eb04d4d |
File details
Details for the file poetry_bundle_local_deps_plugin-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: poetry_bundle_local_deps_plugin-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e93ce8a9ff11eb4f7a69e4c43dfd9cc01a96f9b1b1ea0be0e70adf051a84ea7 |
|
MD5 | 964c704e9b17e718165333cb26731203 |
|
BLAKE2b-256 | a8a5aa3f9812280f516fe64207fbcc84fd7eaa0df5f8ddd7c6cc9f1e129e7e8e |