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.0.tar.gz
.
File metadata
- Download URL: poetry_bundle_local_deps_plugin-0.2.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f902704366f48a29ffbb708bfcc3d0f6e85773d8e2ec0943abc3f2def9b96c83 |
|
MD5 | a889bd30e435ce96f22b75d0d831bab3 |
|
BLAKE2b-256 | 1c20b8b96149768f3237d291cd8e4d9fa0f3cb49baf84694a7b4c946e1bcb38d |
File details
Details for the file poetry_bundle_local_deps_plugin-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: poetry_bundle_local_deps_plugin-0.2.0-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 | 6ef1cbb9c67bfaa77a6b824bfcd05e6f093b0c1e5a7284eecb5a305235d93852 |
|
MD5 | 83fc19c252536e95f61ece46ee0e2f34 |
|
BLAKE2b-256 | 8fa25838088500545da0ec4a8acc62a73f6cb0bc655c9b72d35dcac6fd2fddd2 |