Compare commits
53 Commits
0.0.1.post
...
1.0.0.post
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e226f16292 | ||
|
|
8ea6b43a73 | ||
|
|
cb213df6b6 | ||
|
|
2c87f5488d | ||
|
|
348204abb5 | ||
|
|
48114149fb | ||
|
|
5eb2f1c5cf | ||
|
|
65927077aa | ||
|
|
0c02512814 | ||
|
|
9f900ba597 | ||
|
|
97612703b7 | ||
|
|
5bb8b35c73 | ||
|
|
a6c2513d9f | ||
|
|
70ef90a529 | ||
|
|
f728842a5a | ||
|
|
4837a99ac6 | ||
|
|
3e130e6bdf | ||
|
|
d7fbf52647 | ||
|
|
f5c97757b6 | ||
|
|
3c0e5bebc2 | ||
|
|
c5962d533b | ||
|
|
e9e25793d8 | ||
|
|
17f74d6675 | ||
|
|
264c51de2e | ||
|
|
ac942480cb | ||
|
|
be9ef684e4 | ||
|
|
792666c6ec | ||
|
|
2951e70c47 | ||
|
|
63b3f25b33 | ||
|
|
cefa964a3a | ||
|
|
38cde9d700 | ||
|
|
fff52596b1 | ||
|
|
3ce09a0194 | ||
|
|
961f92d9c6 | ||
|
|
a1cf4983ff | ||
|
|
c9e6f4f436 | ||
|
|
7d9f2a7792 | ||
|
|
a223500509 | ||
|
|
04578b3066 | ||
|
|
2598a41227 | ||
|
|
4e43629dfd | ||
|
|
05093566d6 | ||
|
|
f3f3459ccf | ||
|
|
df74016945 | ||
|
|
bce35f0a60 | ||
|
|
39e7d8236c | ||
|
|
6a1331d1bf | ||
|
|
96250682ec | ||
|
|
014e8ac0d2 | ||
|
|
b74269b39b | ||
|
|
46ee6dec57 | ||
|
|
c0d5e4480c | ||
|
|
2d718d2e4c |
128
Jenkinsfile
vendored
128
Jenkinsfile
vendored
@@ -120,51 +120,132 @@ pipeline {
|
|||||||
echo("_GITEA_BASE_URL: . . . . . . . . $_GITEA_BASE_URL")
|
echo("_GITEA_BASE_URL: . . . . . . . . $_GITEA_BASE_URL")
|
||||||
echo("GIT_COMMIT:. . . . . . . . . . . $GIT_COMMIT ")
|
echo("GIT_COMMIT:. . . . . . . . . . . $GIT_COMMIT ")
|
||||||
echo("_PROJECT_USER_NAME:. . . . . . . $_PROJECT_USER_NAME")
|
echo("_PROJECT_USER_NAME:. . . . . . . $_PROJECT_USER_NAME")
|
||||||
echo("_GITEA_PROJECT_NAME: . . . . . . $_PROJECT_NAME")
|
echo("_PROJECT_NAME: . . . . . . . . . $_PROJECT_NAME")
|
||||||
echo("_MaintainerEmail:. . . . . . . . $_MaintainerEmail")
|
echo("_MaintainerEmail:. . . . . . . . $_MaintainerEmail")
|
||||||
echo("_MaintainerName:. . . . . . . . $_MaintainerName")
|
echo("_MaintainerName:. . . . . . . . $_MaintainerName")
|
||||||
|
|
||||||
sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python BUILD_ENV")
|
sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python BUILD_ENV")
|
||||||
sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python TEST_ENV")
|
sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python TEST_ENV")
|
||||||
|
sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python TOOLS_ENV")
|
||||||
|
|
||||||
sh(". ~/BUILD_ENV/bin/activate && pip install --upgrade setuptools build pip copier jinja2-slug toml \"setuptools-git-versioning<2\"")
|
sh(". ~/BUILD_ENV/bin/activate && pip install --upgrade setuptools build pip copier jinja2-slug toml \"setuptools-git-versioning<2\"")
|
||||||
|
|
||||||
|
sh(". ~/TOOLS_ENV/bin/activate && pip install simple_rest_client requests")
|
||||||
|
sh(". ~/TOOLS_ENV/bin/activate && pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master")
|
||||||
|
|
||||||
|
sh("git config --global user.email $_MaintainerEmail")
|
||||||
|
sh("git config --global user.name $_MaintainerName")
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage("GetCode") {
|
stage("GetCode") {
|
||||||
steps {
|
steps {
|
||||||
dir("gitrepo") {
|
dir("gitrepo") {
|
||||||
// manually checkout the repository, with All branches and tags
|
// manually checkout the repository, with All branches and tags
|
||||||
// => because we might need them for version and changelog computing
|
// => because we might need them for version and changelog computing
|
||||||
checkout([ $class: "GitSCM",
|
checkout([ $class: "GitSCM",
|
||||||
branches: [[name: GIT_BRANCH]],
|
branches: [[name: GIT_BRANCH]],
|
||||||
extensions: [[$class: "CloneOption", noTags: false, shallow: false, depth: 0, reference: '']],
|
extensions: [[$class: "CloneOption", noTags: false, shallow: false, depth: 0, reference: '']],
|
||||||
userRemoteConfigs: [[credentialsId: _SCMCredentials, url: GIT_URL]]])
|
userRemoteConfigs: [[credentialsId: _SCMCredentials, url: GIT_URL]]])
|
||||||
script{
|
script{
|
||||||
|
|
||||||
|
withCredentials([usernamePassword(credentialsId: _SCMCredentials, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
|
||||||
|
sh("git remote set-url origin https://${GIT_USERNAME}:${GIT_PASSWORD}@chacha.ddns.net/gitea/${_PROJECT_USER_NAME}/${_PROJECT_NAME}.git")
|
||||||
|
}
|
||||||
|
|
||||||
|
// using git to get the latest tag on this branch (before processing)
|
||||||
|
def latestTag_beforeProcessing = sh(returnStdout: true, script: "git tag --sort=-creatordate | head -n 1").trim()
|
||||||
|
echo("latestTag_beforeProcessing:. . . . . . . . . . . . $latestTag_beforeProcessing")
|
||||||
|
|
||||||
|
sh(script: """#!/bin/sh -
|
||||||
|
|. ~/TOOLS_ENV/bin/activate
|
||||||
|
|exec python - << '__EOWRAPPER__'
|
||||||
|
|
|
||||||
|
|from pygitversionhelper import gitversionhelper
|
||||||
|
|
|
||||||
|
|print(f"most recent repository tag: {gitversionhelper.tag.getLastTag()}")
|
||||||
|
|print(f"most recent repository tag: {gitversionhelper.tag.getLastTag(same_branch=True)}")
|
||||||
|
|print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag()}")
|
||||||
|
|print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag(same_branch=True)}")
|
||||||
|
|print(f"most recent repository version: {gitversionhelper.version.getLastVersion(formated_output=True)}")
|
||||||
|
|print(f'current repository version: {gitversionhelper.version.getCurrentVersion(formated_output=True,version_std="PEP440",bump_type="dev",bump_dev_strategy="post")}')
|
||||||
|
|
|
||||||
|
|__EOWRAPPER__
|
||||||
|
""".stripMargin())
|
||||||
|
|
||||||
if(_GIT_BRANCH=="master")
|
if(_GIT_BRANCH=="master")
|
||||||
{
|
{
|
||||||
if(sh(returnStdout: true, script: "git tag --points-at HEAD").trim().isEmpty())
|
if(sh(returnStdout: true, script: "git tag --points-at HEAD").trim().isEmpty())
|
||||||
{
|
{
|
||||||
error("master push/merge must have an explicit tag release number")
|
BUMPED_VERSION = sh(script: """#!/bin/sh -
|
||||||
|
|. ~/TOOLS_ENV/bin/activate
|
||||||
|
|exec python - << '__EOWRAPPER__'
|
||||||
|
|
|
||||||
|
|from pygitversionhelper import gitversionhelper
|
||||||
|
|import re
|
||||||
|
|
|
||||||
|
|lastcommit=gitversionhelper.commit.getLast(same_branch=True)
|
||||||
|
|msg=gitversionhelper.commit.getMessage(lastcommit)
|
||||||
|
|
|
||||||
|
|_match=re.search(r"\\s*(?:#)?\\s*(?<=new-tag:)(?:\\s*)(?P<TAG>\\S*)",msg)
|
||||||
|
|print(_match.group("TAG"),end="")
|
||||||
|
|
|
||||||
|
|__EOWRAPPER__
|
||||||
|
""".stripMargin(),
|
||||||
|
returnStdout: true).trim()
|
||||||
|
if(BUMPED_VERSION.isEmpty())
|
||||||
|
{
|
||||||
|
echo "master push/merge must have an explicit tag release number, stopping pipeline"
|
||||||
|
currentBuild.getRawBuild().getExecutor().doStop()
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo "new-tag requested in commit message: $BUMPED_VERSION"
|
||||||
|
|
||||||
|
sh("git tag $BUMPED_VERSION")
|
||||||
|
sh("git push origin --tags")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// using git to get the latest tag on this branch
|
sh(script: """#!/bin/sh -
|
||||||
def latestTag = sh(returnStdout: true, script: "git tag --sort=-creatordate | head -n 1").trim()
|
|. ~/TOOLS_ENV/bin/activate
|
||||||
|
|exec python - << '__EOWRAPPER__'
|
||||||
|
|
|
||||||
|
|from pygitversionhelper import gitversionhelper
|
||||||
|
|
|
||||||
|
|print(f"most recent repository tag: {gitversionhelper.tag.getLastTag()}")
|
||||||
|
|print(f"most recent repository tag: {gitversionhelper.tag.getLastTag(same_branch=True)}")
|
||||||
|
|print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag()}")
|
||||||
|
|print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag(same_branch=True)}")
|
||||||
|
|print(f"most recent repository version: {gitversionhelper.version.getLastVersion(formated_output=True)}")
|
||||||
|
|print(f'current repository version: {gitversionhelper.version.getCurrentVersion(formated_output=True,version_std="PEP440",bump_type="dev",bump_dev_strategy="post")}')
|
||||||
|
|
|
||||||
|
|__EOWRAPPER__
|
||||||
|
""".stripMargin())
|
||||||
|
|
||||||
|
latestTag = sh(script: """#!/bin/sh -
|
||||||
|
|. ~/TOOLS_ENV/bin/activate
|
||||||
|
|exec python - << '__EOWRAPPER__'
|
||||||
|
|
|
||||||
|
|from pygitversionhelper import gitversionhelper
|
||||||
|
|
|
||||||
|
|print(gitversionhelper.tag.getLastTag(same_branch=True),end ="")
|
||||||
|
|
|
||||||
|
|__EOWRAPPER__
|
||||||
|
""".stripMargin(),
|
||||||
|
returnStdout: true)
|
||||||
echo("latestTag:. . . . . . . . . . . . $latestTag ")
|
echo("latestTag:. . . . . . . . . . . . $latestTag ")
|
||||||
|
|
||||||
// using setuptools_git_versioning to get the generated version number based on Git tags and logs
|
// get current (or bumped) version number from git history
|
||||||
// TODO: read dev_template from toml
|
|
||||||
PY_PROJECT_VERSION = sh(script: """#!/bin/sh -
|
PY_PROJECT_VERSION = sh(script: """#!/bin/sh -
|
||||||
|. ~/BUILD_ENV/bin/activate
|
|. ~/TOOLS_ENV/bin/activate
|
||||||
|exec python - << '__EOWRAPPER__'
|
|exec python - << '__EOWRAPPER__'
|
||||||
|
|
|
|
||||||
|from setuptools_git_versioning import version_from_git
|
|from pygitversionhelper import gitversionhelper
|
||||||
|
|
|
|
||||||
|print(str(version_from_git(tag_filter="^\\d+\\.\\d+\\.\\d+\$",dev_template = "{tag}.post{ccount}")),end ="")
|
|print(gitversionhelper.version.getCurrentVersion(formated_output=True,version_std="PEP440",bump_type="dev",bump_dev_strategy="post"),end ="")
|
||||||
|
|
|
|
||||||
|__EOWRAPPER__
|
|__EOWRAPPER__
|
||||||
""".stripMargin(),
|
""".stripMargin(),
|
||||||
@@ -172,16 +253,20 @@ pipeline {
|
|||||||
echo("PY_PROJECT_VERSION: . . . . . . . . . $PY_PROJECT_VERSION")
|
echo("PY_PROJECT_VERSION: . . . . . . . . . $PY_PROJECT_VERSION")
|
||||||
PY_PROJECT_VERSION_STRIPPED=ExtractBaseVersion(PY_PROJECT_VERSION)
|
PY_PROJECT_VERSION_STRIPPED=ExtractBaseVersion(PY_PROJECT_VERSION)
|
||||||
|
|
||||||
|
// Manually pushing a new tag with version string guessed by gitversionhelper
|
||||||
|
// because setuptools-git-versioning cant fing tag on other branches, so will guess a wring version without this tag.
|
||||||
|
if(latestTag!=PY_PROJECT_VERSION)
|
||||||
|
{
|
||||||
|
sh("git tag $PY_PROJECT_VERSION")
|
||||||
|
sh("git push origin --tags")
|
||||||
|
}
|
||||||
|
|
||||||
// specific handling to test the template itself
|
// specific handling to test the template itself
|
||||||
// => little hacky... creating a new git repo with a commit/tag corresponding to HEAD of the official one
|
// => little hacky... creating a new git repo with a commit/tag corresponding to HEAD of the official one
|
||||||
if(_PROJECT_NAME=="pyChaChaDummyProject") //specific case to test the template itself
|
if(_PROJECT_NAME=="pyChaChaDummyProject") //specific case to test the template itself
|
||||||
{
|
{
|
||||||
sh("git config --global user.email $_MaintainerEmail")
|
|
||||||
sh("git config --global user.name $_MaintainerName")
|
|
||||||
|
|
||||||
sh("rm -Rf ~/_gitrepo || true")
|
sh("rm -Rf ~/_gitrepo || true")
|
||||||
|
|
||||||
//sh(". ~/BUILD_ENV/bin/activate && python -m copier --vcs-ref HEAD --prereleases --defaults ./ ~/_gitrepo")
|
|
||||||
sh(script: """#!/bin/sh -
|
sh(script: """#!/bin/sh -
|
||||||
|. ~/BUILD_ENV/bin/activate
|
|. ~/BUILD_ENV/bin/activate
|
||||||
|exec python - << '__EOWRAPPER__'
|
|exec python - << '__EOWRAPPER__'
|
||||||
@@ -388,13 +473,15 @@ pipeline {
|
|||||||
def GITEA_LOGIN_TOKEN=credentials("GiteaCHACHAPush")
|
def GITEA_LOGIN_TOKEN=credentials("GiteaCHACHAPush")
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh("python3 -m pip install simple_rest_client requests")
|
|
||||||
dir("gitrepo") {
|
dir("gitrepo") {
|
||||||
script {
|
script {
|
||||||
def CurrentDateTime=java.time.LocalDateTime.now()
|
def CurrentDateTime=java.time.LocalDateTime.now()
|
||||||
withCredentials([string( credentialsId: _MkDocsWebCredentials,variable: 'MKDOCSTOKEN' )])
|
withCredentials([string( credentialsId: _MkDocsWebCredentials,variable: 'MKDOCSTOKEN' )])
|
||||||
{
|
{
|
||||||
sh(script: """#!/usr/bin/env python3
|
sh(script: """#!/bin/sh -
|
||||||
|
|. ~/TOOLS_ENV/bin/activate
|
||||||
|
|exec python - << '__EOWRAPPER__'
|
||||||
|
|
|
||||||
|from simple_rest_client.api import API
|
|from simple_rest_client.api import API
|
||||||
|from simple_rest_client.resource import Resource
|
|from simple_rest_client.resource import Resource
|
||||||
|import json
|
|import json
|
||||||
@@ -478,8 +565,9 @@ pipeline {
|
|||||||
|response=requests.post("http://${_MkDocsWebURL}/API.php?REQ=pushDoc",data=reqData,files=files)
|
|response=requests.post("http://${_MkDocsWebURL}/API.php?REQ=pushDoc",data=reqData,files=files)
|
||||||
|if response.status_code != 200:
|
|if response.status_code != 200:
|
||||||
| raise RuntimeError(f"Wrong server response: {response.status_code}")
|
| raise RuntimeError(f"Wrong server response: {response.status_code}")
|
||||||
|
|
|
|
||||||
""".stripMargin())
|
|__EOWRAPPER__
|
||||||
|
""".stripMargin())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
59
README.md
59
README.md
@@ -3,46 +3,33 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
# Python project template
|
# pyGitVersionHelper
|
||||||
|
|
||||||
A nice template to start a blank python projet.
|
_A tiny library to help versioning management of git python projects_
|
||||||
|
|
||||||
This template automate a lot of handy things and allow CI/CD automatic releases generation.
|
|
||||||
|
|
||||||
It is also collectings data to feed Jenkins build.
|
Because a good developer is a lazy developer and version management in CI/CD can be very time consuming.
|
||||||
|
|
||||||
Checkout [Latest Documentation](https://chacha.ddns.net/mkdocs-web/chacha/pychachadummyproject/{{branch}}/latest/).
|
|
||||||
|
Checkout [Latest Documentation](https://chacha.ddns.net/mkdocs-web/chacha/pygitversionhelper/{{branch}}/latest/).
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
- list tags
|
||||||
### Generic pipeline skeleton:
|
- get last tag
|
||||||
- Prepare
|
- get last version
|
||||||
- GetCode
|
- get current version (bumped)
|
||||||
- BuildPackage
|
- convert / switch from SemVer to PEP440 (both ways)
|
||||||
- Install
|
- automatic version format detection (SemVer by default)
|
||||||
- CheckCode
|
|
||||||
- PlotMetrics
|
|
||||||
- RunUnitTests
|
|
||||||
- GenDOC
|
|
||||||
- PostRelease
|
|
||||||
|
|
||||||
### CI/CD Environment
|
## Options
|
||||||
- Jenkins
|
- restrict to same branch
|
||||||
- Gitea (with patch for dynamic Readme variables: https://chacha.ddns.net/gitea/chacha/GiteaMarkupVariable)
|
- both SemVer and PEP440 support
|
||||||
- Docker
|
- custom output format
|
||||||
- MkDocsWeb
|
- configurable default bump type major, minor, patch or dev
|
||||||
|
- configurable default bump type: post, pre-patch, pre-minor, pre-major
|
||||||
### CI/CD Helper libs
|
- ignore non-version tag
|
||||||
- VirtualEnv
|
- force version format
|
||||||
- Changelog generation based on commits
|
|
||||||
- copier
|
|
||||||
- pylint + pylint_json2html
|
|
||||||
- mypy
|
|
||||||
- unittest + xmlrunner + junitparser + junit2htmlreport
|
|
||||||
- mkdocs
|
|
||||||
|
|
||||||
### Python project
|
## Process
|
||||||
- Full .toml implementation
|
- full CI/CD developpment: Gitea / Jenkins + few python libs (pytlint, coverage, unittest, mkdocs)
|
||||||
- .whl automatic generation
|
- documentation generated mkdocs and self-hosted
|
||||||
- dynamic versionning using git repository
|
- CI/CD on Linux, manually tested in Windows environnement
|
||||||
- embedded unit-test
|
|
||||||
@@ -1,16 +1,128 @@
|
|||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
## Pulvinar dolor
|
## Installation
|
||||||
Donec dapibus est fermentum justo volutpat condimentum. Integer quis nunc neque. Donec dictum vehicula justo, in facilisis ex tincidunt in.
|
|
||||||
Vivamus sollicitudin sem dui, id mollis orci facilisis ut. Proin sed pulvinar dolor. Donec volutpat commodo urna imperdiet pulvinar. Fusce eget aliquam risus.
|
|
||||||
Vivamus viverra luctus ex, in finibus mi. Nullam elementum dapibus mollis. Ut suscipit volutpat ex, quis feugiat lacus consectetur eu.
|
|
||||||
|
|
||||||
## Condimentum faucibus
|
From master repository:
|
||||||
Quisque auctor egestas sem, luctus suscipit ex maximus vitae. Duis facilisis augue et condimentum faucibus.
|
|
||||||
Donec cursus, enim a sagittis egestas, lectus lorem eleifend libero, at tincidunt leo magna at libero.
|
|
||||||
Nunc eros velit, suscipit luctus tempor vel, finibus et est. Curabitur efficitur pretium pulvinar.
|
|
||||||
Donec urna lectus, vulputate quis turpis sed, placerat congue urna. Phasellus aliquet fermentum quam, non auctor elit porta nec. Morbi eu ligula at nisl ultricies condimentum vitae id ante.
|
|
||||||
|
|
||||||
## Aliquam lacinia
|
python -m pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master
|
||||||
In volutpat lorem ex, et fringilla nibh faucibus quis. Mauris et arcu elementum, auctor dui vitae, egestas arcu. Duis sit amet aliquam quam.
|
|
||||||
Phasellus a odio turpis. Etiam tristique mi eu enim varius, eget facilisis est vestibulum. Aliquam lacinia nec purus sed luctus. Cras at laoreet erat.
|
From local .whl file:
|
||||||
|
|
||||||
|
python -m pip install pygitversionhelper-<VERSION>-py3-none-any.whl
|
||||||
|
|
||||||
|
From public repository:
|
||||||
|
|
||||||
|
TBD
|
||||||
|
|
||||||
|
## Import in your project
|
||||||
|
|
||||||
|
Add this line on the top of your python script:
|
||||||
|
|
||||||
|
#from pygitversionhelper import gitversionhelper
|
||||||
|
|
||||||
|
[optionnal] If you need to catch exception from this module:
|
||||||
|
|
||||||
|
#from pygitversionhelper import gitversionhelperException
|
||||||
|
|
||||||
|
## Basic API
|
||||||
|
|
||||||
|
All the API commands are static so it is not needed to create instantiate any object.
|
||||||
|
|
||||||
|
They are all executed in the current active directory.
|
||||||
|
|
||||||
|
One easy way to change directory:
|
||||||
|
|
||||||
|
import os
|
||||||
|
os.chdir("<YOUR DIRECTORY>")
|
||||||
|
|
||||||
|
### sublib: repository
|
||||||
|
|
||||||
|
To check if a repository is dirty:
|
||||||
|
|
||||||
|
if gitversionhelper.repository.isDirty():
|
||||||
|
print("repository is dirty")
|
||||||
|
|
||||||
|
### sublib: tag
|
||||||
|
|
||||||
|
List all tags [default to taggerdate order]:
|
||||||
|
|
||||||
|
for tag in gitversionhelper.tag.getTags():
|
||||||
|
print(f"found tag: {tag}")
|
||||||
|
|
||||||
|
List all tags [using git refname order]:
|
||||||
|
|
||||||
|
for tag in gitversionhelper.tag.getTags("v:refname"):
|
||||||
|
print(f"found tag: {tag}")
|
||||||
|
|
||||||
|
Get the last tag:
|
||||||
|
|
||||||
|
print(f"most recent repository tag: {gitversionhelper.tag.getLastTag()}")
|
||||||
|
|
||||||
|
Get the last tag [only on same branch]:
|
||||||
|
|
||||||
|
print(f"most recent repository tag: {gitversionhelper.tag.getLastTag(same_branch=True)}")
|
||||||
|
|
||||||
|
|
||||||
|
Get the distance from HEAD to last tag:
|
||||||
|
|
||||||
|
print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag()}")
|
||||||
|
|
||||||
|
Get the distance from HEAD to last tag [only on same branch]:
|
||||||
|
|
||||||
|
print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag(same_branch=True)}")
|
||||||
|
|
||||||
|
### sublib: version
|
||||||
|
|
||||||
|
Get the last found version in the repository [return MetaVersion object]:
|
||||||
|
|
||||||
|
print(f"most recent repository version: {gitversionhelper.version.getLastVersion()}")
|
||||||
|
|
||||||
|
Get the last found version in the repository [return formated string]:
|
||||||
|
|
||||||
|
print(f"most recent repository version: {gitversionhelper.version.getLastVersion(formated_output=True)}")
|
||||||
|
|
||||||
|
Others kwargs available to this function:
|
||||||
|
|
||||||
|
* version_std: string to force a version standard for rendering ["PEP440" or "SemVer"]
|
||||||
|
* same_branch: boolean to force searching on same branch
|
||||||
|
* ignore\_unknown\_tags: boolean to allow unknown tag to be ignored
|
||||||
|
|
||||||
|
Get the current version of the repository, automatically bump it if the last one is not tagged [returns MetaVersion object]:
|
||||||
|
|
||||||
|
print(f"current repository version: {gitversionhelper.version.getCurrentVersion()}")
|
||||||
|
|
||||||
|
Or with formated output:
|
||||||
|
|
||||||
|
print(f"current repository version: {gitversionhelper.version.getCurrentVersion(formated_output=True)}")
|
||||||
|
|
||||||
|
Typical usage in CI/CD env:
|
||||||
|
|
||||||
|
bumped_version = gitversionhelper.version.getCurrentVersion( formated_output=True, \
|
||||||
|
version_std="PEP440", \
|
||||||
|
bump_type="dev", \
|
||||||
|
bump_dev_strategy="post")
|
||||||
|
print(f"current repository version: {bumped_version}")
|
||||||
|
|
||||||
|
kwargs available to this function:
|
||||||
|
|
||||||
|
* All same args as getLastVersion()
|
||||||
|
* bump_type: if version need to be pump, allow to configure next release update type: __major, minor, patch, dev__
|
||||||
|
* bump\_dev\_strategy: if bump\_type is dev, allow to choose dev update strategy: __post, pre-patch, pre-minor, pre-major__
|
||||||
|
|
||||||
|
A version object can also be manually formated:
|
||||||
|
|
||||||
|
_version = gitversionhelper.tag.getCurrentVersion()
|
||||||
|
_version.doFormatVersion()
|
||||||
|
#or
|
||||||
|
gitversionhelper.version.doFormatVersion(_version)
|
||||||
|
|
||||||
|
kwargs available to those function:
|
||||||
|
- output_format: string to choose a rendering format ["Auto","PEP440" or "SemVer"]
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
There is unfortunately some technical limitation :
|
||||||
|
|
||||||
|
* MultiThreading and async behavior is not tested.
|
||||||
|
* Multiple tag on the same commit is not supported.
|
||||||
|
* Branch filter when searching for a version is only tested with -no-ff strategy
|
||||||
@@ -61,7 +61,7 @@ class quality_check(helper_withresults_base):
|
|||||||
'--ignore=_version.py',
|
'--ignore=_version.py',
|
||||||
'--reports=y',
|
'--reports=y',
|
||||||
'--score=yes',
|
'--score=yes',
|
||||||
'--max-line-length=120',
|
'--max-line-length=140',
|
||||||
'src.' + cls.pyproject['project']['name']], exit=False)
|
'src.' + cls.pyproject['project']['name']], exit=False)
|
||||||
|
|
||||||
with open(cls.get_result_dir()/"report.json","w+", encoding='utf-8') as Outfile:
|
with open(cls.get_result_dir()/"report.json","w+", encoding='utf-8') as Outfile:
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ classifiers = [
|
|||||||
]
|
]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
'importlib-metadata; python_version<"3.9"',
|
'importlib-metadata; python_version<"3.9"',
|
||||||
|
'packaging'
|
||||||
]
|
]
|
||||||
dynamic = ["version"]
|
dynamic = ["version"]
|
||||||
|
|
||||||
@@ -49,10 +50,6 @@ where = ["src"]
|
|||||||
[tool.setuptools.package-data]
|
[tool.setuptools.package-data]
|
||||||
"pygitversionhelper.data" = ["*.*"]
|
"pygitversionhelper.data" = ["*.*"]
|
||||||
|
|
||||||
#[tool.setuptools_scm]
|
|
||||||
#write_to = "src/pygitversionhelper/_version.py"
|
|
||||||
#version_scheme = "python-simplified-semver"
|
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Homepage = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper"
|
Homepage = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper"
|
||||||
Documentation = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper/wiki"
|
Documentation = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper/wiki"
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ except PackageNotFoundError: # pragma: no cover
|
|||||||
warnings.warn("can not read __version__, assuming local test context, setting it to ?.?.?")
|
warnings.warn("can not read __version__, assuming local test context, setting it to ?.?.?")
|
||||||
__version__ = "?.?.?"
|
__version__ = "?.?.?"
|
||||||
|
|
||||||
from .gitversionhelper import gitversionhelper
|
from .gitversionhelper import gitversionhelper, gitversionhelperException
|
||||||
|
|||||||
@@ -1,317 +1,663 @@
|
|||||||
|
# pygitversionhelper (c) by chacha
|
||||||
|
#
|
||||||
|
# pygitversionhelper is licensed under a
|
||||||
|
# Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Unported License.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the license along with this
|
||||||
|
# work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
|
||||||
|
"""
|
||||||
|
This project try to help doing handy operations with git when
|
||||||
|
dealing with project versioning and tags on python project -
|
||||||
|
at leat for project using PEP440 or SemVer standards.
|
||||||
|
|
||||||
|
One requirement is to keep it compact and to not cover too much fancy features.
|
||||||
|
This is the reason why it is one single file with nested classes.
|
||||||
|
|
||||||
|
=> Design is on-purpose poorly expandable to keep the scope light.
|
||||||
|
|
||||||
|
This library is maid for repository using tag as version.
|
||||||
|
Support for non-version tags is optional and not well tested.
|
||||||
|
|
||||||
|
This module is the main project file, containing all the code.
|
||||||
|
|
||||||
|
Read the read me for more information.
|
||||||
|
Check the unittest s for usage samples.
|
||||||
|
|
||||||
|
Note: _Other Parameters_ are **kwargs
|
||||||
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
import logging
|
||||||
|
|
||||||
from packaging.version import VERSION_PATTERN as packaging_VERSION_PATTERN
|
from packaging.version import VERSION_PATTERN as packaging_VERSION_PATTERN
|
||||||
|
|
||||||
if TYPE_CHECKING: # Only imports the below statements during type checking
|
def _exec(cmd: str, root: str | os.PathLike | None = None, raw:bool = False) -> list[str]:
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
def _exec(cmd: str, root: str | os.PathLike | None = None) -> list[str]:
|
|
||||||
"""
|
"""
|
||||||
Helper function to handle system cmd execution
|
helper function to handle system cmd execution
|
||||||
Args:
|
Args:
|
||||||
cmd: command line to be executed
|
cmd: command line to be executed
|
||||||
root: root directory where the command need to be executed
|
root: root directory where the command need to be executed
|
||||||
Return:
|
Returns:
|
||||||
a list of command's return lines
|
a list of command's return lines
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
p = subprocess.run(cmd, text=True, cwd=root, capture_output=True, check=False, timeout=2,shell=True)
|
||||||
stdout = subprocess.check_output(cmd, shell=True, text=True, cwd=root)
|
if re.search("not a git repository",p.stderr):
|
||||||
except subprocess.CalledProcessError as e:
|
raise gitversionhelper.repository.notAGitRepository()
|
||||||
stdout = e.output
|
if re.search("fatal:",p.stderr): #pragma: nocover
|
||||||
lines = stdout.splitlines()
|
raise gitversionhelper.unknownGITFatalError(p.stderr)
|
||||||
|
if int(p.returncode) < 0: #pragma: nocover
|
||||||
|
raise gitversionhelper.unknownGITError(p.stderr)
|
||||||
|
|
||||||
|
if raw:
|
||||||
|
return p.stdout
|
||||||
|
lines = p.stdout.splitlines()
|
||||||
return [line.rstrip() for line in lines if line.rstrip()]
|
return [line.rstrip() for line in lines if line.rstrip()]
|
||||||
|
|
||||||
class gitversionhelper: # pylint: disable=too-few-public-methods
|
class gitversionhelperException(Exception):
|
||||||
"""
|
"""
|
||||||
Main gitversionhelper class
|
general Module Exception
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||||
|
"""
|
||||||
|
main gitversionhelper class
|
||||||
|
"""
|
||||||
|
class wrongArguments(gitversionhelperException):
|
||||||
|
"""
|
||||||
|
wrong argument generic exception
|
||||||
|
"""
|
||||||
|
|
||||||
|
class unknownGITError(gitversionhelperException):
|
||||||
|
"""
|
||||||
|
unknown git error generic exception
|
||||||
|
"""
|
||||||
|
|
||||||
|
class unknownGITFatalError(unknownGITError):
|
||||||
|
"""
|
||||||
|
unknown fatal git error generic exception
|
||||||
|
"""
|
||||||
|
|
||||||
class repository:
|
class repository:
|
||||||
"""
|
"""
|
||||||
class containing methods focusing on repository
|
class containing methods focusing on repository
|
||||||
"""
|
"""
|
||||||
|
class repositoryException(gitversionhelperException):
|
||||||
|
"""
|
||||||
|
generic repository exeption
|
||||||
|
"""
|
||||||
|
|
||||||
|
class notAGitRepository(repositoryException):
|
||||||
|
"""
|
||||||
|
not a git repository exception
|
||||||
|
"""
|
||||||
|
|
||||||
|
class repositoryDirty(repositoryException):
|
||||||
|
"""
|
||||||
|
dirty repository exception
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def isDirty(cls) -> bool:
|
def isDirty(cls) -> bool:
|
||||||
"""
|
"""
|
||||||
Check if the repository is in dirty state
|
check if the repository is in dirty state
|
||||||
Return:
|
Returns:
|
||||||
True if it is dirty
|
True if it is dirty
|
||||||
"""
|
"""
|
||||||
return True if _exec(f"git status --short") else False
|
return bool(_exec("git status --short"))
|
||||||
|
class commit:
|
||||||
|
"""
|
||||||
|
class containing methods focusing on commits
|
||||||
|
"""
|
||||||
|
__OptDict = {"same_branch": "same_branch",
|
||||||
|
"merged_output":"merged_output"}
|
||||||
|
|
||||||
|
class commitException(gitversionhelperException):
|
||||||
|
"""
|
||||||
|
generic commit exception
|
||||||
|
"""
|
||||||
|
|
||||||
|
class commitNotFound(commitException):
|
||||||
|
"""
|
||||||
|
tag not found exception
|
||||||
|
"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getMessagesSinceTag(cls,tag:str,**kwargs) -> str:
|
||||||
|
"""
|
||||||
|
retrieve a commits message history from repository
|
||||||
|
from LastCommit to the given tag
|
||||||
|
Keyword Arguments:
|
||||||
|
merged_output: output one single merged string
|
||||||
|
same_branch(bool): force searching only in the same branch
|
||||||
|
Returns:
|
||||||
|
the commit message
|
||||||
|
"""
|
||||||
|
current_commit_id=cls.getLast(**kwargs)
|
||||||
|
tag_commit_id=cls.getFromTag(tag)
|
||||||
|
|
||||||
|
if ((cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True)):
|
||||||
|
commits = _exec(f"git rev-list --first-parent --ancestry-path {tag_commit_id}..{current_commit_id}")
|
||||||
|
else:
|
||||||
|
commits = _exec(f"git rev-list --ancestry-path {tag_commit_id}..{current_commit_id}")
|
||||||
|
result=[]
|
||||||
|
for commit in commits:
|
||||||
|
result.append(cls.getMessage(commit))
|
||||||
|
|
||||||
|
if ((cls.__OptDict["merged_output"] in kwargs) and (kwargs[cls.__OptDict["merged_output"]] is True)):
|
||||||
|
print("JOIN")
|
||||||
|
return os.linesep.join(result)
|
||||||
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getMessage(cls, commit_hash:str) -> str:
|
||||||
|
"""
|
||||||
|
retrieve a commit message from repository
|
||||||
|
Args:
|
||||||
|
commit_hash: id of the commit
|
||||||
|
Returns:
|
||||||
|
the commit message
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
res=_exec(f"git log -z --pretty=\"tformat:%B%-C()\" -n 1 {commit_hash}",None,True).rstrip('\x00')
|
||||||
|
except gitversionhelper.unknownGITFatalError as _e:
|
||||||
|
raise cls.commitNotFound("no commit found in commit history") from _e
|
||||||
|
|
||||||
|
return res.replace('\r\n','\n').replace('\n','\r\n')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getFromTag(cls,tag:str) -> str:
|
||||||
|
"""
|
||||||
|
retrieve a commit from repository associated to a tag
|
||||||
|
Args:
|
||||||
|
tag: tag of the commit
|
||||||
|
Returns:
|
||||||
|
the commit Id
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
res=_exec(f"git rev-list -n 1 {tag}")
|
||||||
|
except gitversionhelper.unknownGITFatalError as _e:
|
||||||
|
raise cls.commitNotFound("no commit found in commit history") from _e
|
||||||
|
if len(res)==0:
|
||||||
|
raise cls.commitNotFound("no commit found in commit history")
|
||||||
|
return res[0]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getLast(cls,**kwargs) -> str:
|
||||||
|
"""
|
||||||
|
retrieve last commit from repository
|
||||||
|
Keyword Arguments:
|
||||||
|
same_branch(bool): force searching only in the same branch
|
||||||
|
Returns:
|
||||||
|
the commit Id
|
||||||
|
"""
|
||||||
|
if ((cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True)):
|
||||||
|
try:
|
||||||
|
res = _exec("git rev-parse HEAD")
|
||||||
|
except gitversionhelper.unknownGITFatalError as _e:
|
||||||
|
raise cls.commitNotFound("no commit found in commit history") from _e
|
||||||
|
else:
|
||||||
|
res = _exec("git for-each-ref --sort=-committerdate refs/heads/ --count 1 --format=\"%(objectname)\"")
|
||||||
|
|
||||||
|
if len(res)==0:
|
||||||
|
raise cls.commitNotFound("no commit found in commit history")
|
||||||
|
return res[0]
|
||||||
|
|
||||||
class tag:
|
class tag:
|
||||||
"""
|
"""
|
||||||
class containing methods focusing on tags
|
class containing methods focusing on tags
|
||||||
"""
|
"""
|
||||||
__OptDict = {"same_branch": "same_branch"}
|
__OptDict = {"same_branch": "same_branch"}
|
||||||
__validGitTagSort=["","v:refname","-v:refname","taggerdate","committerdate","-taggerdate","-committerdate"]
|
__validGitTagSort=["","v:refname","-v:refname","taggerdate","committerdate","-taggerdate","-committerdate"]
|
||||||
|
|
||||||
|
class tagException(gitversionhelperException):
|
||||||
|
"""
|
||||||
|
generic tag exception
|
||||||
|
"""
|
||||||
|
|
||||||
|
class tagNotFound(tagException):
|
||||||
|
"""
|
||||||
|
tag not found exception
|
||||||
|
"""
|
||||||
|
|
||||||
|
class moreThanOneTag(tagException):
|
||||||
|
"""
|
||||||
|
more than one tag exception
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getTags(cls,sort:str = "version:refname") -> list[str]:
|
def getTags(cls,sort:str = "taggerdate",**kwargs) -> list[str|None]:
|
||||||
"""
|
"""
|
||||||
retrieve all tags from a repository
|
retrieve all tags from a repository
|
||||||
Args:
|
Args:
|
||||||
sort: sorting constraints (git format)
|
sort: sorting constraints (git format)
|
||||||
Return:
|
Returns:
|
||||||
the tags list
|
the tags list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if sort not in cls.__validGitTagSort:
|
if sort not in cls.__validGitTagSort:
|
||||||
raise RuntimeError("sort option not in allowed list")
|
raise gitversionhelper.wrongArguments("sort option not in allowed list")
|
||||||
return _exec(f"git tag -l --sort={sort}")
|
|
||||||
|
if ((cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True)):
|
||||||
|
currentBranch = _exec("git rev-parse --abbrev-ref HEAD")
|
||||||
|
return list(reversed(_exec(f"git tag --merged {currentBranch[0]} --sort={sort}")))
|
||||||
|
return list(reversed(_exec(f"git tag -l --sort={sort}")))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getLastTag(cls,**kwargs) -> Union[str,None]:
|
def getLastTag(cls,**kwargs) -> str | None:
|
||||||
f"""
|
"""
|
||||||
retrieve the last tag from a repository
|
retrieve the last tag from a repository
|
||||||
Arguments:
|
Keyword Arguments:
|
||||||
sort: sorting constraints (git format)
|
same_branch(bool): force searching only in the same branch
|
||||||
Kwargs:
|
Returns:
|
||||||
{cls.__OptDict["same_branch"]}: force searching only in the same branch
|
|
||||||
Return:
|
|
||||||
the tag
|
the tag
|
||||||
"""
|
"""
|
||||||
if ((cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True)):
|
if ((cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True)):
|
||||||
return _exec("git describe --tags --abbrev=0")[0]
|
res = _exec("git describe --tags --first-parent --abbrev=0")
|
||||||
tag = _exec("git rev-list --tags --max-count=1")
|
else:
|
||||||
return _exec(f"git describe --tags {tag[0]}")[0]
|
res = _exec("git rev-list --tags --date-order --max-count=1")
|
||||||
|
if len(res)==1:
|
||||||
|
res = _exec(f"git describe --tags {res[0]}")
|
||||||
|
|
||||||
|
if len(res)==0:
|
||||||
|
raise cls.tagNotFound("no tag found in commit history")
|
||||||
|
if len(res)!=1: #pragma: nocover
|
||||||
|
raise cls.moreThanOneTag("multiple tags on same commit is unsupported")
|
||||||
|
return res[0]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getDistanceFromTag(cls,tag=None,**kwargs) -> int:
|
def getDistanceFromTag(cls,tag:str=None,**kwargs) -> int:
|
||||||
f"""
|
"""
|
||||||
retrieve the distance from tag in the repository
|
retrieve the distance between HEAD and tag in the repository
|
||||||
Arguments:
|
Arguments:
|
||||||
tag: reference tag, if None the most recent one will be used
|
tag: reference tag, if None the most recent one will be used
|
||||||
Kwargs:
|
Keyword Arguments:
|
||||||
{cls.__OptDict["same_branch"]}: force searching only in the same branch
|
same_branch(bool): force searching only in the same branch
|
||||||
Return:
|
Returns:
|
||||||
the tag
|
the tag
|
||||||
"""
|
"""
|
||||||
if (tag is None):
|
if tag is None:
|
||||||
tag = cls.getLastTag(**kwargs)
|
tag = cls.getLastTag(**kwargs)
|
||||||
return int(_exec(f"git rev-list {tag}..HEAD --count")[0])
|
return int(_exec(f"git rev-list {tag}..HEAD --count")[0])
|
||||||
|
|
||||||
class version:
|
class version:
|
||||||
"""
|
"""
|
||||||
class containing methods focusing on versions
|
class containing methods focusing on versions
|
||||||
"""
|
"""
|
||||||
__OptDict = { "version_std": "version_std",
|
__OptDict = { "version_std": "version_std",
|
||||||
"formated_output": "formated_output",
|
"formated_output": "formated_output",
|
||||||
"output_format": "output_format"}
|
"output_format": "output_format",
|
||||||
DefaultInputFormat = "PEP440"
|
"ignore_unknown_tags": "ignore_unknown_tags"}
|
||||||
VersionStds = { "SemVer" : { "regex" : r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"},
|
DefaultInputFormat = "Auto"
|
||||||
"PEP440" : { "regex" : packaging_VERSION_PATTERN }
|
VersionStds = { "SemVer" : { "regex" : r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)"\
|
||||||
|
r"(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)"\
|
||||||
|
r"(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?"\
|
||||||
|
r"(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$",
|
||||||
|
"regex_preversion_num": r"(?:\.)(?P<num>(?:\d+(?!\w))+)",
|
||||||
|
"regex_build_num" : r"(?:\.)(?P<num>(?:\d+(?!\w))+)"
|
||||||
|
},
|
||||||
|
"PEP440" : { "regex" : packaging_VERSION_PATTERN,
|
||||||
|
"Auto" : None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
__versionReseted = False
|
||||||
|
class versionException(gitversionhelperException):
|
||||||
|
"""
|
||||||
|
generic version exception
|
||||||
|
"""
|
||||||
|
|
||||||
|
class noValidVersion(versionException):
|
||||||
|
"""
|
||||||
|
no valid version found exception
|
||||||
|
"""
|
||||||
|
|
||||||
|
class PreAndPostVersionUnsupported(versionException):
|
||||||
|
"""
|
||||||
|
pre and post release can not be present at the same time
|
||||||
|
"""
|
||||||
|
|
||||||
class MetaVersion:
|
class MetaVersion:
|
||||||
"""
|
"""
|
||||||
generic version object
|
generic version object
|
||||||
"""
|
"""
|
||||||
__OptDict = { "bump_type": "bump_type",
|
|
||||||
"bump_dev_strategy": "bump_dev_strategy"}
|
__OptDict = { "bump_type": "bump_type",
|
||||||
|
"bump_dev_strategy": "bump_dev_strategy",
|
||||||
|
"formated_output": "formated_output"}
|
||||||
DefaultBumpType = "patch"
|
DefaultBumpType = "patch"
|
||||||
BumpTypes = ["major","minor","patch","dev"]
|
BumpTypes = ["major","minor","patch","dev"]
|
||||||
DefaultBumpDevStrategy = "post"
|
DefaultBumpDevStrategy = "post"
|
||||||
BumpDevStrategys = ["post","pre","force_post","force_pre"]
|
BumpDevStrategys = ["post","pre-patch","pre-minor","pre-major"]
|
||||||
major: int = 0
|
|
||||||
minor: int = 1
|
version_std: str = "None"
|
||||||
patch: int = 0
|
major: int = 0
|
||||||
pre_count:int = 0
|
minor: int = 1
|
||||||
post_count:int = 0
|
patch: int = 0
|
||||||
raw:str = "0.1.0"
|
pre_count:int = 0
|
||||||
|
post_count:int = 0
|
||||||
def __init__(self,major=0,minor=1,patch=0,pre_count=0,post_count=0,raw="0.1.0"):
|
raw:str = "0.1.0"
|
||||||
self.major,self.minor,self.patch,self.pre_count,self.post_count,self.raw = major,minor,patch,pre_count,post_count,raw
|
|
||||||
|
def __init__(self,version_std,major=0,minor=1,patch=0,pre_count=0,post_count=0,raw="0.1.0"): #pylint: disable=R0913
|
||||||
|
self.version_std = version_std
|
||||||
|
self.major = major
|
||||||
|
self.minor = minor
|
||||||
|
self.patch = patch
|
||||||
|
self.pre_count = pre_count
|
||||||
|
self.post_count = post_count
|
||||||
|
self.raw = raw
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _getBumpDevStrategy(cls,**kwargs) -> str:
|
def _getBumpDevStrategy(cls,**kwargs) -> str:
|
||||||
f"""
|
"""
|
||||||
get selected bump_dev_strategy
|
get selected bump_dev_strategy
|
||||||
Kwargs:
|
Keyword Arguments:
|
||||||
{cls.__OptDict["bump_dev_strategy"]}: the given bump_dev_strategy (can be None)
|
bump_dev_strategy(str): the given bump_dev_strategy (can be None)
|
||||||
Return:
|
Returns:
|
||||||
Kwargs given {cls.__OptDict["bump_dev_strategy"]} or the default one.
|
Kwargs given bump_dev_strategy or the default one.
|
||||||
"""
|
"""
|
||||||
BumpDevStrategy = cls.DefaultBumpDevStrategy
|
BumpDevStrategy = cls.DefaultBumpDevStrategy
|
||||||
if (cls.__OptDict["bump_dev_strategy"] in kwargs):
|
if cls.__OptDict["bump_dev_strategy"] in kwargs:
|
||||||
if kwargs[cls.__OptDict["bump_dev_strategy"]] in cls.BumpDevStrategys:
|
if kwargs[cls.__OptDict["bump_dev_strategy"]] in cls.BumpDevStrategys:
|
||||||
BumpDevStrategy = kwargs[cls.__OptDict["bump_dev_strategy"]]
|
BumpDevStrategy = kwargs[cls.__OptDict["bump_dev_strategy"]]
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(f"invalid {cls.__OptDict['bump_type']} requested")
|
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['bump_type']} requested")
|
||||||
return BumpDevStrategy
|
return BumpDevStrategy
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _getBumpType(cls,**kwargs) -> str:
|
def _getBumpType(cls,**kwargs) -> str:
|
||||||
f"""
|
"""
|
||||||
get selected bump_type
|
get selected bump_type
|
||||||
Kwargs:
|
Keyword Arguments:
|
||||||
{cls.__OptDict["bump_type"]}: the given bump_type (can be None)
|
bump_type(str): the given bump_type (can be None)
|
||||||
Return:
|
Returns:
|
||||||
Kwargs given {cls.__OptDict["bump_type"]} or the default one.
|
Kwargs given bump_type or the default one.
|
||||||
"""
|
"""
|
||||||
BumpType = cls.DefaultBumpType
|
BumpType = cls.DefaultBumpType
|
||||||
if (cls.__OptDict["bump_type"] in kwargs):
|
if cls.__OptDict["bump_type"] in kwargs:
|
||||||
if kwargs[cls.__OptDict["bump_type"]] in cls.BumpTypes:
|
if kwargs[cls.__OptDict["bump_type"]] in cls.BumpTypes:
|
||||||
BumpType = kwargs[cls.__OptDict["bump_type"]]
|
BumpType = kwargs[cls.__OptDict["bump_type"]]
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(f"invalid {cls.__OptDict['bump_type']} requested")
|
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['bump_type']} requested")
|
||||||
return BumpType
|
return BumpType
|
||||||
|
|
||||||
def bump(self,**kwargs):
|
def bump(self,amount:int=1,**kwargs) -> gitversionhelper.version.MetaVersion | str : # pylint: disable=R0912
|
||||||
f"""
|
"""
|
||||||
bump the version to the next one
|
bump the version to the next one
|
||||||
Kwargs:
|
Keyword Arguments:
|
||||||
{cls.__OptDict["bump_type"]}: the given bump_type (can be None)
|
bump_type(str): the given bump_type (can be None)
|
||||||
{cls.__OptDict["bump_dev_strategy"]}: the given bump_dev_strategy (can be None)
|
bump_dev_strategy(str): the given bump_dev_strategy (can be None)
|
||||||
Return:
|
Returns:
|
||||||
the bumped version
|
the bumped version
|
||||||
"""
|
"""
|
||||||
BumpType = self._getBumpType(**kwargs)
|
BumpType = self._getBumpType(**kwargs)
|
||||||
BumpDevStrategy=self._getBumpDevStrategy(**kwargs)
|
BumpDevStrategy=self._getBumpDevStrategy(**kwargs)
|
||||||
_v=copy(self)
|
_v=copy(self)
|
||||||
if BumpType is "dev":
|
|
||||||
if BumpDevStrategy is "post":
|
if BumpType == "dev":
|
||||||
|
if BumpDevStrategy == "post":
|
||||||
if _v.pre_count > 0:
|
if _v.pre_count > 0:
|
||||||
_v.pre_count = _v.pre_count + 1
|
_v.pre_count = _v.pre_count + amount
|
||||||
else:
|
else:
|
||||||
_v.post_count = _v.post_count + 1
|
_v.post_count = _v.post_count + amount
|
||||||
elif BumpDevStrategy is "pre":
|
#elif BumpDevStrategy in ["pre-patch","pre-minor","pre-major"]:
|
||||||
|
else:
|
||||||
if _v.post_count > 0:
|
if _v.post_count > 0:
|
||||||
_v.post_count = _v.post_count + 1
|
_v.post_count = _v.post_count + amount
|
||||||
else:
|
else:
|
||||||
_v.pre_count = _v.pre_count + 1
|
if _v.pre_count == 0:
|
||||||
elif BumpDevStrategy is "force_post":
|
if BumpDevStrategy == "pre-patch":
|
||||||
pass
|
_v.patch = _v.patch + 1
|
||||||
elif BumpDevStrategy is "force_pre":
|
elif BumpDevStrategy == "pre-minor":
|
||||||
pass
|
_v.minor = _v.minor + 1
|
||||||
|
_v.patch = 0
|
||||||
|
#elif BumpDevStrategy == "pre-major":
|
||||||
|
else:
|
||||||
|
_v.major = _v.major + 1
|
||||||
|
_v.minor = 0
|
||||||
|
_v.patch = 0
|
||||||
|
_v.pre_count = _v.pre_count + amount
|
||||||
else:
|
else:
|
||||||
if BumpType is "major":
|
if BumpType == "major":
|
||||||
_v.major = _v.major + 1
|
_v.major = _v.major + amount
|
||||||
elif BumpType is "minor":
|
elif BumpType == "minor":
|
||||||
_v.minor = _v.minor + 1
|
_v.minor = _v.minor + amount
|
||||||
elif BumpType is "patch":
|
#elif BumpType == "patch":
|
||||||
_v.patch = _v.patch + 1
|
else:
|
||||||
|
_v.patch = _v.patch + amount
|
||||||
_v.pre_count=0
|
_v.pre_count=0
|
||||||
_v.post_count=0
|
_v.post_count=0
|
||||||
|
_v.raw=_v.doFormatVersion(**kwargs)
|
||||||
_v.raw="{major}.{minor}.{patch}{revpattern}{revcount}".format(major=_v.major,minor=_v.minor,patch=_v.patch,revpattern="",revcount="")
|
|
||||||
|
if ((self.__OptDict["formated_output"] in kwargs) and (kwargs[self.__OptDict["formated_output"]] is True)):
|
||||||
|
return _v.doFormatVersion(**kwargs)
|
||||||
return _v
|
return _v
|
||||||
|
|
||||||
def doFormatVersion(self,**kwargs):
|
def doFormatVersion(self,**kwargs) -> str:
|
||||||
|
"""
|
||||||
|
output a formated version string
|
||||||
|
Keyword Arguments:
|
||||||
|
output_format: output format to render ("Auto" or "PEP440" or "SemVer")
|
||||||
|
Returns:
|
||||||
|
formated version string
|
||||||
|
"""
|
||||||
return gitversionhelper.version.doFormatVersion(self,**kwargs)
|
return gitversionhelper.version.doFormatVersion(self,**kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _getVersionStd(cls,**kwargs):
|
def _getVersionStd(cls,**kwargs) -> str:
|
||||||
"""
|
"""
|
||||||
get selected version_std
|
get selected version_std
|
||||||
|
Keyword Arguments:
|
||||||
|
version_std(str): the given version_std (can be None)
|
||||||
|
Returns:
|
||||||
|
Kwargs given version_std or the default one.
|
||||||
"""
|
"""
|
||||||
VersionStd = cls.DefaultInputFormat
|
VersionStd = cls.DefaultInputFormat
|
||||||
if (cls.__OptDict["version_std"] in kwargs):
|
if cls.__OptDict["version_std"] in kwargs:
|
||||||
if kwargs[cls.__OptDict["version_std"]] in cls.VersionStds:
|
if kwargs[cls.__OptDict["version_std"]] in cls.VersionStds:
|
||||||
VersionStd = kwargs[cls.__OptDict["version_std"]]
|
VersionStd = kwargs[cls.__OptDict["version_std"]]
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(f"invalid {cls.__OptDict['version_std']} requested")
|
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['version_std']} requested")
|
||||||
return VersionStd
|
return VersionStd
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getLastVersion(cls,**kwargs):
|
def getCurrentVersion(cls,**kwargs) -> MetaVersion | str :
|
||||||
"""
|
"""
|
||||||
get last version from git tags
|
get the current version or bump depending of repository state
|
||||||
|
Keyword Arguments:
|
||||||
|
version_std(str): the given version_std (can be None)
|
||||||
|
same_branch(bool): force searching only in the same branch
|
||||||
|
formated_output(bool) : output a formated version string
|
||||||
|
bump_type(str): the given bump_type (can be None)
|
||||||
|
bump_dev_strategy(str): the given bump_dev_strategy (can be None)
|
||||||
|
Returns:
|
||||||
|
the last version
|
||||||
"""
|
"""
|
||||||
VersionStd = cls._getVersionStd(**kwargs)
|
if gitversionhelper.repository.isDirty() is not False:
|
||||||
_r=re.compile(r"^\s*" + cls.VersionStds[VersionStd]["regex"] + r"\s*$", re.VERBOSE | re.IGNORECASE)
|
raise gitversionhelper.repository.repositoryDirty( "The repository is dirty and a current version" \
|
||||||
|
" can not be generated.")
|
||||||
lastTag = gitversionhelper.tag.getLastTag(**kwargs)
|
saved_kwargs = copy(kwargs)
|
||||||
|
if "formated_output" in kwargs:
|
||||||
_m = re.match(_r,lastTag)
|
del saved_kwargs["formated_output"]
|
||||||
if not _m:
|
|
||||||
raise RuntimeError("no valid version found in tags")
|
_v = cls.getLastVersion(**saved_kwargs)
|
||||||
if VersionStd is "PEP440":
|
|
||||||
ver=_m.group("release").split(".")
|
if not cls.__versionReseted:
|
||||||
ver += ["0"] * (3 - len(ver))
|
amount = gitversionhelper.tag.getDistanceFromTag(_v.raw,**kwargs)
|
||||||
ver[0]=int(ver[0])
|
_v = _v.bump(amount,**saved_kwargs)
|
||||||
ver[1]=int(ver[1])
|
|
||||||
ver[2]=int(ver[2])
|
|
||||||
major, minor, patch = tuple(ver)
|
|
||||||
pre_count = int(_m.group("pre_n")) if _m.group("pre_n") else 0
|
|
||||||
post_count = int(_m.group("post_n2")) if _m.group("post_n2") else 0
|
|
||||||
elif VersionStd is "SemVer":
|
|
||||||
major, minor, patch = int(_m.group("major")),int(_m.group("minor")),int(_m.group("patch")),(_m.group("prerelease") if _m.group("prerelease") else ""), ""
|
|
||||||
pre_count = 0
|
|
||||||
post_count = 0
|
|
||||||
|
|
||||||
_v = cls.MetaVersion(major, minor, patch, pre_count, post_count, lastTag)
|
|
||||||
|
|
||||||
if ((cls.__OptDict["formated_output"] in kwargs) and (kwargs[cls.__OptDict["formated_output"]] is True)):
|
if ((cls.__OptDict["formated_output"] in kwargs) and (kwargs[cls.__OptDict["formated_output"]] is True)):
|
||||||
return cls.doFormatVersion(_v,**kwargs)
|
return _v.doFormatVersion(**kwargs)
|
||||||
else:
|
return _v
|
||||||
return _v
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def doFormatVersion(cls,inputversion:MetaVersion,**kwargs):
|
def getCurrentFormatedVersion(cls,**kwargs) -> str :
|
||||||
"""
|
"""
|
||||||
output a formated version
|
Same as getCurrentVersion() with formated_output kwarg activated
|
||||||
|
"""
|
||||||
|
kwargs["formated_output"]=True
|
||||||
|
return cls.getCurrentVersion(kwargs)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _parseTag(cls,tag,**kwargs): # pylint: disable=R0914, R0912, R0915
|
||||||
|
"""get the last version from tags
|
||||||
|
Arguments:
|
||||||
|
tag: the tag to be parsed
|
||||||
|
Keyword Arguments:
|
||||||
|
version_std(str): the given version_std (can be None)
|
||||||
|
ignore_unknown_tags(bool): skip tags with not decoded versions (default to False)
|
||||||
|
Returns:
|
||||||
|
the last version
|
||||||
"""
|
"""
|
||||||
VersionStd = cls._getVersionStd(**kwargs)
|
VersionStd = cls._getVersionStd(**kwargs)
|
||||||
|
bAutoVersionStd = False
|
||||||
|
if VersionStd == "Auto":
|
||||||
|
bAutoVersionStd = True
|
||||||
|
bFound = False
|
||||||
|
if VersionStd == "SemVer" or (bAutoVersionStd is True) :
|
||||||
|
_r=re.compile(r"^\s*" + cls.VersionStds["SemVer"]["regex"] + r"\s*$", re.VERBOSE | \
|
||||||
|
re.IGNORECASE)
|
||||||
|
_m = re.match(_r,tag)
|
||||||
|
if not _m:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
major, minor, patch = int(_m.group("major")),\
|
||||||
|
int(_m.group("minor")),\
|
||||||
|
int(_m.group("patch"))
|
||||||
|
|
||||||
|
pre_count = 0
|
||||||
|
if _pre := _m.group("prerelease"):
|
||||||
|
if (_match := re.search (cls.VersionStds["SemVer"]["regex_preversion_num"],_pre)) is not None:
|
||||||
|
pre_count = int(_match.group("num"))
|
||||||
|
else:
|
||||||
|
pre_count = 1
|
||||||
|
|
||||||
|
post_count = 0
|
||||||
|
if _post := _m.group("buildmetadata"):
|
||||||
|
if (_match := re.search (cls.VersionStds["SemVer"]["regex_build_num"],_post)) is not None:
|
||||||
|
post_count = int(_match.group("num"))
|
||||||
|
else:
|
||||||
|
post_count = 1
|
||||||
|
bFound = True
|
||||||
|
VersionStd = "SemVer"
|
||||||
|
|
||||||
|
if VersionStd == "PEP440" or ( (bAutoVersionStd is True) and (bFound is not True)):
|
||||||
|
_r=re.compile(r"^\s*" + cls.VersionStds["PEP440"]["regex"] + r"\s*$", re.VERBOSE | \
|
||||||
|
re.IGNORECASE)
|
||||||
|
_m = re.match(_r,tag)
|
||||||
|
if not _m:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
ver=_m.group("release").split(".")
|
||||||
|
ver += ["0"] * (3 - len(ver))
|
||||||
|
ver[0]=int(ver[0])
|
||||||
|
ver[1]=int(ver[1])
|
||||||
|
ver[2]=int(ver[2])
|
||||||
|
major, minor, patch = tuple(ver)
|
||||||
|
pre_count = int(_m.group("pre_n")) if _m.group("pre_n") else 0
|
||||||
|
post_count = int(_m.group("post_n2")) if _m.group("post_n2") else 0
|
||||||
|
bFound = True
|
||||||
|
VersionStd = "PEP440"
|
||||||
|
|
||||||
|
if not bFound :
|
||||||
|
raise gitversionhelper.version.noValidVersion("no valid version found in tags")
|
||||||
|
|
||||||
|
if pre_count > 0 and post_count > 0:
|
||||||
|
raise cls.PreAndPostVersionUnsupported("can not parse a version with both pre" \
|
||||||
|
" and post release number.")
|
||||||
|
return cls.MetaVersion(VersionStd, major, minor, patch, pre_count, post_count, tag)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getLastVersion(cls,**kwargs) -> MetaVersion | str : # pylint: disable=R0914, R0912, R0915
|
||||||
|
"""get the last version from tags
|
||||||
|
Keyword Arguments:
|
||||||
|
version_std(str): the given version_std (can be None)
|
||||||
|
same_branch(bool): force searching only in the same branch
|
||||||
|
formated_output(bool) : output a formated version string
|
||||||
|
ignore_unknown_tags(bool): skip tags with not decoded versions (default to False)
|
||||||
|
Returns:
|
||||||
|
the last version
|
||||||
|
"""
|
||||||
|
lastTag=cls.MetaVersion.raw
|
||||||
|
cls.__versionReseted = False
|
||||||
|
try:
|
||||||
|
lastTag = gitversionhelper.tag.getLastTag(**kwargs)
|
||||||
|
except gitversionhelper.tag.tagNotFound:
|
||||||
|
logging.warning('tag not found, reseting versionning')
|
||||||
|
cls.__versionReseted = True
|
||||||
|
|
||||||
|
_v=None
|
||||||
|
try:
|
||||||
|
_v=cls._parseTag(lastTag,**kwargs)
|
||||||
|
except gitversionhelper.version.noValidVersion as _ex:
|
||||||
|
if ((cls.__OptDict["ignore_unknown_tags"] in kwargs) and (kwargs[cls.__OptDict["ignore_unknown_tags"]] is True)):
|
||||||
|
tags = gitversionhelper.tag.getTags(sort= "taggerdate",**kwargs)
|
||||||
|
_v = None
|
||||||
|
for _tag in tags:
|
||||||
|
try:
|
||||||
|
_v=cls._parseTag(_tag,**kwargs)
|
||||||
|
break
|
||||||
|
except gitversionhelper.version.noValidVersion:
|
||||||
|
continue
|
||||||
|
if _v is None:
|
||||||
|
raise gitversionhelper.version.noValidVersion() from _ex
|
||||||
|
|
||||||
|
if ((cls.__OptDict["formated_output"] in kwargs) and (kwargs[cls.__OptDict["formated_output"]] is True)):
|
||||||
|
return _v.doFormatVersion(**kwargs)
|
||||||
|
return _v
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def doFormatVersion(cls,inputversion:MetaVersion,**kwargs) -> str:
|
||||||
|
"""
|
||||||
|
output a formated version string
|
||||||
|
Keyword Arguments:
|
||||||
|
output_format: output format to render ("Auto" or "PEP440" or "SemVer")
|
||||||
|
Args:
|
||||||
|
inputversion: version to be rendered
|
||||||
|
Returns:
|
||||||
|
formated version string
|
||||||
|
"""
|
||||||
|
|
||||||
|
VersionStd = cls._getVersionStd(**kwargs)
|
||||||
|
if VersionStd=="Auto" :
|
||||||
|
VersionStd = inputversion.version_std
|
||||||
|
|
||||||
OutputFormat = None
|
OutputFormat = None
|
||||||
revpattern=""
|
revpattern=""
|
||||||
revcount=""
|
revcount=""
|
||||||
post_count = inputversion.post_count
|
post_count = inputversion.post_count
|
||||||
pre_count = inputversion.pre_count
|
pre_count = inputversion.pre_count
|
||||||
patch = inputversion.patch
|
patch = inputversion.patch
|
||||||
if (cls.__OptDict["output_format"] in kwargs):
|
|
||||||
|
if cls.__OptDict["output_format"] in kwargs:
|
||||||
OutputFormat=kwargs[cls.__OptDict["output_format"]]
|
OutputFormat=kwargs[cls.__OptDict["output_format"]]
|
||||||
|
|
||||||
if OutputFormat is None:
|
if OutputFormat is None:
|
||||||
if VersionStd is "PEP440":
|
OutputFormat = "{major}.{minor}.{patch}{revpattern}{revcount}"
|
||||||
OutputFormat = "{major}.{minor}.{patch}{revpattern}{revcount}"
|
if post_count > 0 and pre_count > 0:
|
||||||
|
raise gitversionhelper.version.PreAndPostVersionUnsupported("cannot output a version with both pre " \
|
||||||
|
"and post release number.")
|
||||||
|
if VersionStd == "PEP440":
|
||||||
if post_count > 0:
|
if post_count > 0:
|
||||||
revpattern=".post"
|
revpattern=".post"
|
||||||
revcount=f"{post_count}"
|
revcount=f"{post_count}"
|
||||||
elif VersionStd is "SemVer":
|
elif pre_count > 0:
|
||||||
OutputFormat = "{major}.{minor}.{patch}{revpattern}{revcount}"
|
revpattern=".pre"
|
||||||
if post_count > 0:
|
|
||||||
pre_count = pre_count + post_count
|
|
||||||
post_count = 0
|
|
||||||
patch = patch + 1
|
|
||||||
if pre_count > 0:
|
|
||||||
revpattern="-pre"
|
|
||||||
revcount=f"{pre_count}"
|
revcount=f"{pre_count}"
|
||||||
|
#elif VersionStd == "SemVer":
|
||||||
return OutputFormat.format(major=inputversion.major,minor=inputversion.minor,patch=patch,revpattern=revpattern,revcount=revcount)
|
else:
|
||||||
|
if post_count > 0:
|
||||||
|
revpattern="+post"
|
||||||
|
revcount=f".{post_count}"
|
||||||
|
elif pre_count > 0:
|
||||||
|
revpattern="-pre"
|
||||||
#print(gitversionhelper.head.isDirty())
|
revcount=f".{pre_count}"
|
||||||
#print(gitversionhelper.tag.getTags())
|
return OutputFormat.format( major=inputversion.major, \
|
||||||
#print(gitversionhelper.tag.getLastTag())
|
minor=inputversion.minor, \
|
||||||
#print(gitversionhelper.tag.getLastTag(same_branch=True))
|
patch=patch, \
|
||||||
#print(gitversionhelper.tag.getDistanceFromLastTag())
|
revpattern=revpattern, \
|
||||||
#print(gitversionhelper.tag.getDistanceFromLastTag(same_branch=True))
|
revcount=revcount)
|
||||||
|
|
||||||
#print(gitversionhelper.version.getLastVersion())
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=True,version_std="PEP440"))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=True,version_std="PEP440"))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=False,version_std="PEP440"))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=True,version_std="PEP440",formated_output=True))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=True,version_std="PEP440",formated_output=True,output_format="v{major}.{minor}.{patch}"))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=False,version_std="PEP440").bump())
|
|
||||||
#print("")
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=False,version_std="PEP440").bump(bump_type="dev").doFormatVersion(version_std="SemVer"))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=False,version_std="PEP440").bump(bump_type="patch").doFormatVersion(version_std="SemVer"))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=False,version_std="PEP440").bump(bump_type="minor").doFormatVersion(version_std="SemVer"))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=False,version_std="PEP440").bump(bump_type="major").doFormatVersion(version_std="SemVer"))
|
|
||||||
#print("")
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=False,version_std="PEP440").bump(bump_type="dev").doFormatVersion(version_std="PEP440"))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=False,version_std="PEP440").bump(bump_type="patch").doFormatVersion(version_std="PEP440"))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=False,version_std="PEP440").bump(bump_type="minor").doFormatVersion(version_std="PEP440"))
|
|
||||||
#print(gitversionhelper.version.getLastVersion(same_branch=False,version_std="PEP440").bump(bump_type="major").doFormatVersion(version_std="PEP440"))
|
|
||||||
|
|
||||||
#from setuptools_git_versioning import version_from_git
|
|
||||||
#print(str(version_from_git(tag_filter="^\d+\.\d+\.\d+$",dev_template = "{tag}.post{ccount}",sort_by="v:refname")),end ="")
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user