Compare commits

...

33 Commits

Author SHA1 Message Date
cclecle
b01779dd06 add missing parentheses 2023-03-28 00:50:43 +01:00
cclecle
f7ec5d98a7 fix changelog multiline 2023-03-28 00:45:48 +01:00
cclecle
82d4b1bd70 fix: remove useless printf in getMessagesSinceTag() 2023-03-28 00:45:00 +01:00
cclecle
880fa29bbd try to get changelog before tag creation 2023-03-28 00:35:00 +01:00
cclecle
7347106694 test printing changelog parts 2023-03-28 00:21:37 +01:00
cclecle
e1c1e643c3 include others changes in changelog 2023-03-28 00:08:18 +01:00
cclecle
a5f39d6cb2 update changelog 2023-03-28 00:04:31 +01:00
cclecle
c6ed7ef0a1 fix wrong typo in jenkinsfile 2023-03-27 23:48:18 +01:00
cclecle
0ef5a8f463 feature: add changelog ! 2023-03-27 23:46:34 +01:00
cclecle
e06a3b00ae fix wrong getMessagesSinceTag() command 2023-03-27 23:27:21 +01:00
cclecle
d3bf6ddaa6 add ignore_merged to git messages 2023-03-27 23:18:42 +01:00
cclecle
a419af2ade add ignore_merged option to commit search 2023-03-27 23:11:16 +01:00
cclecle
5f9d513c59 finish fixing typing
updating and fixing doc
2023-03-27 01:59:15 +01:00
cclecle
5087cf9614 improve typing checks and fix warnings / errors 2023-03-27 01:03:21 +01:00
cclecle
dc322e52da fix quality cmd line 2023-03-26 20:38:00 +01:00
cclecle
a9052f1d71 back port from pychangelogfactory 2023-03-26 20:25:57 +01:00
cclecle
e64dcf4978 improve project configuration from pychangelogfactory 2023-03-25 19:59:20 +00:00
cclecle
a045a47cb0 re-add readme 2023-03-24 22:48:03 +00:00
cclecle
876e428003 remove dynamic link to doc in readme 2023-03-24 22:38:22 +00:00
cclecle
f32127abd7 revert to static readme file... :-/ 2023-03-24 22:12:08 +00:00
cclecle
b20e5bd868 fix 2023-03-24 21:46:51 +00:00
cclecle
f1b1901f8a format + dynamic readme 2023-03-24 21:37:55 +00:00
cclecle
f63a7b76cd format 2023-03-24 21:08:57 +00:00
cclecle
7ce1a04eb9 formating 2023-03-24 20:28:57 +00:00
cclecle
658eef2df6 update readme 2023-03-24 20:25:16 +00:00
cclecle
3d2b8d3762 adjust colours 2023-03-24 20:02:17 +00:00
cclecle
da9fa475e8 fix csv path 2023-03-24 19:53:01 +00:00
cclecle
93d2046c98 set badge colour 2023-03-24 19:51:24 +00:00
cclecle
fa7eaf0769 update badge_maintainability 2023-03-24 19:47:54 +00:00
cclecle
cad73c4711 add complexity check 2023-03-24 19:26:11 +00:00
cclecle
5621ba99f6 start implementation of complexity measurement 2023-03-24 01:09:10 +00:00
cclecle
c49468e294 fix decimal + colours 2023-03-24 00:19:30 +00:00
cclecle
bec5f9234d fix 2023-03-24 00:11:08 +00:00
21 changed files with 797 additions and 469 deletions

2
.gitignore vendored
View File

@@ -41,3 +41,5 @@ docs
helpers-results
.coverage
/.mypy_cache/
.coverage
.mypy_cache

View File

@@ -6,7 +6,6 @@
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}/src</path>
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>

111
Jenkinsfile vendored
View File

@@ -35,9 +35,9 @@ def _MkDocsWebCredentials = "2c5b684e-3787-4b37-8aca-b3dd4a383fe2"
def _PypiCredentials = "Pypi"
def badge_coverage = addEmbeddableBadgeConfiguration(id: "coverage", subject: "coverage")
def badge_complexity = addEmbeddableBadgeConfiguration(id: "complexity", subject: "code complexity")
def badge_quality = addEmbeddableBadgeConfiguration(id: "quality", subject: "quality score")
def badge_coverage = addEmbeddableBadgeConfiguration(id: "coverage", subject: "coverage")
def badge_maintainability = addEmbeddableBadgeConfiguration(id: "maintainability", subject: "maintainability")
def badge_quality = addEmbeddableBadgeConfiguration(id: "quality", subject: "quality score")
// commands Helper: /!\ Made for GITEA /!\
String determineRepoUserName() {
@@ -89,7 +89,7 @@ int GetCoverageValue(String CoverageFilePath,String XPath)
String getColorScale(BigDecimal value)
{
if( value >9) { return "gold"}
if( value >9) { return "Goldenrod"}
else if( value >6) { return "seagreen"}
else if( value >4) { return "orange"}
else if( value >2) { return "darkred"}
@@ -102,7 +102,7 @@ String getColorScale_reversed(BigDecimal value)
else if( value >6) { return "darkred"}
else if( value >4) { return "orange"}
else if( value >2) { return "seagreen"}
else { return "gold"}
else { return "Goldenrod"}
}
int GetCoverageValue_lines_valid(String CoverageFilePath) { return GetCoverageValue(CoverageFilePath,"/coverage/@lines-valid") }
@@ -148,6 +148,7 @@ pipeline {
PY_PROJECT_NAME = "__NOTSET__"
PY_PROJECT_VERSION = "__NOTSET__"
PY_PROJECT_VERSION_STRIPPED = "__NOTSET__"
CHANGELOG = "__NOTSET__"
}
stages {
@@ -184,16 +185,14 @@ pipeline {
sh(". ~/BUILD_ENV/bin/activate && pip install --upgrade setuptools build pip copier jinja2-slug toml")
sh(". ~/TOOLS_ENV/bin/activate && pip install simple_rest_client requests twine")
sh(". ~/TOOLS_ENV/bin/activate && pip install simple_rest_client requests twine packaging")
script {
if(_PROJECT_NAME!="pygitversionhelper") {
sh(". ~/TOOLS_ENV/bin/activate && pip install pygitversionhelper")
}
else
{
//TODO: need to install pygitversionhelper deps from a better way...
sh(". ~/TOOLS_ENV/bin/activate && pip install packaging")
if(_PROJECT_NAME!="pychangelogfactory") {
sh(". ~/TOOLS_ENV/bin/activate && pip install pychangelogfactory")
}
}
sh("git config --global user.email $_MaintainerEmail")
@@ -217,6 +216,33 @@ pipeline {
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")
}
CHANGELOG = sh(script: """#!/bin/sh -
|. ~/TOOLS_ENV/bin/activate
|exec python - << '__EOWRAPPER__'
|
|import re
|
|try:
| from pychangelogfactory import ChangelogFactory
|except ImportError:
| from src.pychangelogfactory import ChangelogFactory
|
|try:
| from pygitversionhelper import gitversionhelper
|except ImportError:
| from src.pygitversionhelper import gitversionhelper
|
|
|LastTag=gitversionhelper.tag.getLastTag(same_branch=True)
|CommitHistory=gitversionhelper.commit.getMessagesSinceTag(LastTag, merged_output=True, ignore_merged=True)
|Changelog = ChangelogFactory(CommitHistory).RenderFullChangelog(include_unknown=True)
|print(Changelog.replace("\\n","\\n\\n"))
|
|__EOWRAPPER__
""".stripMargin(),
returnStdout: true).trim()
if(_GIT_BRANCH=="master") {
if(sh(returnStdout: true, script: "git tag --points-at HEAD").trim().isEmpty()) {
@@ -375,7 +401,7 @@ pipeline {
def wheelPath = findFiles(glob: "**/dist/*.whl")[0]
echo "wheel artifact path: $wheelPath"
// install the package, with *test* optionnal packages, as user
sh(". ~/TEST_ENV/bin/activate && pip install --find-links dist/ ${PY_PROJECT_NAME} .[test,coverage-check,quality-check,type-check,doc-gen]")
sh(". ~/TEST_ENV/bin/activate && pip install --find-links dist/ ${PY_PROJECT_NAME} .[test,coverage-check,quality-check,type-check,doc-gen,complexity-check]")
}
}
}
@@ -387,22 +413,33 @@ pipeline {
sh(". ~/TEST_ENV/bin/activate && python -m helpers --type-check --quality-check")
script {
def jsonObj = readJSON file: "helpers-results/quality_check/metrics.json"
quality_score = jsonObj["GlobalScore"]
badge_quality.setStatus(Double.toString(quality_score))
quality_score = new BigDecimal(jsonObj["GlobalScore"])
sz_quality_score = quality_score.setScale(2, RoundingMode.HALF_EVEN).toString()
badge_quality.setStatus(sz_quality_score)
badge_quality.setColor(getColorScale(quality_score))
}
sh(". ~/TEST_ENV/bin/activate && python -m helpers --complexity-check")
}
}
post {
always {
dir("gitrepo") {
publishHTML([
reportDir: "helpers-results/quality_check",
reportFiles: "report.html",
reportName: "quality-report",
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true])
dir("gitrepo") {
publishCoverage adapters: [cobertura(mergeToOneReport: true, path: "helpers-results/types_check/cobertura.xml")]
junit 'helpers-results/types_check/junit.xml'
publishHTML([
reportDir: "helpers-results/quality_check",
reportFiles: "report.html",
reportName: "quality-report",
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true])
publishHTML([
reportDir: "helpers-results/types_check",
reportFiles: "index.html",
reportName: "types_check",
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true])
}
}
}
@@ -445,6 +482,14 @@ pipeline {
style: 'stackedArea',
keepRecords: true,
numBuilds: ''])
plot([ csvFileName: 'plot-4ceb9ee2-ca78-11ed-afa1-0242ac120002.csv',
csvSeries: [[ file: 'gitrepo/helpers-results/complexity_check/MI.csv', inclusionFlag: 'INCLUDE_BY_STRING',exclusionValues: 'MeanMaintainability', url: '']],
group: 'metrics',
title: 'maintainability',
style: 'stackedArea',
keepRecords: true,
numBuilds: ''])
}
}
@@ -470,12 +515,18 @@ pipeline {
full_rate = new BigDecimal( 10*(GetCoverageValue_line_rate(coverage_report_path) + GetCoverageValue_branch_rate(coverage_report_path)) / 2 )
sz_full_rate = full_rate.setScale(2, RoundingMode.HALF_EVEN).toString()
badge_coverage.setStatus(sz_full_rate)
badge_quality.setColor(getColorScale(full_rate))
badge_coverage.setColor(getColorScale(full_rate))
//badge_maintainability
records = readCSV file: 'helpers-results/complexity_check/MI.csv'
maintainability = records[1][1]
badge_maintainability.setStatus(maintainability)
complexity = new BigDecimal( 10*GetCoverageValue_complexity(coverage_report_path))
sz_complexity = complexity.setScale(2, RoundingMode.HALF_EVEN).toString()
badge_complexity.setStatus(sz_complexity)
badge_quality.setColor(getColorScale_reversed(complexity))
if ( maintainability == 'D') { badge_maintainability.setColor( "dimgrey")}
else if( maintainability == 'C') { badge_maintainability.setColor( "darkred")}
else if( maintainability == 'B') { badge_maintainability.setColor( "orange")}
else if( maintainability == 'A') { badge_maintainability.setColor( "seagreen")}
else if( maintainability == 'A+') { badge_maintainability.setColor( "Goldenrod")}
}
}
}
@@ -548,6 +599,7 @@ pipeline {
|from simple_rest_client.api import API
|from simple_rest_client.resource import Resource
|
|
|try:
| from pygitversionhelper import gitversionhelper
|except ImportError:
@@ -594,6 +646,13 @@ pipeline {
|ReleaseContent = "${_ReleaseContent_Title}" + "\\n" \\
| + "\\n" \\
| + "Reference documentation: [mkdocs page](https://chacha.ddns.net/mkdocs-web/${_PROJECT_USER_NAME}/${PY_PROJECT_NAME}/${_GIT_BRANCH}/${PY_PROJECT_VERSION_STRIPPED}/) "
|
|Changelog='''${CHANGELOG}'''
|
|ReleaseContent = ReleaseContent + "\\n"+ "\\n"+ "## Changelog:\\n" + Changelog
|
|if not Changelog:
| ReleaseContent = ReleaseContent + "code/project maintainance"
|
|data={
| "body": ReleaseContent,

View File

@@ -1,9 +1,9 @@
![](https://chacha.ddns.net/jenkins/buildStatus/icon?subject=status&status=active&color=seagreen)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?subject=doc&status=MkDocs&color=blue)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?subject=jenkins-unittest&job={{repository}}-{{branch}})
![](https://chacha.ddns.net/jenkins/buildStatus/icon?job={{repository}}-{{branch}}&build=0&config=coverage&color=darkviolet)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?job={{repository}}-{{branch}}&build=0&config=complexity&color=darkviolet)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?job={{repository}}-{{branch}}&build=0&config=quality&color=darkviolet)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?job={{repository}}-{{branch}}&build=0&config=coverage)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?job={{repository}}-{{branch}}&build=0&config=maintainability)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?job={{repository}}-{{branch}}&build=0&config=quality)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?subject=licence&status=CC%20BY-NC-SA%204.0&color=teal)
![](docs-static/Library.jpg)
@@ -14,8 +14,7 @@ _A tiny library to help versioning management of git python projects_
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/pygitversionhelper/{{branch}}/latest/).
Checkout [Latest Documentation](https://chacha.ddns.net/mkdocs-web/chacha/pygitversionhelper/master/latest/).
## Features
- list tags
@@ -24,7 +23,8 @@ Checkout [Latest Documentation](https://chacha.ddns.net/mkdocs-web/chacha/pygitv
- get current version (bumped)
- convert / switch from SemVer to PEP440 (both ways)
- automatic version format detection (SemVer by default)
- get commit message history
## Options
- restrict to same branch
- both SemVer and PEP440 support

16
RUN_changelog.launch Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.python.pydev.debug.regularLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/${project_name}/helpers"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="2"/>
</listAttribute>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc}/helpers"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--changelog-gen"/>
<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
<stringAttribute key="org.python.pydev.debug.ATTR_PROJECT" value="pygitversionhelper"/>
<stringAttribute key="process_factory_id" value="org.python.pydev.debug.processfactory.PyProcessFactory"/>
</launchConfiguration>

16
RUN_complexity.launch Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.python.pydev.debug.regularLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/${project_name}/helpers"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="2"/>
</listAttribute>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc}/helpers"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--complexity-check"/>
<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
<stringAttribute key="org.python.pydev.debug.ATTR_PROJECT" value="pygitversionhelper"/>
<stringAttribute key="process_factory_id" value="org.python.pydev.debug.processfactory.PyProcessFactory"/>
</launchConfiguration>

19
RUN_mkdocs.launch Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.python.pydev.debug.regularLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/${project_name}/helpers"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="2"/>
</listAttribute>
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
<mapEntry key="PATH" value="C:\Program Files\GTK3-Runtime Win64\bin"/>
</mapAttribute>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc}/helpers"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--doc-gen --doc-gen-pdf"/>
<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
<stringAttribute key="org.python.pydev.debug.ATTR_PROJECT" value="pygitversionhelper"/>
<stringAttribute key="process_factory_id" value="org.python.pydev.debug.processfactory.PyProcessFactory"/>
</launchConfiguration>

16
RUN_quality.launch Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.python.pydev.debug.regularLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/${project_name}/helpers"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="2"/>
</listAttribute>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc}/helpers"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--type-check --quality-check"/>
<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
<stringAttribute key="org.python.pydev.debug.ATTR_PROJECT" value="pygitversionhelper"/>
<stringAttribute key="process_factory_id" value="org.python.pydev.debug.processfactory.PyProcessFactory"/>
</launchConfiguration>

16
RUN_unittest.launch Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.python.pydev.debug.regularLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/${project_name}/helpers"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="2"/>
</listAttribute>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc}/helpers"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--unit-test --coverage-check"/>
<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
<stringAttribute key="org.python.pydev.debug.ATTR_PROJECT" value="pygitversionhelper"/>
<stringAttribute key="process_factory_id" value="org.python.pydev.debug.processfactory.PyProcessFactory"/>
</launchConfiguration>

View File

@@ -3,30 +3,32 @@
## Installation
From pypi repository (prefered):
python -m pip install pygitversionhelper
```console
/> python -m pip install pygitversionhelper
```
From downloaded .whl file:
```console
/> python -m pip install pygitversionhelper-<VERSION>-py3-none-any.whl
```
python -m pip install pygitversionhelper-<VERSION>-py3-none-any.whl
From master git repository:
python -m pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master
```console
/> python -m pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master
```
## Import in your project
Add this line on the top of your python script:
#from pygitversionhelper import gitversionhelper
```py
from pygitversionhelper import gitversionhelper
```
[optionnal] If you need to catch exception from this module:
#from pygitversionhelper import gitversionhelperException
```py
from pygitversionhelper import gitversionhelperException
```
## Basic API
All the API commands are static so it is not needed to create instantiate any object.
@@ -34,93 +36,100 @@ All the API commands are static so it is not needed to create instantiate any ob
They are all executed in the current active directory.
One easy way to change directory:
import os
os.chdir("<YOUR DIRECTORY>")
### sublib: repository
```py
import os
os.chdir("<YOUR DIRECTORY>")
```
### sub-lib: repository
To check if a repository is dirty:
if gitversionhelper.repository.isDirty():
print("repository is dirty")
### sublib: tag
```py
if gitversionhelper.repository.isDirty():
print("repository is dirty")
```
### sub-lib: tag
List all tags [default to taggerdate order]:
for tag in gitversionhelper.tag.getTags():
print(f"found tag: {tag}")
```py
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}")
```py
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()}")
```py
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)}")
```py
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()}")
```py
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
```py
print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag(same_branch=True)}")
```
### sub-lib: version
Get the last found version in the repository [return MetaVersion object]:
print(f"most recent repository version: {gitversionhelper.version.getLastVersion()}")
```py
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)}")
```py
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()}")
Get the current version of the repository, automatically bump it if the last commit is not tagged [returns MetaVersion object]:
```py
print(f"current repository version: {gitversionhelper.version.getCurrentVersion()}")
```
Or with formated output:
print(f"current repository version: {gitversionhelper.version.getCurrentVersion(formated_output=True)}")
```py
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}")
```py
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:
```py
_version = gitversionhelper.tag.getCurrentVersion()
```
Then;
```py
_version.doFormatVersion()
```
or;
```py
gitversionhelper.version.doFormatVersion(_version)
```
kwargs available to this function:
_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"]
- output_format: string to choose a rendering format ["Auto","PEP440" or "SemVer"]
## Limitations

View File

@@ -23,6 +23,7 @@ if __package__ == "helpers":
from .unit_test import unit_test
from .doc_gen import doc_gen
from .changelog_gen import changelog_gen
from .complexity_check import complexity_check
else:
# when calling the __main__.py file (from IDE)
from helpers.types_check import types_check
@@ -30,6 +31,7 @@ else:
from helpers.unit_test import unit_test
from helpers.doc_gen import doc_gen
from helpers.changelog_gen import changelog_gen
from helpers.complexity_check import complexity_check
logging.getLogger().setLevel(logging.INFO)
@@ -59,6 +61,8 @@ if __name__ == "__main__":
parser.add_argument("-clg", "--changelog-gen", dest="changeloggen", action="store_true", help="enable changelog generation")
parser.add_argument("-cpc", "--complexity-check", dest="complexitycheck", action="store_true", help="enable complexity check")
args = parser.parse_args()
##################################
@@ -73,6 +77,7 @@ if __name__ == "__main__":
# args.docgen = True
# args.docgenpdf = True
# args.changeloggen = True
# args.complexitycheck = True
helpers = []
if args.typecheck == True:
@@ -102,6 +107,9 @@ if __name__ == "__main__":
if args.changeloggen == True:
helpers.append(changelog_gen)
if args.complexitycheck == True:
helpers.append(complexity_check)
for helper in helpers:
helper.set_context(project_rootdir_path, pyproject)
helper.reset_result_dir()

View File

@@ -0,0 +1,69 @@
# pyChaChaDummyProject (c) by chacha
#
# pyChaChaDummyProject 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/>.
from __future__ import annotations
from typing import TYPE_CHECKING
# from pathlib import Path
# import os
import statistics
import csv
from json import loads as JSON_LOADS
from radon.complexity import cc_rank, SCORE
from radon.cli import Config
from radon.cli.harvest import CCHarvester, HCHarvester, MIHarvester
from .helper_base import helper_withresults_base
class complexity_check(helper_withresults_base):
@classmethod
def do_job(cls):
config = Config(
exclude="__init__\.py",
ignore=None,
order=SCORE,
show_closures=False,
no_assert=True,
min="A",
max="F",
multi=False,
)
h = MIHarvester([str(_) for _ in sorted((cls.project_rootdir_path / "src").rglob("*.py"))], config).as_json()
res = JSON_LOADS(h)
with open(cls.get_result_dir() / "MI.json", "w", newline="") as oFile:
oFile.write(h)
mean = statistics.mean(_["mi"] for _ in res.values())
if mean >= 65:
rank = "A+"
elif mean >= 20:
rank = "A"
elif mean >= 10:
rank = "B"
else:
rank = "C"
RES_MI = {"MeanMaintainability": mean, "MaintainabilityIndex": rank}
with open(cls.get_result_dir() / "MI.csv", "w", newline="") as oFile:
writer = csv.DictWriter(oFile, fieldnames=RES_MI.keys())
writer.writeheader()
writer.writerow(RES_MI)
config = Config(exclude=None, ignore=None, order=SCORE, show_closures=False, no_assert=True, min="A", max="F", multi=False)
h = CCHarvester([str(_) for _ in sorted((cls.project_rootdir_path / "src").rglob("*.py"))], config).as_json()
with open(cls.get_result_dir() / "CC.json", "w", newline="") as oFile:
oFile.write(h)
config = Config(exclude=None, ignore=None, order=SCORE, show_closures=False, no_assert=True, min="A", max="F", by_function=None)
h = HCHarvester([str(_) for _ in sorted((cls.project_rootdir_path / "src").rglob("*.py"))], config).as_json()
with open(cls.get_result_dir() / "HC.json", "w", newline="") as oFile:
oFile.write(h)

View File

@@ -31,8 +31,6 @@ class doc_gen(helper_withresults_base):
@classmethod
def do_job(cls):
print(cls.project_rootdir_path)
print()
# create doc root dir
doc_path = cls.project_rootdir_path / "docs"
@@ -74,9 +72,11 @@ class doc_gen(helper_withresults_base):
# little hack here, to enable / disable pdf generation using own class config
# => reason is mkdocs seems to try loading the plugin even if we disable it, so we need to
# manually process the configuration file.
mkdocsCfg = None
with open(cls.project_rootdir_path / "mkdocs.yml", "r") as mkdocsCfgFile:
mkdocsCfg = yaml.load(mkdocsCfgFile, Loader=yaml.SafeLoader)
mkdocsCfg = yaml.load(mkdocsCfgFile, Loader=yaml.Loader)
if "plugins" in mkdocsCfg:
mkdocsCfg["plugins"] = [_ for _ in mkdocsCfg["plugins"] if (not isinstance(_, dict) or "with-pdf" not in _.keys())]
if cls.enable_gen_pdf == True:
mkdocsCfg["plugins"].append(
@@ -85,19 +85,11 @@ class doc_gen(helper_withresults_base):
"cover_subtitle": "User Manual",
"cover_logo": str(cls.project_rootdir_path / "docs-static" / "Library.jpg"),
"verbose": False,
"media_type": "print",
"exclude_pages": ["LICENSE"],
"output_path": str(site_path / "pdf" / "manual.pdf"),
}
}
)
else:
for subelem in mkdocsCfg["plugins"]:
if isinstance(subelem, dict):
if "with-pdf" in subelem.keys():
mkdocsCfg["plugins"].remove(subelem)
break
with open(cls.project_rootdir_path / "mkdocs.yml", "w") as mkdocsCfgFile:
mkdocsCfgFile.write(yaml.dump(mkdocsCfg, Dumper=Dumper, default_flow_style=False, sort_keys=False))

View File

@@ -57,10 +57,11 @@ class helper_base(ABC):
return process.stdout
@classmethod
def run_cmd(cls, cmdarray):
def run_cmd(cls, cmdarray, silent: bool = False):
p = subprocess.run(cmdarray, capture_output=True)
print(p.stdout)
print(p.stderr)
if not silent:
print(p.stdout.decode())
print(p.stderr.decode())
return p.stdout

View File

@@ -37,7 +37,7 @@ class quality_check(helper_withresults_base):
def GetPylintMessageList(cls):
Messagelist = dict()
regex = r"^:([a-zA-Z-]+) \(([^\)]+)\)"
for line in cls.run_cmd([sys.executable, "-m", "pylint", "--list-msgs"]).splitlines():
for line in cls.run_cmd([sys.executable, "-m", "pylint", "--list-msgs"], True).splitlines():
if res := re.search(regex, line.decode()):
Messagelist[res.group(1)] = res.group(2)
cls.PylintMessageList = Messagelist
@@ -52,6 +52,7 @@ class quality_check(helper_withresults_base):
@classmethod
def do_job(cls):
print("checking code quality ...")
cls.GetPylintMessageList()
RES_all = dict()
@@ -60,6 +61,7 @@ class quality_check(helper_withresults_base):
with redirect_stdout(StdOutput):
pylint_Run(
[
"--load-plugins=pylint.extensions.mccabe",
"--output-format=json,parseable",
"--disable=invalid-name",
"--ignore=_version.py",

View File

@@ -24,22 +24,19 @@ class types_check(helper_withresults_base):
print("checking code typing ...")
result = api.run(
[ # project path
"-m",
"src." + str(cls.pyproject["project"]["name"]),
"-p",
"src." + cls.pyproject["project"]["name"],
# analysis configuration
"--ignore-missing-imports",
"--strict-equality",
# "--show-traceback",
"--explicit-package-bases",
# "--strict-equality",
# "--check-untyped-defs",
"--enable-incomplete-feature=Unpack",
# reports generation
"--cobertura-xml-report",
str(cls.get_result_dir()),
"--html-report",
str(cls.get_result_dir()),
"--linecount-report",
str(cls.get_result_dir()),
"--linecoverage-report",
str(cls.get_result_dir()),
"--lineprecision-report",
str(cls.get_result_dir()),
"--txt-report",
str(cls.get_result_dir()),
"--xml-report",
@@ -52,6 +49,9 @@ class types_check(helper_withresults_base):
if result[0]:
print("\nType checking report:\n")
print(result[0]) # stdout
# converting the report using pylint_json2html (/!\ internal API, but as their is no leading '_' ...)
with open(cls.get_result_dir() / "raw_eport.txt", "w+", encoding="utf-8") as Outfile:
Outfile.write(result[0])
if result[1]:
print("\nError report:\n")

View File

@@ -1,92 +1,117 @@
# pyChaChaDummyProject (c) by chacha
#
# pyChaChaDummyProject 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/>.
docs_dir: docs
site_name: pygitversionhelper
site_url: 'https://chacha.ddns.net/mkdocs-web/chacha/pygitversionhelper/latest/'
site_description: pygitversionhelper
site_author: ChaCha
repo_url: 'https://chacha.ddns.net/gitea/chacha/pygitversionhelper'
site_url: https://chacha.ddns.net/mkdocs-web/chacha/pygitversionhelper/latest/
site_description: A simple simple git version helper in python.
site_author: prune
repo_url: https://chacha.ddns.net/gitea/chacha/pygitversionhelper
use_directory_urls: false
copyright: CC BY-NC-SA 4.0
theme:
name: material
features:
- navigation.instant
- navigation.tracking
- navigation.tabs
- navigation.tabs.sticky
- toc.integrate
- navigation.top
- navigation.instant
- navigation.tracking
- navigation.tabs
- navigation.tabs.sticky
- navigation.footer
- toc.integrate
- navigation.top
- navigation.section
- content.code.annotate
- navigation.prune
- toc.follow
palette:
- media: '(prefers-color-scheme: dark)'
scheme: slate
toggle:
icon: material/brightness-4
name: Switch to system preference
- media: (prefers-color-scheme)
toggle:
icon: material/brightness-auto
name: Switch to light mode
- media: '(prefers-color-scheme: light)'
scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode
- media: '(prefers-color-scheme: dark)'
scheme: slate
toggle:
icon: material/brightness-4
name: Switch to system preference
- media: (prefers-color-scheme)
toggle:
icon: material/brightness-auto
name: Switch to light mode
- media: '(prefers-color-scheme: light)'
scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode
plugins:
- search
- markdownextradata
- mermaid2
- localsearch
- autorefs
- mkdocstrings:
default_handler: python
handlers:
python:
selection:
filters:
- '!^_(?!_init__)'
inherited_members: true
rendering:
show_root_heading: false
show_root_toc_entry: false
show_root_full_path: false
show_if_no_docstring: true
show_signature_annotations: true
show_source: false
heading_level: 2
group_by_category: true
show_category_heading: true
- search
- markdownextradata
- mermaid2
- localsearch
- mkdocstrings:
default_handler: python
handlers:
python:
options:
filters:
- '!^_[^_]'
inherited_members: true
show_if_no_docstring: true
show_signature_annotations: true
show_source: false
show_category_heading: true
group_by_category: true
docstring_section_style: spacy
show_root_full_path: false
merge_init_into_class: true
separate_signature: true
- with-pdf:
cover_subtitle: User Manual
cover_logo: C:\Users\chacha\git\pygitversionhelper\docs-static\Library.jpg
verbose: false
exclude_pages:
- LICENSE
output_path: C:\Users\chacha\git\pygitversionhelper\helpers-results\doc_gen\site\pdf\manual.pdf
markdown_extensions:
- def_list
- tables
- attr_list
- abbr
- pymdownx.betterem:
smart_enable: all
- pymdownx.caret
- pymdownx.critic
- pymdownx.details
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.keys
- pymdownx.mark
- pymdownx.progressbar
- pymdownx.smartsymbols
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.tilde
- footnotes
- def_list
- tables
- attr_list
- abbr
- pymdownx.blocks.admonition:
types:
- new
- settings
- note
- abstract
- info
- tip
- success
- question
- warning
- failure
- danger
- bug
- example
- quote
- pymdownx.blocks.definition
- pymdownx.blocks.details
- pymdownx.blocks.tab
- pymdownx.blocks.html
- pymdownx.betterem:
smart_enable: all
- pymdownx.caret
- pymdownx.critic
- pymdownx.details
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.keys
- pymdownx.mark
- pymdownx.progressbar
- pymdownx.smartsymbols
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.tilde
- footnotes
- pymdownx.superfences
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
extra:
branch: master
repository: pygitversionhelper
repository: pygitversionhelper

View File

@@ -12,11 +12,10 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
version_scheme= "post-release"
# tag_regex="^(?:v)?(?P<version>\\d+\\.\\d+\\.\\d+)([\\.\\-\\+])?(?:.*)?"
[project]
name = "pygitversionhelper"
description = "pygitversionhelper"
description = "A simple simple git version helper in python."
readme = "README.md"
requires-python = ">=3.9"
keywords = ["chacha","chacha","template","pygitversionhelper"]
@@ -57,9 +56,10 @@ Tracker = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper/issue
[project.optional-dependencies]
test = ["junitparser>=2.8","junit2html>=30.1","xmlrunner>=1.7","mypy>=0.99" ]
coverage-check = ["coverage>=7.0"]
complexity-check = ["radon>=5.1"]
quality-check = ["pylint>=2.15","pylint-json2html>=0.4","pandas>=1.5"]
type-check = ["mypy[reports]>=0.99" ]
doc-gen = ["mkdocs>=1.4.0", "mkdocs-material>=8.5", "mkdocs-localsearch>=0.9.0", "mkdocstrings[python]>=0.19", "mkdocs-with-pdf>=0.9.3","pyyaml>=6.0","pymdown-extensions>=9","mkdocs-markdownextradata-plugin","mkdocs-mermaid2-plugin"]
doc-gen = ["mkdocs>=1.4.0", "mkdocs-material>=8.5","mkdocs-pymdownx-material-extras", "mkdocs-localsearch>=0.9.0", "mkdocstrings[python]>=0.19", "mkdocs-with-pdf>=0.9.3","pyyaml>=6.0","pymdown-extensions>=9","mkdocs-markdownextradata-plugin","mkdocs-mermaid2-plugin"]
#[project.scripts]
#my-script = "my_package.module:function"

View File

@@ -0,0 +1,7 @@
# 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/>.

View File

@@ -5,17 +5,16 @@
#
# 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
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.
This library is made for repository that uses tags as version.
Support for non-version tags is optional and not well tested.
This module is the main project file, containing all the code.
@@ -23,34 +22,69 @@ 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
///Note
_Other Parameters_ are **kwargs
///
Attributes:
TKwargs: Kwargs type definition for type hints
"""
from __future__ import annotations
from typing import TYPE_CHECKING, cast, TypedDict, Literal
import os
import subprocess
import re
from copy import copy
import logging
from pathlib import Path
from packaging.version import VERSION_PATTERN as packaging_VERSION_PATTERN
if TYPE_CHECKING:
from typing import List, Optional, Any, Dict
from typing_extensions import Unpack
def _exec(cmd: str, root: str | os.PathLike | None = None, raw: bool = False) -> list[str]:
"""
helper function to handle system cmd execution
TKwargs = TypedDict(
"TKwargs",
{
"version_std": Optional[str],
"same_branch": Optional[bool],
"formated_output": Optional[bool],
"bump_type": Optional[str],
"bump_dev_strategy": Optional[str],
"merged_output": Optional[bool],
"ignore_unknown_tags": Optional[bool],
"output_format": Optional[str],
"ignore_merged": Optional[bool],
},
total=False,
)
def _exec(cmd: str, root: Optional[str | os.PathLike[str]] = None, raw: bool = False) -> str | List[str]:
"""helper function to handle system cmd execution
Args:
cmd: command line to be executed
root: root directory where the command need to be executed
raw: return bytes if True, str if False or None
Returns:
a list of command's return lines
a list of command's return lines or the raw output
"""
_root: Path
if isinstance(root, str):
_root = Path(root)
elif isinstance(root, os.PathLike):
_root = Path(root)
else:
_root = Path(os.getcwd())
p = subprocess.run(
cmd,
text=True,
cwd=root,
cwd=_root,
capture_output=True,
check=False,
timeout=2,
@@ -63,115 +97,99 @@ def _exec(cmd: str, root: str | os.PathLike | None = None, raw: bool = False) ->
if int(p.returncode) < 0:
raise gitversionhelper.unknownGITError(p.stderr)
if raw:
if raw is True:
return p.stdout
lines = p.stdout.splitlines()
return [line.rstrip() for line in lines if line.rstrip()]
class gitversionhelperException(Exception):
"""
general Module Exception
"""
"""general Module Exception"""
class gitversionhelper: # pylint: disable=too-few-public-methods
"""
main gitversionhelper class
"""
"""main gitversionhelper class"""
class wrongArguments(gitversionhelperException):
"""
wrong argument generic exception
"""
"""wrong argument generic exception"""
class unknownGITError(gitversionhelperException):
"""
unknown git error generic exception
"""
"""unknown git error generic exception"""
class unknownGITFatalError(unknownGITError):
"""
unknown fatal git error generic exception
"""
"""unknown fatal git error generic exception"""
class repository:
"""
class containing methods focusing on repository
"""
"""class containing methods focusing on repository"""
class repositoryException(gitversionhelperException):
"""
generic repository exeption
"""
"""generic repository exeption"""
class notAGitRepository(repositoryException):
"""
not a git repository exception
"""
"""not-a-git-repository repository exception"""
class repositoryDirty(repositoryException):
"""
dirty repository exception
"""
"""dirty-repository repository exception"""
@classmethod
def isDirty(cls) -> bool:
"""
check if the repository is in dirty state
"""check if the repository is in dirty state
Returns:
True if it is dirty
"""
return bool(_exec("git status --short"))
class commit:
"""
class containing methods focusing on commits
"""
__OptDict = {"same_branch": "same_branch", "merged_output": "merged_output"}
"""class containing methods focusing on commits"""
class commitException(gitversionhelperException):
"""
generic commit exception
"""
"""generic commit exception"""
class commitNotFound(commitException):
"""
tag not found exception
"""
"""tag not found exception"""
@classmethod
def getMessagesSinceTag(cls, tag: str, **kwargs) -> str:
"""
retrieve a commits message history from repository
from Latest commit to the given tag
def getMessagesSinceTag(cls, tag: str, **kwargs: Unpack[TKwargs]) -> str | List[str]:
"""Retrieve a commits message history from repository.
Start from Latest found commit until the given tag.
Args:
tag: tag of the commit where search will stop
Keyword Arguments:
merged_output: output one single merged string
same_branch(bool): force searching only in the same branch
kwargs/merged_output (bool): Output one single merged string
kwargs/same_branch (bool): Force searching only in the same branch
kwargs/ignore_merged (bool): ignore merged commits
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}")
str_cmd: str
if ("same_branch" in kwargs) and (kwargs["same_branch"] is True):
str_cmd = f"git rev-list --first-parent {tag_commit_id}..{current_commit_id}" # ok
else:
commits = _exec(f"git rev-list --ancestry-path {tag_commit_id}..{current_commit_id}")
str_cmd = f"git rev-list {tag_commit_id}..{current_commit_id}" # ok
if ("ignore_merged" in kwargs) and (kwargs["ignore_merged"] is True):
str_cmd = str_cmd + " --no-merges" # ok
try:
commits = _exec(str_cmd)
except gitversionhelper.unknownGITFatalError as _e:
raise cls.commitNotFound("no commit found in commit history") from _e
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")
if ("merged_output" in kwargs) and (kwargs["merged_output"] is True):
return os.linesep.join(result)
return result
@classmethod
def getMessage(cls, commit_hash: str) -> str:
"""
retrieve a commit message from repository
"""retrieve a commit message from repository
Args:
commit_hash: id of the commit
Returns:
@@ -179,10 +197,11 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
"""
try:
res = _exec(
f'git log -z --pretty="tformat:%B%-C()" -n 1 {commit_hash}',
f'git log -z --pretty="tformat:%B%-C()" -n 1 {commit_hash}', # ok
None,
True,
).rstrip("\x00")
)
res = cast(str, res).rstrip("\x00")
except gitversionhelper.unknownGITFatalError as _e:
raise cls.commitNotFound("no commit found in commit history") from _e
@@ -190,48 +209,51 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
@classmethod
def getFromTag(cls, tag: str) -> str:
"""
retrieve a commit from repository associated to a tag
"""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}")
res = _exec(f"git rev-list -n 1 {tag}") # ok
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
def getLast(cls, **kwargs: Unpack[TKwargs]) -> str:
"""retrieve last commit from repository
Keyword Arguments:
same_branch(bool): force searching only in the same branch
kwargs/same_branch (bool): force searching only in the same branch
kwargs/ignore_merged (bool): ignore merged commits
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
str_cmd: str
if ("same_branch" in kwargs) and (kwargs["same_branch"] is True):
str_cmd = "git rev-list --max-count=1 --date-order HEAD --first-parent" # ok
else:
res = _exec('git for-each-ref --sort=-committerdate refs/heads/ --count 1 --format="%(objectname)"')
str_cmd = "git log --format=%H --all -n1" # ok
if ("ignore_merged" in kwargs) and (kwargs["ignore_merged"] is True):
str_cmd = str_cmd + " --no-merges" # ok
try:
res = _exec(str_cmd)
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]
class tag:
"""
class containing methods focusing on tags
"""
"""class containing methods focusing on tags"""
__OptDict = {"same_branch": "same_branch"}
__validGitTagSort = [
"",
"v:refname",
@@ -243,48 +265,42 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
]
class tagException(gitversionhelperException):
"""
generic tag exception
"""
"""generic tag exception"""
class tagNotFound(tagException):
"""
tag not found exception
"""
"""tag-not-found tag exception"""
class moreThanOneTag(tagException):
"""
more than one tag exception
"""
"""more-than-one-tag tag exception"""
@classmethod
def getTags(cls, sort: str = "taggerdate", **kwargs) -> list[str | None]:
"""
retrieve all tags from a repository
def getTags(cls, Sort: str = "taggerdate", **kwargs: Unpack[TKwargs]) -> List[str]:
"""retrieve all tags from a repository
Args:
sort: sorting constraints (git format)
Sort: sorting constraints (git format)
Keyword Arguments:
kwargs/same_branch (bool): force searching only in the same branch
Returns:
the tags list
"""
if sort not in cls.__validGitTagSort:
raise gitversionhelper.wrongArguments("sort option not in allowed list")
if Sort not in cls.__validGitTagSort:
raise gitversionhelper.wrongArguments("Sort option not in allowed list")
if (cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True):
if ("same_branch" in kwargs) and (kwargs["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}")))
return list(reversed(_exec(f"git tag --merged {currentBranch[0]} --sort={Sort}")))
return list(reversed(_exec(f"git tag -l --sort={Sort}")))
@classmethod
def getLastTag(cls, **kwargs) -> str | None:
"""
retrieve the Latest tag from a repository
def getLastTag(cls, **kwargs: Unpack[TKwargs]) -> str:
"""retrieve the Latest tag from a repository
Keyword Arguments:
same_branch(bool): force searching only in the same branch
kwargs/same_branch (bool): force searching only in the same branch
Returns:
the tag
"""
if (cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True):
if ("same_branch" in kwargs) and (kwargs["same_branch"] is True):
res = _exec("git describe --tags --first-parent --abbrev=0")
else:
res = _exec("git rev-list --tags --date-order --max-count=1")
@@ -298,13 +314,12 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
return res[0]
@classmethod
def getDistanceFromTag(cls, tag: str = None, **kwargs) -> int:
"""
retrieve the distance between Latest commit and tag in the repository
def getDistanceFromTag(cls, tag: Optional[str] = None, **kwargs: Unpack[TKwargs]) -> int:
"""retrieve the distance between Latest commit and tag in the repository
Arguments:
tag: reference tag, if None the most recent one will be used
Keyword Arguments:
same_branch(bool): force searching only in the same branch
kwargs/same_branch (bool): force searching only in the same branch
Returns:
the tag
"""
@@ -313,18 +328,13 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
return int(_exec(f"git rev-list {tag}..HEAD --count")[0])
class version:
"""
class containing methods focusing on versions
"""
"""class containing methods focusing on versions"""
__OptDict = {
"version_std": "version_std",
"formated_output": "formated_output",
"output_format": "output_format",
"ignore_unknown_tags": "ignore_unknown_tags",
}
DefaultInputFormat = "Auto"
VersionStds = {
TVersionStds = TypedDict("TVersionStds", {"regex": str, "regex_preversion_num": str, "regex_build_num": str}, total=False)
VersionStds: dict[str, TVersionStds] = {
"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-]*)"
@@ -333,41 +343,32 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
"regex_preversion_num": r"(?:\.)(?P<num>(?:\d+(?!\w))+)",
"regex_build_num": r"(?:\.)(?P<num>(?:\d+(?!\w))+)",
},
"PEP440": {"regex": packaging_VERSION_PATTERN, "Auto": None},
"PEP440": {"regex": packaging_VERSION_PATTERN},
}
__versionReseted = False
class versionException(gitversionhelperException):
"""
generic version exception
"""
"""generic version exception"""
class noValidVersion(versionException):
"""
no valid version found exception
"""
"""no valid version found exception"""
class PreAndPostVersionUnsupported(versionException):
"""
pre and post release can not be present at the same time
"""
"""pre and post release can not be present at the same time"""
class MetaVersion:
"""
generic version object
"""
"""generic version object"""
__OptDict = {
"bump_type": "bump_type",
"bump_dev_strategy": "bump_dev_strategy",
"formated_output": "formated_output",
}
DefaultBumpType = "patch"
BumpTypes = ["major", "minor", "patch", "dev"]
DefaultBumpDevStrategy = "post"
BumpDevStrategys = ["post", "pre-patch", "pre-minor", "pre-major"]
TBumpTypes = Literal["major", "minor", "patch", "dev"]
DefaultBumpType: TBumpTypes = "patch"
BumpTypes: set[TBumpTypes] = {"major", "minor", "patch", "dev"}
version_std: str = "None"
TBumpDevStrategies = Literal["post", "pre-patch", "pre-minor", "pre-major"]
DefaultBumpDevStrategy: TBumpDevStrategies = "post"
BumpDevStrategies: set[TBumpDevStrategies] = {"post", "pre-patch", "pre-minor", "pre-major"}
TVersionStd = Literal["Auto", "PEP440", "SemVer"]
version_std: TVersionStd = "Auto"
major: int = 0
minor: int = 1
patch: int = 0
@@ -377,13 +378,13 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
def __init__(
self,
version_std,
major=0,
minor=1,
patch=0,
pre_count=0,
post_count=0,
raw="0.1.0",
version_std: TVersionStd = "Auto",
major: int = 0,
minor: int = 1,
patch: int = 0,
pre_count: int = 0,
post_count: int = 0,
raw: str = "0.1.0",
): # pylint: disable=R0913
self.version_std = version_std
self.major = major
@@ -394,50 +395,55 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
self.raw = raw
@classmethod
def _getBumpDevStrategy(cls, **kwargs) -> str:
"""
get selected bump_dev_strategy
def _getBumpDevStrategy(cls, **kwargs: Unpack[TKwargs]) -> str:
"""get selected bump_dev_strategy
Keyword Arguments:
bump_dev_strategy(str): the given bump_dev_strategy (can be None)
kwargs/bump_dev_strategy (str): the given bump_dev_strategy (can be None)
Returns:
Kwargs given bump_dev_strategy or the default one.
"""
BumpDevStrategy = cls.DefaultBumpDevStrategy
if cls.__OptDict["bump_dev_strategy"] in kwargs:
if kwargs[cls.__OptDict["bump_dev_strategy"]] in cls.BumpDevStrategys:
BumpDevStrategy = kwargs[cls.__OptDict["bump_dev_strategy"]]
BumpDevStrategy: str = cls.DefaultBumpDevStrategy
if kwargs and ("bump_dev_strategy" in kwargs):
if kwargs["bump_dev_strategy"] in cls.BumpDevStrategies:
BumpDevStrategy = kwargs["bump_dev_strategy"]
else:
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['bump_type']} requested")
raise gitversionhelper.wrongArguments(f"invalid {'bump_type'} requested")
return BumpDevStrategy
@classmethod
def _getBumpType(cls, **kwargs) -> str:
"""
get selected bump_type
def _getBumpType(cls, **kwargs: Unpack[TKwargs]) -> str:
"""get selected bump_type
Keyword Arguments:
bump_type(str): the given bump_type (can be None)
kwargs/bump_type (str): the given bump_type (can be None)
Returns:
Kwargs given bump_type or the default one.
"""
BumpType = cls.DefaultBumpType
if cls.__OptDict["bump_type"] in kwargs:
if kwargs[cls.__OptDict["bump_type"]] in cls.BumpTypes:
BumpType = kwargs[cls.__OptDict["bump_type"]]
BumpType: str = cls.DefaultBumpType
if "bump_type" in kwargs:
if kwargs["bump_type"] in cls.BumpTypes:
BumpType = kwargs["bump_type"]
else:
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['bump_type']} requested")
raise gitversionhelper.wrongArguments(f"invalid {'bump_type'} requested")
return BumpType
def bump(self, amount: int = 1, **kwargs) -> gitversionhelper.version.MetaVersion | str: # pylint: disable=R0912
"""
bump the version to the next one
def bump( # pylint: disable=R1260,R0912
self, amount: int = 1, **kwargs: Unpack[TKwargs]
) -> gitversionhelper.version.MetaVersion | str:
"""bump the version to the next one
Args:
amount: number of revision to bump
Keyword Arguments:
bump_type(str): the given bump_type (can be None)
bump_dev_strategy(str): the given bump_dev_strategy (can be None)
kwargs/bump_type (str): the given bump_type (can be None)
kwargs/bump_dev_strategy (str): the given bump_dev_strategy (can be None)
Returns:
the bumped version
"""
BumpType = self._getBumpType(**kwargs)
BumpType: str = self._getBumpType(**kwargs)
BumpDevStrategy = self._getBumpDevStrategy(**kwargs)
_v = copy(self)
if BumpType == "dev":
@@ -473,88 +479,97 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
_v.patch = _v.patch + amount
_v.pre_count = 0
_v.post_count = 0
_v.raw = _v.doFormatVersion(**kwargs)
if (self.__OptDict["formated_output"] in kwargs) and (kwargs[self.__OptDict["formated_output"]] is True):
if ("formated_output" in kwargs) and (kwargs["formated_output"] is True):
return _v.doFormatVersion(**kwargs)
return _v
def doFormatVersion(self, **kwargs) -> str:
"""
output a formated version string
def doFormatVersion(self, **kwargs: Unpack[TKwargs]) -> str:
"""output a formated version string
Keyword Arguments:
output_format: output format to render ("Auto" or "PEP440" or "SemVer")
kwargs/output_format: output format to render ("Auto" or "PEP440" or "SemVer")
Returns:
formated version string
"""
return gitversionhelper.version.doFormatVersion(self, **kwargs)
@classmethod
def _getVersionStd(cls, **kwargs) -> str:
"""
get selected version_std
def _getVersionStd(cls, **kwargs: Unpack[TKwargs]) -> gitversionhelper.version.MetaVersion.TVersionStd:
"""get selected version_std
Keyword Arguments:
version_std(str): the given version_std (can be None)
kwargs/version_std (str): the given version_std (can be None)
Returns:
Kwargs given version_std or the default one.
"""
VersionStd = cls.DefaultInputFormat
if cls.__OptDict["version_std"] in kwargs:
if kwargs[cls.__OptDict["version_std"]] in cls.VersionStds:
VersionStd = kwargs[cls.__OptDict["version_std"]]
VersionStd: str = cls.DefaultInputFormat
if "version_std" in kwargs:
if kwargs["version_std"] in cls.VersionStds:
VersionStd = kwargs["version_std"]
else:
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['version_std']} requested")
return VersionStd
raise gitversionhelper.wrongArguments(f"invalid {'version_std'} requested")
return cast(gitversionhelper.version.MetaVersion.TVersionStd, VersionStd)
@classmethod
def getCurrentVersion(cls, **kwargs) -> MetaVersion | str:
"""
get the current version or bump depending of repository state
def getCurrentVersion(cls, **kwargs: Unpack[TKwargs]) -> gitversionhelper.version.MetaVersion | str:
"""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)
kwargs/version_std (str): the given version_std (can be None)
kwargs/same_branch (bool): force searching only in the same branch
kwargs/formated_output (bool): output a formated version string
kwargs/bump_type (str): the given bump_type (can be None)
kwargs/bump_dev_strategy (str): the given bump_dev_strategy (can be None)
kwargs/output_format (str): output format to render ("Auto" or "PEP440" or "SemVer")
Returns:
the last version
"""
if gitversionhelper.repository.isDirty() is not False:
raise gitversionhelper.repository.repositoryDirty("The repository is dirty and a current version can not be generated.")
saved_kwargs = copy(kwargs)
if "formated_output" in kwargs:
del saved_kwargs["formated_output"]
_v = cls.getLastVersion(**saved_kwargs)
_v = cast(gitversionhelper.version.MetaVersion, cls.getLastVersion(**saved_kwargs))
if not cls.__versionReseted:
amount = gitversionhelper.tag.getDistanceFromTag(_v.raw, **kwargs)
_v = _v.bump(amount, **saved_kwargs)
amount = gitversionhelper.tag.getDistanceFromTag(_v.raw, **saved_kwargs)
_v = cast(gitversionhelper.version.MetaVersion, _v.bump(amount, **saved_kwargs))
if (cls.__OptDict["formated_output"] in kwargs) and (kwargs[cls.__OptDict["formated_output"]] is True):
if ("formated_output" in kwargs) and (kwargs["formated_output"] is True):
return _v.doFormatVersion(**kwargs)
return _v
@classmethod
def getCurrentFormatedVersion(cls, **kwargs) -> str:
"""
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
def getCurrentFormatedVersion(cls, **kwargs: Unpack[TKwargs]) -> str:
"""same as getCurrentVersion() with formated_output kwarg forced activated.
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)
kwargs/version_std (str): the given version_std (can be None)
kwargs/same_branch (bool): force searching only in the same branch
kwargs/bump_type (str): the given bump_type (can be None)
kwargs/bump_dev_strategy (str): the given bump_dev_strategy (can be None)
kwargs/output_format (str): output format to render ("Auto" or "PEP440" or "SemVer")
Returns:
the last version
"""
VersionStd = cls._getVersionStd(**kwargs)
kwargs["formated_output"] = True
return cast(str, cls.getCurrentVersion(**kwargs))
@classmethod
def _parseTag( # pylint: disable=R1260,R0914,R0912,R0915
cls, tag: str, **kwargs: Unpack[TKwargs]
) -> gitversionhelper.version.MetaVersion:
"""get version from tags.
Arguments:
tag: the tag to be parsed
Keyword Arguments:
kwargs/version_std (str): the given version_std (can be None)
Returns:
MetaVersion object
"""
_m: Optional[re.Match[str]]
VersionStd: gitversionhelper.version.MetaVersion.TVersionStd = cls._getVersionStd(**kwargs)
bAutoVersionStd = False
if VersionStd == "Auto":
bAutoVersionStd = True
@@ -565,14 +580,12 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
re.VERBOSE | re.IGNORECASE,
)
_m = re.match(_r, tag)
if not _m:
if _m is None:
pass
else:
major, minor, patch = (
int(_m.group("major")),
int(_m.group("minor")),
int(_m.group("patch")),
)
major = int(_m.group("major"))
minor = int(_m.group("minor"))
patch = int(_m.group("patch"))
pre_count = 0
if _pre := _m.group("prerelease"):
@@ -596,19 +609,25 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
re.VERBOSE | re.IGNORECASE,
)
_m = re.match(_r, tag)
if not _m:
if _m is None:
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"
res: str = _m.group("release")
if isinstance(res, str):
ver = res.split(".")
ver += ["0"] * (3 - len(ver))
ver_int: List[int] = [0, 0, 0]
ver_int[0] = int(ver[0])
ver_int[1] = int(ver[1])
ver_int[2] = int(ver[2])
major, minor, patch = tuple(ver_int)
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")
@@ -618,30 +637,30 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
return cls.MetaVersion(VersionStd, major, minor, patch, pre_count, post_count, tag)
@classmethod
def getLastVersion(cls, **kwargs) -> MetaVersion | str: # pylint: disable=R0914, R0912, R0915
def getLastVersion(cls, **kwargs: Unpack[TKwargs]) -> gitversionhelper.version.MetaVersion | str: # pylint: disable=R1260
"""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)
kwargs/version_std (str): the given version_std (can be None)
kwargs/same_branch (bool): force searching only in the same branch
kwargs/formated_output (bool): output a formated version string
kwargs/ignore_unknown_tags (bool): skip tags with not decoded versions (default to False)
Returns:
the last version
the last version in MetaVersion object or string
"""
lastTag = cls.MetaVersion.raw
lastTag: str = cls.MetaVersion.raw
cls.__versionReseted = False
try:
lastTag = gitversionhelper.tag.getLastTag(**kwargs)
lastTag = cast(str, gitversionhelper.tag.getLastTag(**kwargs))
except gitversionhelper.tag.tagNotFound:
logging.warning("tag not found, reseting versionning")
cls.__versionReseted = True
_v = None
_v: Optional[gitversionhelper.version.MetaVersion] = 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)
if ("ignore_unknown_tags" in kwargs) and (kwargs["ignore_unknown_tags"] is True):
tags = gitversionhelper.tag.getTags(Sort="taggerdate", **kwargs)
_v = None
for _tag in tags:
try:
@@ -652,16 +671,15 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
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):
if ("formated_output" in kwargs) and (kwargs["formated_output"] is True):
return _v.doFormatVersion(**kwargs)
return _v
@classmethod
def doFormatVersion(cls, inputversion: MetaVersion, **kwargs) -> str:
"""
output a formated version string
def doFormatVersion(cls, inputversion: MetaVersion, **kwargs: Unpack[TKwargs]) -> str:
"""output a formated version string from a MetaVersion object
Keyword Arguments:
output_format: output format to render ("Auto" or "PEP440" or "SemVer")
kwargs/output_format (str): output format to render ("Auto" or "PEP440" or "SemVer")
Args:
inputversion: version to be rendered
Returns:
@@ -672,15 +690,13 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
if VersionStd == "Auto":
VersionStd = inputversion.version_std
OutputFormat = None
revpattern = ""
revcount = ""
post_count = inputversion.post_count
pre_count = inputversion.pre_count
patch = inputversion.patch
if cls.__OptDict["output_format"] in kwargs:
OutputFormat = kwargs[cls.__OptDict["output_format"]]
OutputFormat = kwargs.get("output_format")
if OutputFormat is None:
OutputFormat = "{major}.{minor}.{patch}{revpattern}{revcount}"

View File

@@ -730,9 +730,9 @@ class Test_gitversionhelper(unittest.TestCase):
with self.assertRaises(pygitversionhelper.gitversionhelper.version.PreAndPostVersionUnsupported):
pygitversionhelper.gitversionhelper.version._parseTag("0.0.1.pre1.post1")
def test_defect__git__wrongargument_sortargs(self):
def test_defect__git__wrongargument_Sortargs(self):
with self.assertRaises(pygitversionhelper.gitversionhelper.wrongArguments):
pygitversionhelper.gitversionhelper.tag.getTags(sort="toto")
pygitversionhelper.gitversionhelper.tag.getTags(Sort="toto")
def test_defect__git__notagfound(self):
with open("demofile.txt", "w+t") as tmpFile:
@@ -1009,6 +1009,16 @@ class Test_gitversionhelper(unittest.TestCase):
self.assertEqual(_v.minor, 3)
self.assertEqual(_v.patch, 0)
with open("demofile.txt", "w+t") as tmpFile:
tmpFile.write("testvalue4")
os.system("git add .")
os.system('git commit -m "4th commit"')
with open("demofile.txt", "w+t") as tmpFile:
tmpFile.write("testvalue5")
os.system("git add .")
os.system('git commit -m "5th commit"')
os.system("git switch master")
_v = pygitversionhelper.gitversionhelper.version.getLastVersion(version_std="PEP440")
@@ -1404,6 +1414,17 @@ class Test_gitversionhelper(unittest.TestCase):
cmd = "git commit -m".split()
cmd.append(commit_message5)
subprocess.run(cmd, text=True, check=True)
os.system(f"git tag 0.1.1.post4")
commit_message6 = "6.1 update this" + os.linesep + "6.1 fix that" + os.linesep + "6.1 test"
commit_message6 = commit_message6.replace("\r\n", "\n").replace("\n", "\r\n")
with open("demofile.txt", "w+t") as tmpFile:
tmpFile.write("testvalue6")
os.system("git add .")
cmd = "git commit -m".split()
cmd.append(commit_message6)
subprocess.run(cmd, text=True, check=True)
cmd = "git switch master".split()
subprocess.run(cmd, text=True, check=True)
@@ -1412,7 +1433,42 @@ class Test_gitversionhelper(unittest.TestCase):
self.assertEqual(os.linesep.join([commit_message4, commit_message3, commit_message2]), res)
res = pygitversionhelper.gitversionhelper.commit.getMessagesSinceTag("0.1.1", merged_output=True)
self.assertEqual(os.linesep.join([commit_message5, commit_message4, commit_message3, commit_message2]), res)
self.assertEqual(os.linesep.join([commit_message6, commit_message5, commit_message4, commit_message3, commit_message2]), res)
time.sleep(1)
merge_message = "automerge"
cmd = "git merge --no-ff dev -m".split()
cmd.append(merge_message)
subprocess.run(cmd, text=True, check=True)
res = pygitversionhelper.gitversionhelper.commit.getMessagesSinceTag("0.1.1", merged_output=True, same_branch=True)
self.assertEqual(os.linesep.join([merge_message, commit_message4, commit_message3, commit_message2]), res)
res = pygitversionhelper.gitversionhelper.commit.getMessagesSinceTag("0.1.1", merged_output=True)
self.assertEqual(
set(
merge_message.splitlines()
+ commit_message6.splitlines()
+ commit_message5.splitlines()
+ commit_message4.splitlines()
+ commit_message3.splitlines()
+ commit_message2.splitlines()
),
set(res.splitlines()),
)
res = pygitversionhelper.gitversionhelper.commit.getMessagesSinceTag("0.1.1", merged_output=True, ignore_merged=True)
self.assertEqual(
set(
commit_message6.splitlines()
+ commit_message5.splitlines()
+ commit_message4.splitlines()
+ commit_message3.splitlines()
+ commit_message2.splitlines()
),
set(res.splitlines()),
)
def tearDown(self):
os.chdir("/")