freshcrate
Home > Developer Tools > dunamai

dunamai

Dynamic version generation

Description

# Dunamai Dunamai is a Python 3.5+ library and command line tool for producing dynamic, standards-compliant version strings, derived from tags in your version control system. This facilitates uniquely identifying nightly or per-commit builds in continuous integration and releasing new versions of your software simply by creating a tag. Dunamai is also available as a [GitHub Action](https://github.com/marketplace/actions/run-dunamai). ## Features * Version control system support: * [Git](https://git-scm.com) (2.7.0+ is recommended, but versions as old as 1.8.2.3 will work with some reduced functionality) * [Mercurial](https://www.mercurial-scm.org) * [Darcs](http://darcs.net) * [Subversion](https://subversion.apache.org) * [Bazaar](https://bazaar.canonical.com/en) * [Fossil](https://www.fossil-scm.org/home/doc/trunk/www/index.wiki) * [Pijul](https://pijul.org) * Version styles: * [PEP 440](https://www.python.org/dev/peps/pep-0440) * [Semantic Versioning](https://semver.org) * [Haskell Package Versioning Policy](https://pvp.haskell.org) * Custom output formats * Can be used for projects written in any programming language. For Python, this means you do not need a setup.py. ## Usage ### Installation ``` pip install dunamai ``` ### CLI ```console # Suppose you are on commit g29045e8, 7 commits after the v0.2.0 tag. # Auto-detect the version control system and generate a version: $ dunamai from any 0.2.0.post7.dev0+g29045e8 # Or use an explicit VCS and style: $ dunamai from git --no-metadata --style semver 0.2.0-post.7 # Custom formats: $ dunamai from any --format "v{base}+{distance}.{commit}" v0.2.0+7.g29045e8 # If you'd prefer to frame the version in terms of progress toward the next # release rather than distance from the latest one, you can bump it: $ dunamai from any --bump 0.2.1.dev7+g29045e8 # Validation of custom formats: $ dunamai from any --format "v{base}" --style pep440 Version 'v0.2.0' does not conform to the PEP 440 style # Validate your own freeform versions: $ dunamai check 0.01.0 --style semver Version '0.01.0' does not conform to the Semantic Versioning style # More info: $ dunamai --help $ dunamai from --help $ dunamai from git --help ``` ### Library ```python from dunamai import Version, Style # Let's say you're on commit g644252b, which is tagged as v0.1.0. version = Version.from_git() assert version.serialize() == "0.1.0" # Let's say there was a v0.1.0rc5 tag 44 commits ago # and you have some uncommitted changes. version = Version.from_any_vcs() assert version.serialize() == "0.1.0rc5.post44.dev0+g644252b" assert version.serialize(metadata=False) == "0.1.0rc5.post44.dev0" assert version.serialize(dirty=True) == "0.1.0rc5.post44.dev0+g644252b.dirty" assert version.serialize(style=Style.SemVer) == "0.1.0-rc.5.post.44+g644252b" ``` The `serialize()` method gives you an opinionated, PEP 440-compliant default that ensures that versions for untagged commits are compatible with Pip's `--pre` flag. The individual parts of the version are also available for you to use and inspect as you please: ```python assert version.base == "0.1.0" assert version.stage == "rc" assert version.revision == 5 assert version.distance == 44 assert version.commit == "g644252b" assert version.dirty is True # Available if the latest tag includes metadata, like v0.1.0+linux: assert version.tagged_metadata == "linux" ``` ### Tips By default, the "v" prefix on the tag is required, unless you specify a custom tag pattern. You can either write a regular expression: * Console: ```console $ dunamai from any --pattern "(?P<base>\d+\.\d+\.\d+)" ``` * Python: ```python from dunamai import Version version = Version.from_any_vcs(pattern=r"(?P<base>\d+\.\d+\.\d+)") ``` ...or use a named preset: * Console: ```console $ dunamai from any --pattern default-unprefixed ``` * Python: ```python from dunamai import Version, Pattern version = Version.from_any_vcs(pattern=Pattern.DefaultUnprefixed) ``` You can also keep the default pattern and just specify a prefix. For example, this would match tags like `some-package-v1.2.3`: * Console: ```console $ dunamai from any --pattern-prefix some-package- ``` * Python: ```python from dunamai import Version version = Version.from_any_vcs(pattern_prefix="some-package-") ``` ### VCS archives Sometimes, you may only have access to an archive of a repository (e.g., a zip file) without the full history. Dunamai can still detect a version in some of these cases: * For Git, you can configure `git archive` to produce a file with some metadata for Dunamai. Add a `.git_archival.json` file to the root of your repository with this content: ``` { "hash-full": "$Format:%H$", "hash-short": "$Format:%h$", "timestamp": "$Format:%cI$", "refs": "$Format:%D$", "describe": "$Format:%(describe:tags=true,match=v[0-9]*)$" } ``` Add this line to your `.gitattributes` file. If you don't already have t

Release History

VersionChangesUrgencyDate
1.26.1Imported from PyPI (1.26.1)Low4/21/2026
v1.26.1* Fixed: The `highest_tag` argument was ignored in `Version.from_any_vcs()`. ([Contributed by ninoseki](https://github.com/mtkennerly/dunamai/pull/110)) * Fixed: Compatibility with Pijul `1.0.0-beta.11`.Medium4/4/2026
v1.26.0* Added `--highest-tag` option to select the numerically highest version, even if it is not the chronologically latest tag.Low2/15/2026
v1.25.0* Added `commit_prefix` option to `Version.serialize()` to insert a prefix when serializing commit IDs. * Added `escape_with` option to `Version.serialize()` to customize how branch names are escaped.Low7/4/2025
v1.24.1* Fixed: Deprecation warning from `re.sub()` using Python 3.13+. ([Contributed by emmanuel-ferdman](https://github.com/mtkennerly/dunamai/pull/103))Low5/9/2025
v1.24.0* Changed: Previously, for Git 2.7+, if the initial commit were both tagged and empty, Dunamai would raise an exception due to Git not reporting that tag in `git log --simplify-by-decoration`. Now, if a tag is missing from that list, Dunamai treats it as the oldest tag.Low5/8/2025
v1.23.2* Fixed: `Version.from_git` would fail if the `GIT_TRACE` environment variable were set, due to unexpected output from Git.Low5/6/2025
v1.23.1* Fixed: `Version.__lt__` checked if *all* fields were less than the other instance, rather than using the proper field precedence and version ordering.Low3/21/2025
v1.23.0* Added: `{major}`, `{minor}`, and `{patch}` format placeholders.Low11/18/2024
v1.22.0* Fixed: The `--ignore-untracked` CLI flag was ignored. * Added: `--commit-length` option.Low8/7/2024
v1.21.2* Fixed: Some timestamps could fail to parse on Python 3.5 and 3.6.Low6/27/2024
v1.21.1* Fixed: Distance was calculated inconsistently for Git when there were some tags and none matched the version pattern.Low5/4/2024
v1.21.0* Generally, when Dunamai can detect the VCS in use, but there's no version set yet, then Dunamai uses 0.0.0 as a fallback, unless strict mode is enabled. This is useful for new projects that do not yet have a release. However, if there were some tags and none matched the version pattern, then Dunamai would yield an error. That wouldn't be helpful for a new project with some non-version tag, and it could be incorrect for a monorepo with different tags for different packages. Now, DunamLow4/29/2024
v1.20.0* Updated `Version.bump()` to add a `smart` argument, which only bumps when `distance != 0`. This will also make `Version.serialize()` use pre-release formatting automatically, like calling `Version.serialize(bump=True)`.Low4/12/2024
v1.19.2* Fixed an exception when a Git repository had a broken ref. Git would print a warning that Dunamai failed to parse.Low2/16/2024
v1.19.1* Relaxed Python bounds from `^3.5` to `>=3.5` since Python does not follow Semantic Versioning. * Fixed some `git log` commands that did not include `-c log.showsignature=false`. ([Contributed by pdecat](https://github.com/mtkennerly/dunamai/pull/75))Low2/7/2024
v1.19.0* Added a `--path` option to inspect a directory other than the current one. The `Version.from_*` methods now also take a `path` argument.Low10/4/2023
v1.18.1* For Git 2.16+, `--decorate-refs=refs/tags/` is now specified for `git log` in case you've configured `log.excludeDecoration=refs/tags/`.Low9/22/2023
v1.18.0* Added a `vcs` attribute to `Version` to indicate which VCS was detected.Low7/10/2023
v1.17.0* The `from` command will print a warning for shallow Git repositories. This becomes an error with `--strict`. * The `Version` class has a new `concerns` field to indicate warnings with the version. Right now, the only possibility is `Concern.ShallowRepository`.Low5/19/2023
v1.16.1* Fixed outdated reference to `pkg_resources` in the docstring for `get_version`. * `CHANGELOG.md` and `tests` are now included in sdists.Low5/13/2023
v1.16.0* Updated `Version.parse` to better handle PEP 440 versions produced by Dunamai itself. Specifically, in `1.2.3.post4.dev5`, the post number becomes the distance and the dev number is ignored. In `1.2.3.dev5`, the dev number becomes the distance. * Added `increment` argument to `bump_version` and `Version.bump`. ([Contributed by legendof-selda](https://github.com/mtkennerly/dunamai/pull/54)) * Fixed Git detection when there is a "dubious ownership" error. Previously, `from git` would report thLow2/21/2023
v1.15.0* Added compatibility with Git versions as old as 1.8.2.3.Low12/2/2022
v1.14.1* Fixed Git 2.7.0 compatibility by changing `git log --no-show-signature` to `git -c log.showsignature=false log`.Low11/14/2022
v1.14.0* Added a `strict` option to prevent falling back to `0.0.0` when there are no tags. * Added support for `.git_archival.json` files created by `git archive`. * Added support for `.hg_archival.txt` files created by `hg archive`.Low11/7/2022
v1.13.2* Fixed an error when parsing Git output with `showSignature = true` configured. ([Contributed by riton](https://github.com/mtkennerly/dunamai/pull/51))Low10/14/2022
v1.13.1* Made pattern-related error messages more readable by moving the pattern after the primary message instead of mixing them.Low9/25/2022
v1.13.0* Added support for [Pijul](https://pijul.org).Low8/21/2022
v1.12.0* Added `Pattern` type for named pattern presets. Currently, this includes: * `Pattern.Default` (CLI: `--pattern default`) for the existing default. * `Pattern.DefaultUnprefixed` (CLI: `--pattern default-unprefixed`) for the existing default, but without requiring the `v` prefix. * Added `tag_branch` option (CLI: `--tag-branch`) for Git repositories. This is particularly useful for Gitflow without fast forward, where `develop` does not contain the tag history, so you can specify `--tag-brLow5/6/2022
v1.11.1* Fixed the `--bump` CLI option and the `bump` argument of `Version.serialize` bumping even on a commit with a version tag. Now, no bumping occurs on such a commit.Low4/5/2022
v1.11.0* Explicitly specified `Optional[...]` typing on arguments with a default of `None`. ([Contributed by jonathangreen](https://github.com/mtkennerly/dunamai/pull/44)) * Made `VERSION_SOURCE_PATTERN` public for consumption by other tools.Low4/5/2022
v1.10.0* Added `branch` and `timestamp` to the `Version` class, along with associated format placeholders (`branch`, `branch_escaped`, `timestamp`). Branch info is not populated for Darcs and Subversion repositories. * Fixed validation for PEP 440, where the local segment was allowed to contain any characters. * Fixed validation for Semantic Versioning, where some segments were allowed to contain these additional characters: ``` [ \ ] ^ _ ` ```Low3/9/2022
v1.9.0* Changed `Version.serialize`'s `format` argument to support passing a callback. ([Contributed by marnikow](https://github.com/mtkennerly/dunamai/pull/40)) * Added `ignore` option to `get_version()`. ([Contributed by marnikow](https://github.com/mtkennerly/dunamai/pull/39)) * Added `parser` option to `get_version()`. * Added `Version.parse()`. ([Contributed by marnikow](https://github.com/mtkennerly/dunamai/pull/41)) * Added `Version.bump()`. ([Contributed by marnikow](https://github.com/mtkLow2/20/2022
v1.8.0* Changed the build backend to poetry-core. ([Contributed by fabaff](https://github.com/mtkennerly/dunamai/pull/35)) * Clarified serialization options that are ignored when using a custom format. * Relaxed dependency range of `importlib-metadata` for compatibility with Poetry. * Added `epoch` to `Version` class, default tag pattern, and format placeholders. * Fixed PEP 440 validation to allow multiple digits in the epoch. * Improved parsing of optional pattern groups so that we don't stop cLow1/27/2022
v1.7.0* Broadened the default version tag pattern to allow more separator styles recognized in PEP 440 pre-normalized forms (`-`, `.`, and `_`). * Enhanced `serialize_pep440()` to normalize the alternative prerelease names (`alpha` -> `a`, `beta` -> `b`, `c`/`pre`/`preview` -> `rc`) and capitalizations (`RC` -> `rc`, etc). * Added a `py.typed` file for PEP-561. ([Contributed by wwuck](https://github.com/mtkennerly/dunamai/pull/25)) * Replaced `pkg_resources` dependency with `packaging` and `importlLow10/31/2021
v1.6.0* Fixed an oversight where the default version tag pattern would only find tags with exactly three parts in the base (e.g., `v1.0.0` and `v1.2.3`). This is now relaxed so that `v1`, `v1.2.3.4`, and so on are also recognized. If you prefer the old default, you can pass a custom `--pattern` on the command line or a custom `pattern` to the `Version.from_*` methods. Specifically, the previous default used `^v(?P<base>\d+\.\d+\.\d+)` instead of the new `^v(?P<base>\d+(\.\d+)*)`, but the rest of Low8/9/2021
v1.5.5* Fixed handling of Git tags that contain slashes. ([Contributed by ioben](https://github.com/mtkennerly/dunamai/pull/17))Low4/27/2021
v1.5.4* Fixed handling of Git tags that contain commas.Low1/21/2021
v1.5.3* Fixed Semantic Versioning enforcement to allow metadata segments with more than two dot-separated identifiers.Low1/13/2021
v1.5.2* For Git, avoided use of `--decorate-refs` to maintain compatibility with older Git versions.Low12/17/2020
v1.5.1* Improved ordering of Git tags, particularly when commit dates were not chronological. ([Contributed by mariusvniekerk](https://github.com/mtkennerly/dunamai/pull/9)) * Improved Subversion handling when in a subdirectory of the repository. ([Contributed by Spirotot](https://github.com/mtkennerly/dunamai/pull/10))Low12/17/2020
v1.5.0* Added the `--tagged-metadata` option and corresponding attribute on the `Version` class. ([Contributed by mariusvniekerk](https://github.com/mtkennerly/dunamai/pull/8)) * Added explicit dependency on setuptools (because of using `pkg_resources`) for environments where it is not installed by default.Low12/3/2020
v1.4.1* For Git, replaced `--porcelain=v1` with `--porcelain` to maintain compatibility with older Git versions.Low11/17/2020
v1.4.0* Added the `--bump` command line option and the `bump` argument to `Version.serialize()`. * Fixed an issue with Git annotated tag sorting. When there was a newer annotated tag A on an older commit and an older annotated tag B on a newer commit, Dunamai would choose tag A, but will now correctly choose tag B because the commit is newer. * With Git, trigger the dirty flag when there are untracked files. ([Contributed by jpc4242](https://github.com/mtkennerly/dunamai/pull/6))Low11/17/2020
v1.3.1* Fixed ambiguous reference error when using Git if a tag and branch name were identical.Low9/27/2020
v1.3.0* Previously, when there were not yet any version-like tags, the distance would be set to 0, so the only differentiator was the commit ID. Now, the distance will be set to the number of commits so far. For example: * No commits: base = 0.0.0, distance = 0 * 1 commit, no tags: base = 0.0.0, distance = 1 * 10 commits, no tags: base = 0.0.0, distance = 10Low7/4/2020
v1.2.0* Added `--debug` flag in the `from` command.Low6/12/2020
v1.1.0* Added these functions to the public API: * `serialize_pep440` * `serialize_semver` * `serialize_pvp` * `bump_version`Low3/22/2020
v1.0.0* Changed the `Version` class to align with Dunamai's own semantics instead of PEP 440's semantics. Previously, `Version` implemented all of PEP 440's features, like epochs and dev releases, even though Dunamai itself did not use epochs (unless you created your own `Version` instance with one and serialized it) and always set dev to 0 in the `from_git`/etc methods. The `serialize` method then tried to generalize those PEP 440 concepts to other versioning schemes, as in `0.1.0-epoch.1` for SLow10/27/2019
v0.9.0* Added Fossil support. * Fixed case with Git/Mercurial/Subversion/Bazaar where, if you checked out an older commit, then Dunamai would consider tags for commits both before and after the commit that was checked out. It now only considers tags for the checked out commit or one of its ancestors, making the results more deterministic. * Changed VCS detection to be based on the result of VCS commands rather than looking for VCS-specific directories/files. This avoids the risk of false positives aLow10/22/2019
v0.8.1* Fixed handling of annotated Git tags, which were previously ignored.Low8/30/2019

Dependencies & License Audit

Loading dependencies...

Similar Packages

semantic-versionA library implementing the 'SemVer' scheme.2.10.0
azure-coreMicrosoft Azure Core Library for Pythonazure-template_0.1.0b6187637
azure-mgmt-coreMicrosoft Azure Management Core Library for Pythonazure-template_0.1.0b6187637
azure-monitor-opentelemetry-exporterMicrosoft Azure Monitor Opentelemetry Exporter Client Library for Pythonazure-template_0.1.0b6187637
azure-servicebusMicrosoft Azure Service Bus Client Library for Pythonazure-template_0.1.0b6187637