Skip to main content

Poetry Plugin for Bundling Local Dependencies

Project description

Poetry Bundle Local Dependencies Plugin

SonarCloud Status

Vulnerabilities Bugs Code Smells Technical Debt Lines of Code

Maintainability Rating Reliability Rating Security Rating Quality Gate 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

  1. Intercept the poetry build command.
  2. Create a temporary directory.
  3. Copy all the project files to the temporary directory.
  4. Read the pyproject.toml and find the local dependencies.
  5. For each local dependency, copy the pyproject.toml::tool.poetry.packages to the temporary directory, (recursively if necessary).
  6. Let Poetry build continue as usual (pointing to the temporary directory).
  7. After the build is done, copy the generated dist package to the original directory.
  8. 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

Change Log

Project details


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.1.0.tar.gz.

File metadata

File hashes

Hashes for poetry_bundle_local_deps_plugin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6eb1f30ee514f5ccb3f53cf262eb0975d7e132403c4f7be75ae9bb38bb0a56cd
MD5 5f700f8251dedd7b67f7749f4fc65008
BLAKE2b-256 649675410abae6e6aee94393f05a4cf7600f952f0d1d8e077d7e96882dda5353

See more details on using hashes here.

File details

Details for the file poetry_bundle_local_deps_plugin-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for poetry_bundle_local_deps_plugin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ceb6d5faafae23d234f088b7e31077bff2e2c91163d3a90478c3de9bc7ecce27
MD5 f7442d062c19efc5e6a039f58d051f95
BLAKE2b-256 6b95ff0ab15cfbd6264ab709e5087e801b5a603b6bf421d8d6d90e8b89480fcc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page