Poetry plugin to get package version from git
Project description
Poetry Git Version Plugin
Poetry plugin to set package version based on git tag.
Functionality
- Git tag parsing
- Alpha version making
- Setting found or generated version as package poetry.version
- Maintenance of PEP 440
- Command to output a new 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
Dependencies
Installed Git
and:
[tool.poetry.dependencies]
python = ">=3.8"
poetry = ">=1.2.2"
Configs
make_alpha_version
If the tag is not found on the HEAD, then the version is built based on the last found tag and the HEAD.
- type: bool
- Default = true
- Example: 1.3.2a5
[tool.poetry-git-version-plugin]
make_alpha_version = true
alpha_version_format
Format for alpha version
- Type: str
- Default =
'{version}a{distance}'
- Example:
- alpha_version_format = '{version}a{distance}' ->
1.3.2a5
- alpha_version_format = '{version}a{distance}+{commit_hash}' ->
1.3.2a5+5babef6
- alpha_version_format = '{version}a{distance}' ->
- Available variables:
- version: Last found tag
- distance: Distance from last found tag to HEAD
- commit_hash: Commit hash
[tool.poetry-git-version-plugin]
alpha_version_format = '{version}a{distance}'
Ignore errors
Three variables to ignore errors
- Type: bool
- Default = true
[tool.poetry-git-version-plugin]
# Ignore mismatch error PEP 440 version format
ignore_pep440 = true
# Ignore mismatch error PEP 440 public version format
ignore_public_pep440 = true
# Ignore all errors
# including version not found errors
ignore_errors = true
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:
- 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
Change the alpha version template:
[tool.poetry-git-version-plugin]
alpha_version_format = '{version}a{distance}+{commit_hash}'
.gitlab-ci.yml:
pypi:
stage: publishing
image: python:3.10
tags:
- docker
script:
- 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
After changes:
make format test
Project details
Release history Release notifications | RSS feed
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
Close
Hashes for poetry_git_version_plugin-0.1.5a2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0074d0e73d9393f5e6ccbb49e961e88f1f3e8deee6f4b99eb4359a543f2f2a46 |
|
MD5 | fda315c9a6f8bf608529d2d639190bcc |
|
BLAKE2b-256 | c19937b839016787ad177d53d956ecb6b343109c00310c4a70e0cdf9568e19d8 |
Close
Hashes for poetry_git_version_plugin-0.1.5a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e5b1985dfc4289db3939ee71729ede4547492a4fea35853e2a96e20ab3bef59 |
|
MD5 | 2308788ce825e97497b3711808491d78 |
|
BLAKE2b-256 | 1bad84bf7516c6f52f9a023a455eea194b232b807061958f86607722a63c3e53 |