mtkennerly / poetry-dynamic-versioning

Plugin for Poetry to enable dynamic versioning based on VCS tags
MIT License
588 stars 36 forks source link
bazaar darcs dynamic-version fossil fossil-scm git mercurial pijul plugin poetry poetry-plugin python semantic-versioning subversion versioning

Dynamic versioning plugin for Poetry

This is a Python 3.7+ plugin for Poetry 1.2.0+ and Poetry Core 1.0.0+ to enable dynamic versioning based on tags in your version control system, powered by Dunamai. Many different version control systems are supported, including Git and Mercurial; please refer to the Dunamai page for the full list (and minimum supported version where applicable).

poetry-dynamic-versioning provides a build backend that patches Poetry Core to enable the versioning system in PEP 517 build frontends. When installed with the plugin feature (i.e., poetry-dynamic-versioning[plugin]), it also integrates with the Poetry CLI to trigger the versioning in commands like poetry build.

For Poetry 1.1.x, you can use an older version of poetry-dynamic-versioning (0.17.1 or earlier) that relied on a *.pth import hack, but this is no longer supported, so you should migrate to the standardized plugin and Poetry 1.2.0+.

Installation

If you've previously installed the deprecated poetry-dynamic-versioning-plugin package, be sure to uninstall it before proceeding.

Poetry still requires the tool.poetry.version field to be present in pyproject.toml, but you are encouraged to use version = "0.0.0" as a standard placeholder.

With the minimal configuration above, the plugin will automatically take effect when you run commands such as poetry build. It will update the version in pyproject.toml, then revert the change when the plugin deactivates.

The default configuration will also update any pre-existing __version__ = "0.0.0" and __version_tuple__ = (0, 0, 0) placeholders in some files. You can configure additional substitution patterns/files as needed (see below).

Configuration

In your pyproject.toml file, you may configure the following options:

Simple example:

[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "semver"

Environment variables

In addition to the project-specific configuration above, you can apply some global overrides via environment variables.

Command line mode

The plugin also has a command line mode for execution on demand. This mode applies the dynamic version to all relevant files and leaves the changes in-place, allowing you to inspect the result. Your configuration will be detected from pyproject.toml as normal, but the enable option is not necessary.

To activate this mode, either use poetry dynamic-versioning (provided by the plugin feature) or poetry-dynamic-versioning (standalone script with default features).

VCS archives

Sometimes, you may only have access to an archive of a repository (e.g., a zip file) without the full history. The plugin can still detect a version in some of these cases. Refer to the Dunamai documentation for more info.

Caveats

All of Dunamai's caveats apply. In addition to those: