Skip to main content

Poetry Git Version Plugin

Poetry plugin to set package version based on git tag.

PyPI PyPI - Python Version

Coverage Quality Gate Status

Downloads GitLab stars GitLab last commit

Features

  • No needed installed Git
  • Git tag parsing
  • Different types of release
  • Setting found or generated version as package poetry.version
  • Maintenance of PEP 440
  • Auto-increment depending on release type
  • Command to output a new version
  • Command to update the pyproject version

Quick start

poetry self add poetry-git-version-plugin
poetry git-version # Write package version based on git tag
poetry build # Build package with version based on git tag

Configs

release_type

Determines which release type to use.

  • type: Enum
    • tag
    • alpha
    • beta
    • rc
    • post
    • dev
  • Default = "dev"

Value definition:

# Environment
export PACKAGE_VERSION_RELEASE_TYPE=dev
# pyproject.toml
[tool.poetry-git-version-plugin]
release_type = "dev"

Values:

Given: current tag - 1.2.3, distance - 4.

Possible values ​​and version result:

  • tag -> 1.2.1
  • alpha -> 1.2.1a4
  • beta -> 1.2.1b4
  • rc -> 1.2.1rc4
  • post -> 1.2.3.post4
  • dev -> 1.2.3.dev4

local

Determines whether to add locale to the version

  • type: bool
  • Default = true

Value definition:

# Environment
export PACKAGE_VERSION_LOCAL=true
# pyproject.toml
[tool.poetry-git-version-plugin]
local = true

Values:

Given: current tag - 1.2.3, distance - 4, hash - 09dc5d2d7d8132c94c9c77ac27e1f594963a8ed4.

Possible values ​​and version result:

  • false -> 1.2.1a4
  • true -> 1.2.1a4+09dc5d2

Commands

poetry git-version

$ poetry git-version # Write package version based on git tag
1.2.3.dev4+09dc5d2

poetry set-git-version

$ poetry git-version # Set new version in pyproject 
The new version has been installed: 1.2.3.dev4+09dc5d2

$ cat pyproject.toml | grep version
version = "1.2.3.dev4+09dc5d2"

Use cases

Publishing python package to pypi via poetry with version equal to git tag

.gitlab-ci.yml:

pypi:
  stage: publishing
  image: python:3.10
  tags:
    - docker
  script:
    - export PACKAGE_VERSION_RELEASE_TYPE=alpha
    - poetry self add poetry-git-version-plugin
    - poetry config repositories.pypi https://upload.pypi.org/legacy/
    - poetry config pypi-token.pypi ${PYPI_TOKEN}
    - poetry publish -r pypi --build
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  • When creating a git tag: new package with version == {TAG}
  • When pushing to CI_DEFAULT_BRANCH: new package with version == {TAG}a{N}

Publishing python package to private pypi via poetry with version equal to git tag and commit hash

.gitlab-ci.yml:

pypi:
  stage: publishing
  image: python:3.10
  tags:
    - docker
  script:
    - export PACKAGE_VERSION_RELEASE_TYPE=alpha
    - export PACKAGE_VERSION_local=true
    - poetry self add poetry-git-version-plugin
    - poetry config repositories.gitlab "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/packages/pypi"
    - poetry config http-basic.gitlab gitlab-ci-token "$CI_JOB_TOKEN"
    - poetry publish -r gitlab --build
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  • When creating a git tag: new package with version == {TAG}
  • When pushing to CI_DEFAULT_BRANCH: new package with version == {TAG}a{N}+{COMMIT_HASH}

Contribute

Issue Tracker: https://gitlab.com/rocshers/python/poetry-git-version-plugin/-/issues
Source Code: https://gitlab.com/rocshers/python/poetry-git-version-plugin

Before adding changes:

make install-dev

After changes:

make format test

Release files for poetry-git-version-plugin 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for poetry-git-version-plugin 2.0.1
File Size Uploaded
poetry_git_version_plugin-2.0.1.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for poetry-git-version-plugin 2.0.1
File Interpreter ABI Platform
poetry_git_version_plugin-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.1 kB

Release files / poetry_git_version_plugin-2.0.1.tar.gz

Download URL poetry_git_version_plugin-2.0.1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e6d743c598477c6f87287b3bb8b0d503aaeae2ca301b6dd476ca20df1d8186c4
BLAKE2b-256 checksum
How to use checksums
4b05b7b73b03a6fbf6d206c2d8499de4d5d1536a575789a54eb84842cbe9de1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.2

Release files / poetry_git_version_plugin-2.0.1-py3-none-any.whl

Download URL poetry_git_version_plugin-2.0.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba1cbac134297ac880c4e055b551923c6628b5d2ab37164a0dd0c9149f1aa854
BLAKE2b-256 checksum
How to use checksums
7d980f57126fe987f87cb3daae6c2af802442c77882840c8cc674c8d128d6042
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.2

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page