Skip to main content

Poetry plugin to petrify a wheel's dependencies per lock file

Project description

Freeze Wheel Plugin

Poetry plugin for creating frozen wheels using lockfiles.

Why

A common issue when publishing a Python application's release into PyPI, is whether or not the dependencies specified will continue to work over time. This tends to happen due to a confluence of reasons, poor dependency specification, bad observance of semantic versioning, or poor release management by the dependency. That translates to a reality where installing an older release of the application is unlikely to work, due to changes in the underlying dependency graph.

The dependency ecosystem is both complex and fragile. The emergence of lock files to ensure repeatability is testimony both to the problem and one solution. Yet when we go to publish in the packaging ecosystem we do so with non frozen dependencies specifications not with lockfiles. That means the testing pipelines that goes to produce and validate a release is against a lockfile but the release artifact is divorced of the lockfile contents, and starts to diverge from the moment of publication.

The various language package distribution channels (npm, pypi, rubygems, etc) are used for two different primary distribution purposes, for both libraries and applications. Generally speaking the extant behavior is reasonable for a library. Libraries should be relatively liberal on their own dependencies baring perhaps major versions to minimize conflicts for applications depending on them and ideally consist of minimal dependencies graphs. But for applications distribution, repeatable and verifyable installs are fundamental goals with potentially large dependency graphs. Using a frozen dependency graph versus version specifications is the only way to ensure repeatiblity of installation over time. Fundamentally the two different distribution purposes have different audiences, ie. libraries have developers and applications as consumers, applications have users as consumers.

What

A post build / pre publish command to allow for creating wheels with frozen dependencies. Basically we update wheel metadata for Requires-Dist to replace the pyproject.toml based version specification to a frozen (ie. ==version) one based on the version from the poetry lock information.

Note we can't use poetry to publish because the frozen wheel because it uses metadata from pyproject.toml instead of frozen wheel metadata.

Optional Dependencies

Frozen wheel metadata will contain Provides-Extra entries for any extra / optional dependencies. Frozen Requires-Dist lines will specify extra names _for packages that appear only in the optional/extra dependency graph.

If a package appears as both a nested "main" dependency and also as an "extra" dependency, its Requires-Dist entry in the frozen wheel will not specify an extra name.

To define this behavior in relation to poetry's export plugin, these two flows should result in the same installed package set:

# Export Flow
poetry export -f requirements.txt > requirements.txt && pip install -r requirements.txt

# Freeze-wheel Flow
poetry build && poetry freeze-wheel && pip install my_frozen_wheel

And introducing extras:

# Export Flow
poetry export --extras gcp -f requirements.txt && pip install -r requirements.txt

# Freeze-wheel Flow
poetry build && poetry freeze-wheel && pip install my_frozen_wheel[gcp]

The difference is in when to choose which extras to install - export does that at freeze time. freeze-wheel embeds the extra context at freeze time, but defers the actual extra selection until install time.

Usage

# install plugin
poetry self add poetry-plugin-freeze

# build per normal
poetry build

# add freeze step
poetry freeze-wheel

# avoid freezing specific packages
poetry freeze-wheel --exclude boto3 -e attrs

# Note we can't use poetry to publish because it uses metadata from pyproject.toml instead
# of frozen wheel metadata.

# publish per normal
twine upload dist/*.whl

Mono-Repo Support

To support mono repos consisting of multiple libraries/applications, when creating a frozen wheel, main group dependencies specified by path can be optionally substituted out for references to their release artifact versions.

This assumes automation to run build and publish across the various subpackages, ie typically via make or just.

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

poetry_plugin_petrify-2.0.0.tar.gz (30.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

poetry_plugin_petrify-2.0.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file poetry_plugin_petrify-2.0.0.tar.gz.

File metadata

  • Download URL: poetry_plugin_petrify-2.0.0.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for poetry_plugin_petrify-2.0.0.tar.gz
Algorithm Hash digest
SHA256 5d54fba70c81797e00f4ec1ba3805ddbbbcf19273d460251fe5ad74ce96ac93e
MD5 1a102fe7b4606a0c508d7fe3740998e6
BLAKE2b-256 c5f62c8e2b069aad286d9b66226a49fb195a8f1c661a0a670601738acc74db05

See more details on using hashes here.

File details

Details for the file poetry_plugin_petrify-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for poetry_plugin_petrify-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c49aa1698914ffada2a785accb7edf91657cfa76d54471956eae86a00140c283
MD5 77ba815fe7bfc49d2fc6269e9ae79790
BLAKE2b-256 e0c9ae95a3b0e3679cd8913afb2330b6df79b466dde6471c7abd91bd7b592f78

See more details on using hashes here.

Supported by

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