Compare commits

...

79 Commits

Author SHA1 Message Date
00882db033 Merge pull request 'dev' (#40) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/40
new-tag:1.3.5
2023-11-06 16:13:04 +01:00
cclecle
5dc86907b6 update from last project template 2023-11-06 15:05:27 +00:00
cclecle
ce7d23f44b split quality & types .launch scripts 2023-11-06 15:01:10 +00:00
eb5bbc2900 Merge pull request 'chore: remove useless data dir' (#39) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/39
new-tag:1.3.4
2023-09-30 01:54:47 +02:00
cclecle
deb9b618d1 chore: remove useless data dir
fix: correct function doc (Google docstrings)
fix: add py.tyed to dist
2023-09-30 00:18:40 +01:00
7c48c8c55e Merge pull request 'fix: switch to pypi version of chacha-cicd-helper' (#38) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/38
new-tag:1.3.3
2023-09-30 00:54:11 +02:00
cclecle
7198f9309d fix: switch to pypi version of chacha-cicd-helper 2023-09-29 23:50:35 +01:00
ac1535e02d Merge pull request 'chore: switch from helpers to chacha_cicd_helper' (#37) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/37
new-tag:1.3.2
2023-09-30 00:07:14 +02:00
cclecle
068e834f7c chore: switch from helpers to chacha_cicd_helper 2023-09-29 23:03:48 +01:00
8049477a5c Merge pull request 'chore: dummy change' (#36) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/36
new-tag:1.3.1
2023-09-24 20:31:09 +02:00
cclecle
d430907f12 chore: dummy change 2023-09-24 19:27:16 +01:00
a87a717b9e Merge pull request 'feat: add py.typed for mypy' (#35) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/35
2023-09-24 20:24:51 +02:00
cclecle
0be71a4c3c feat: add py.typed for mypy 2023-09-24 19:21:29 +01:00
ca7a69ae76 Merge pull request 'dev' (#34) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/34
new-tag:1.3.0
2023-09-24 20:18:10 +02:00
cclecle
114aa31115 cicd: add "--enable-incomplete-feature=Unpack" 2023-09-24 19:13:34 +01:00
cclecle
facd431c59 update docgen & cicd tools 2023-09-24 18:56:29 +01:00
d4b90b1f91 Merge pull request 'Fix title' (#33) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/33
new-tag: 1.2.2
2023-03-28 02:39:04 +02:00
cclecle
a07bcc37c4 Fix title 2023-03-28 01:09:46 +01:00
ac70d4dde4 Merge pull request 'beautify jenkins file' (#32) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/32
new-tag: 1.2.1
2023-03-28 02:05:30 +02:00
cclecle
0d1e981b6b beautify jenkins file 2023-03-28 01:01:10 +01:00
6e1c60ee53 Merge pull request 'dev' (#31) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/31
newt-tag: 1.2.1
2023-03-28 01:55:24 +02:00
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
dd6f24a82e Merge pull request 'dev' (#30) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/30
new-tag: 1.2.0
2023-03-28 01:16:59 +02: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
78d7fbe39d Merge pull request 'dev' (#29) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/29
new-tag:1.1.0
2023-03-27 03:03:53 +02: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
3f5ee5f117 Merge pull request 'improve project configuration from pychangelogfactory' (#28) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/28
new-tag: 1.0.12
2023-03-25 21:05:05 +01:00
cclecle
e64dcf4978 improve project configuration from pychangelogfactory 2023-03-25 19:59:20 +00:00
2d16b0e264 Merge pull request 'dev' (#27) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/27
new-tag: 1.0.11
2023-03-25 00:00:31 +01: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
088dbf8a90 Merge pull request 'dev' (#26) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/26
new-tag:1.0.10
2023-03-24 22:27:57 +01: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
bd49b23b59 Merge pull request 'dev' (#25) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/25
new-tag: 1.0.9
2023-03-24 21:09:23 +01: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
f5d61d8d04 Merge pull request 'fix: twine cmd line' (#24) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/24
new-tag: 1.0.8
2023-03-22 10:49:23 +01:00
d21c839f07 Merge pull request 'dev' (#23) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/23
new-tag: 1.0.7
2023-03-22 10:03:04 +01:00
6542c80e8f Merge pull request 'fix usernamePassword in jenkins' (#22) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/22
new-tag:1.0.6
2023-03-22 01:00:21 +01:00
4272a55dde Merge pull request 'dev' (#21) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/21
new-tag:1.0.5
2023-03-22 00:49:37 +01:00
382e39e684 Merge pull request 'dev' (#20) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/20
new-tag:1.0.4
2023-03-20 10:12:13 +01:00
34c07e0d9f Merge pull request 'escape toml' (#19) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/19
new-tag:1.0.3
2023-03-20 01:16:37 +01:00
2c9886b251 Merge pull request 'test: tag_regex to extract verison only' (#18) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/18
new-tag:1.0.4
2023-03-20 01:14:17 +01:00
782562eef8 Merge pull request 'dev' (#17) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/17
new-tag:1.0.3
2023-03-20 00:15:31 +01:00
82c32ff58c Merge pull request 'dev' (#16) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/16
new-tag:1.0.2
2023-03-19 22:59:59 +01:00
794e54c88b Merge pull request 'dev' (#15) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/15
new-tag:1.0.1
2023-03-19 21:58:48 +01:00
078f5624b2 Merge pull request 'fix: project username' (#14) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/14
new-tag: 1.0.0
2023-03-19 21:02:07 +01:00
44c10b88a5 Merge pull request 'fix: typo in jenkins pipeline file' (#13) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/13
new-tag: 1.0.0
2023-03-19 20:57:20 +01:00
a4b7b27a65 Merge pull request 'dev' (#12) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/12
new-tag:1.0.0
2023-03-19 20:53:01 +01:00
77e2be2714 Merge pull request 'fix: remove branch on git push (useless)' (#11) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/11
new-tag:1.0.0
2023-03-19 20:41:37 +01:00
f422b9ff7d Merge pull request 'fix git tag cmd' (#10) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/10
new-tag:1.0.0
2023-03-19 20:34:23 +01:00
660270d49b Merge pull request 'fix git username/address in jenkinsfile' (#9) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/9
new-tag:1.0.0
2023-03-19 20:29:40 +01:00
9f442a7b8e Merge pull request 'update jenkinsfile' (#8) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/8
new-tag:1.0.0
2023-03-19 20:24:31 +01:00
8fb9ba8406 Merge pull request 'dev' (#7) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/7
2023-03-19 20:02:38 +01:00
38abaa58c5 Merge pull request 'fix deps' (#6) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/6
2023-03-19 19:47:06 +01:00
35d75ea019 Merge pull request 'dev' (#5) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/5
2023-03-19 19:43:17 +01:00
0b8651a30a Merge pull request 'dev' (#4) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/4
2023-03-19 19:22:48 +01:00
c5b3055bfe Merge pull request 'feature: add log-line in pipeline' (#3) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/3
2023-03-19 11:39:08 +01:00
92a1d1a30f Merge pull request 'update jenkinsFile' (#2) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/2
2023-03-19 11:29:50 +01:00
f2c0bf1ddd Merge pull request 'bump master release' (#1) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/1
2023-03-19 11:23:54 +01:00
27 changed files with 798 additions and 1251 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>

148
Jenkinsfile vendored
View File

@@ -26,7 +26,7 @@ def _bPreRelease = false
def _bDraft = false
// release content / changelog management
def _bAutoChangelog = true //Not supported yet
def _ReleaseContent_Title = "_CI/CD Automatic Release_"
def _ReleaseContent_Title = "# _CI/CD Automatic Release_"
def bPushMasterOnPypi = true
// full rebuild toogle
def _bFullRebuilt = true
@@ -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 {
@@ -182,18 +183,20 @@ pipeline {
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")
sh(". ~/BUILD_ENV/bin/activate && pip install --upgrade setuptools build pip")
sh(". ~/BUILD_ENV/bin/activate && pip install --upgrade 'copier==8.*' jinja2-slug toml")
sh(". ~/TEST_ENV/bin/activate && pip install --upgrade pip")
sh(". ~/TOOLS_ENV/bin/activate && pip install simple_rest_client requests twine")
sh(". ~/TOOLS_ENV/bin/activate && pip install --upgrade pip")
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 +220,32 @@ 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()) {
@@ -316,7 +345,7 @@ pipeline {
|'''.strip()
|
|import copier
|copier.run_auto("./", "../_gitrepo",vcs_ref="HEAD",use_prereleases=True,defaults=True,cleanup_on_error=False)
|copier.run_copy("./", "../_gitrepo",vcs_ref="HEAD",use_prereleases=True,defaults=True,cleanup_on_error=False,unsafe=True)
|
|__EOWRAPPER__
""".stripMargin())
@@ -384,27 +413,44 @@ pipeline {
stage("CheckCode") {
steps {
dir("gitrepo") {
sh(". ~/TEST_ENV/bin/activate && python -m helpers --type-check --quality-check")
sh(". ~/TEST_ENV/bin/activate && python -m chacha_cicd_helper --typecheck --qualitycheck")
script {
def jsonObj = readJSON file: "helpers-results/quality_check/metrics.json"
def jsonObj = readJSON file: "helpers-results/cl_quality_check/metrics.json"
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")
sh(". ~/TEST_ENV/bin/activate && python -m chacha_cicd_helper --complexitycheck")
}
}
post {
always {
dir("gitrepo") {
publishHTML([
reportDir: "helpers-results/quality_check",
reportFiles: "report.html",
reportName: "quality-report",
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true])
dir("gitrepo") {
//publish coverage
recordCoverage( sourceDirectories: [[path: 'src']],
tools: [[parser: 'COBERTURA', pattern: 'helpers-results/cl_types_check/cobertura.xml']],
id: 'COBERTURA', name: 'COBERTURA Coverage',
sourceCodeRetention: 'EVERY_BUILD',)
//add type check to junit result set
junit 'helpers-results/cl_types_check/junit.xml'
//publish html reports files
publishHTML([
reportDir: "helpers-results/cl_quality_check",
reportFiles: "report.html",
reportName: "quality-report",
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true])
publishHTML([
reportDir: "helpers-results/cl_types_check",
reportFiles: "index.html",
reportName: "types_check",
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true])
}
}
}
@@ -413,7 +459,7 @@ pipeline {
steps {
plot([ csvFileName: 'plot-df7f03dc-8146-11ed-a1eb-0242ac120002.csv',
csvSeries: [[ file: 'gitrepo/helpers-results/quality_check/metrics_GlobalScore.csv', inclusionFlag: 'OFF', url: '']],
csvSeries: [[ file: 'gitrepo/helpers-results/cl_quality_check/metrics_GlobalScore.csv', inclusionFlag: 'OFF', url: '']],
group: 'metrics',
title: 'code quality score',
style: 'line',
@@ -423,7 +469,7 @@ pipeline {
yaxisMinimum: '0'])
plot([ csvFileName: 'plot-c731cc84-8145-11ed-a1eb-0242ac120002.csv',
csvSeries: [[ file: 'gitrepo/helpers-results/quality_check/metrics_rawpercent.csv', inclusionFlag: 'OFF', url: '']],
csvSeries: [[ file: 'gitrepo/helpers-results/cl_quality_check/metrics_rawpercent.csv', inclusionFlag: 'OFF', url: '']],
group: 'metrics',
title: 'code composition (%)',
style: 'stackedArea',
@@ -433,7 +479,7 @@ pipeline {
yaxisMinimum: '0'])
plot([ csvFileName: 'plot-cac33982-8145-11ed-a1eb-0242ac120002.csv',
csvSeries: [[ file: 'gitrepo/helpers-results/quality_check/metrics_Statistics.csv', inclusionFlag: 'OFF', url: '']],
csvSeries: [[ file: 'gitrepo/helpers-results/cl_quality_check/metrics_Statistics.csv', inclusionFlag: 'OFF', url: '']],
group: 'metrics',
title: 'general statistics',
style: 'line',
@@ -441,7 +487,7 @@ pipeline {
numBuilds: ''])
plot([ csvFileName: 'plot-cddaced2-8145-11ed-a1eb-0242ac120002.csv',
csvSeries: [[ file: 'gitrepo/helpers-results/quality_check/metrics_MessagesCat.csv', inclusionFlag: 'OFF', url: '']],
csvSeries: [[ file: 'gitrepo/helpers-results/cl_quality_check/metrics_MessagesCat.csv', inclusionFlag: 'OFF', url: '']],
group: 'metrics',
title: 'quality warnings',
style: 'stackedArea',
@@ -449,7 +495,7 @@ pipeline {
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: '']],
csvSeries: [[ file: 'gitrepo/helpers-results/cl_complexity_check/MI.csv', inclusionFlag: 'INCLUDE_BY_STRING',exclusionValues: 'MeanMaintainability', url: '']],
group: 'metrics',
title: 'maintainability',
style: 'stackedArea',
@@ -461,14 +507,14 @@ pipeline {
stage("RunUnitTests") {
steps {
dir("gitrepo") {
sh(". ~/TEST_ENV/bin/activate && python -m helpers --unit-test --coverage-check")
sh(". ~/TEST_ENV/bin/activate && python -m chacha_cicd_helper --unittest --coveragecheck")
script {
unit_test_full_name__html=findFiles(glob: "helpers-results/unit_test_full/*.html")[0].getName()
unit_test_full_name__html=findFiles(glob: "helpers-results/cl_unit_test_full/*.html")[0].getName()
println unit_test_full_name__html
unit_test_full_name__xml=findFiles(glob: "helpers-results/unit_test_full/*.xml")[0].getName()
unit_test_full_name__xml=findFiles(glob: "helpers-results/cl_unit_test_full/*.xml")[0].getName()
println unit_test_full_name__xml
coverage_report_path = "helpers-results/unit_test_coverage/test_coverage.xml"
coverage_report_path = "helpers-results/cl_unit_test_coverage/test_coverage.xml"
println GetCoverageValue_lines_valid(coverage_report_path)
println GetCoverageValue_lines_covered(coverage_report_path)
println GetCoverageValue_line_rate(coverage_report_path)
@@ -481,27 +527,28 @@ pipeline {
sz_full_rate = full_rate.setScale(2, RoundingMode.HALF_EVEN).toString()
badge_coverage.setStatus(sz_full_rate)
badge_coverage.setColor(getColorScale(full_rate))
//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))
//badge_maintainability
records = readCSV file: 'gitrepo/helpers-results/complexity_check/MI.csv'
badge_maintainability.setStatus(records[1][1])
records = readCSV file: 'helpers-results/cl_complexity_check/MI.csv'
maintainability = records[1][1]
badge_maintainability.setStatus(maintainability)
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")}
}
}
}
post {
always {
dir("gitrepo") {
junit 'helpers-results/unit_test/*.xml'
junit 'helpers-results/cl_unit_test/*.xml'
// using cobertura format (= coverage xml format)
publishCoverage adapters: [cobertura(mergeToOneReport: true, path: "helpers-results/unit_test_coverage/test_coverage.xml")]
publishCoverage adapters: [cobertura(mergeToOneReport: true, path: "helpers-results/cl_unit_test_coverage/test_coverage.xml")]
publishHTML([
reportDir: "helpers-results/unit_test_coverage",
reportDir: "helpers-results/cl_unit_test_coverage",
reportFiles: "index.html",
reportName: "coverage-report-html",
allowMissing: false,
@@ -509,7 +556,7 @@ pipeline {
keepAll: true])
publishHTML([
reportDir: "helpers-results/unit_test_full",
reportDir: "helpers-results/cl_unit_test_full",
reportFiles: unit_test_full_name__html,
reportName: "test-reports-full",
allowMissing: false,
@@ -523,15 +570,14 @@ pipeline {
stage("GenDOC") {
steps {
dir("gitrepo") {
//--doc-gen-pdf
sh(". ~/TEST_ENV/bin/activate && python -m helpers --doc-gen --doc-gen-pdf")
sh(". ~/TEST_ENV/bin/activate && python -m chacha_cicd_helper --docgen --docgenpdf")
}
}
post {
always {
dir("gitrepo") {
publishHTML([
reportDir: "helpers-results/doc_gen/site",
reportDir: "helpers-results/cl_doc_gen/site",
reportFiles: "index.html",
reportName: "doc-html",
allowMissing: false,
@@ -563,6 +609,7 @@ pipeline {
|from simple_rest_client.api import API
|from simple_rest_client.resource import Resource
|
|
|try:
| from pygitversionhelper import gitversionhelper
|except ImportError:
@@ -609,6 +656,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,
@@ -628,11 +682,11 @@ pipeline {
|
|data = {
| "name": "Documentation (pdf)",
| 'attachment': ("${PY_PROJECT_NAME}_${PY_PROJECT_VERSION}_UserManual.pdf", open("helpers-results/doc_gen/site/pdf/manual.pdf", 'rb')),
| 'attachment': ("${PY_PROJECT_NAME}_${PY_PROJECT_VERSION}_UserManual.pdf", open("helpers-results/cl_doc_gen/site/pdf/manual.pdf", 'rb')),
|}
|GiteaApi.assets.post("${_PROJECT_USER_NAME}","${PY_PROJECT_NAME}",new_release_id,files=data)
|
|shutil.make_archive("doc", 'zip', "helpers-results/doc_gen/site")
|shutil.make_archive("doc", 'zip', "helpers-results/cl_doc_gen/site")
|reqData={
| "SECRET": "${MKDOCSTOKEN}",
| "USER": "${_PROJECT_USER_NAME}",

View File

@@ -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

17
RUN_complexity.launch Normal file
View File

@@ -0,0 +1,17 @@
<?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="/pygitversionhelper/helpers_proxy"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="2"/>
</listAttribute>
<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="UTF-8"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:pygitversionhelper/helpers_proxy}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--complexitycheck"/>
<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>

17
RUN_mkdocs.launch Normal file
View File

@@ -0,0 +1,17 @@
<?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="/pygitversionhelper/helpers_proxy"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="2"/>
</listAttribute>
<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="UTF-8"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:pygitversionhelper/helpers_proxy}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--docgen --docgenpdf"/>
<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>

17
RUN_quality.launch Normal file
View File

@@ -0,0 +1,17 @@
<?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="/pygitversionhelper/helpers_proxy"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="2"/>
</listAttribute>
<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="UTF-8"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:pygitversionhelper/helpers_proxy}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--qualitycheck"/>
<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>

17
RUN_types.launch Normal file
View File

@@ -0,0 +1,17 @@
<?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="/pygitversionhelper/helpers_proxy"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="2"/>
</listAttribute>
<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="UTF-8"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:pygitversionhelper/helpers_proxy}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--typecheck"/>
<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>

17
RUN_unittest.launch Normal file
View File

@@ -0,0 +1,17 @@
<?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="/pygitversionhelper/helpers_proxy"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="2"/>
</listAttribute>
<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="UTF-8"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:pygitversionhelper/helpers_proxy}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--unittest --coveragecheck"/>
<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,98 +36,105 @@ 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
There is unfortunately some technical limitation :
* MultiThreading and async behavior is not tested.
* MultiThreading and async behavior is not tested / supported.
* Multiple tag on the same commit is not supported.
* Branch filter when searching for a version is only tested with -no-ff strategy

1
helpers/.gitignore vendored
View File

@@ -1 +0,0 @@
/.mypy_cache/

View File

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

View File

@@ -1,116 +0,0 @@
# 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 tomli
import argparse
import os
import logging
import sys
if __package__ == "helpers":
# when calling the module from: > python -m helpers
from .types_check import types_check
from .quality_check import quality_check
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
from helpers.quality_check import quality_check
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)
if __name__ == "__main__":
project_rootdir_path = Path(__file__).parent.parent.absolute()
with open(project_rootdir_path / "pyproject.toml", mode="rb") as fp:
pyproject = tomli.load(fp)
parser = argparse.ArgumentParser(
prog="continuous-integration-helper", description="A tiny set of scripts to help continous integration on python"
)
parser.add_argument("-tc", "--type-check", dest="typecheck", action="store_true", help="enable static typing check")
parser.add_argument("-ut", "--unit-test", dest="unittest", action="store_true", help="enable unit-test")
parser.add_argument(
"-cc", "--coverage-check", dest="coveragecheck", action="store_true", help="enable unit-test coverage check (requires unit-test)"
)
parser.add_argument("-qc", "--quality-check", dest="qualitycheck", action="store_true", help="enable code quality check")
parser.add_argument("-dg", "--doc-gen", dest="docgen", action="store_true", help="enable documentation generation using MkDoc")
parser.add_argument(
"-pdf", "--doc-gen-pdf", dest="docgenpdf", action="store_true", help="enable pdf documentation export (requires doc-gen)"
)
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()
##################################
# Dev / Debug forced toogles
#
# --------------------------------
#
# args.typecheck = True
# args.qualitycheck = True
# args.unittest = True
# args.coveragecheck = True
# args.docgen = True
# args.docgenpdf = True
# args.changeloggen = True
# args.complexitycheck = True
helpers = []
if args.typecheck == True:
helpers.append(types_check)
if args.unittest == True:
helpers.append(unit_test)
if args.coveragecheck == True:
if args.unittest == True:
unit_test.enable_coverage_check = True
else:
raise RuntimeError("unit-test is required to enable coverage-check")
if args.qualitycheck == True:
helpers.append(quality_check)
if args.docgen == True:
helpers.append(doc_gen)
if args.docgenpdf == True:
if args.docgen == True:
doc_gen.enable_gen_pdf = True
else:
raise RuntimeError("doc-gen is required to enable doc-gen-pdf")
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()
helper.do_job()

View File

@@ -1,23 +0,0 @@
# 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 datetime
from .helper_base import helper_base
class changelog_gen(helper_base):
@classmethod
def do_job(cls):
pass

View File

@@ -1,70 +0,0 @@
# 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
from pprint import pprint
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

@@ -1,104 +0,0 @@
# 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
import shutil
import os
import sys
import subprocess
from pathlib import Path
from distutils.dir_util import copy_tree
import yaml
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
from .helper_base import helper_withresults_base
class doc_gen(helper_withresults_base):
enable_gen_pdf: bool = False
@classmethod
def do_job(cls):
# create doc root dir
doc_path = cls.project_rootdir_path / "docs"
cls._reset_dir(doc_path)
site_path = cls.get_result_dir() / "site"
cls._reset_dir(site_path)
# copy files from main project dir
shutil.copyfile(str(cls.project_rootdir_path / "README.md"), str(doc_path / "README.md"))
shutil.copyfile(str(cls.project_rootdir_path / "LICENSE.md"), str(doc_path / "LICENSE.md"))
# copy files from static-doc dir
copy_tree(str(cls.project_rootdir_path / "docs-static"), str(doc_path))
# generating API doc + nav from python docstrings
reference_path = doc_path / "reference"
cls._reset_dir(reference_path)
for path in sorted((cls.project_rootdir_path / "src").rglob("*.py")):
module_path = path.relative_to(cls.project_rootdir_path / "src").with_suffix("")
doc_path = path.relative_to(cls.project_rootdir_path / "src").with_suffix(".md")
full_doc_path = Path(reference_path, doc_path)
parts = list(module_path.parts)
if parts[-1] == "__init__":
parts = parts[:-1]
elif parts[-1] == "__main__":
continue
cls._reset_dir(os.path.dirname(full_doc_path))
with open(full_doc_path, "w+") as fd:
identifier = "src." + ".".join(parts)
print("::: " + identifier, file=fd)
cmdopts = [f"{sys.executable}", "-m", "mkdocs", "-v", "build", "--site-dir", str(site_path), "--clean"]
# 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)
if cls.enable_gen_pdf == True:
mkdocsCfg["plugins"].append(
{
"with-pdf": {
"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))
res = cls.run_cmd(cmdopts)
print(res.decode())
print(" !! done")

View File

@@ -1,74 +0,0 @@
# 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 abc import ABC, abstractmethod
import os
from pathlib import Path
import subprocess
if TYPE_CHECKING: # Only imports the below statements during type checking
from typing import Union
class helper_base(ABC):
project_rootdir_path: Union[Path, None] = None
pyproject: Union[dict, None] = None
current_dir: Union[Path, None] = None
@classmethod
def set_context(cls, project_rootdir_path: Path, pyproject: dict):
cls.project_rootdir_path = project_rootdir_path
cls.pyproject = pyproject
cls.current_dir = Path(__file__).parent.absolute()
@classmethod
def get_result_dir(cls):
return None
@staticmethod
def _reset_dir(dirpath: Path):
dirpath = Path(dirpath)
if not os.path.exists(dirpath):
os.makedirs(dirpath)
[f.unlink() for f in Path(dirpath).glob("*") if f.is_file()]
@classmethod
def reset_result_dir(cls):
result_dir = cls.get_result_dir()
if result_dir != None:
cls._reset_dir(result_dir)
@classmethod
@abstractmethod
def do_job(cls):
raise NotImplementedError()
@classmethod
def run_cmd_(cls, cmdarray):
process = subprocess.run(cmdarray, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, check=True)
return process.stdout
@classmethod
def run_cmd(cls, cmdarray):
p = subprocess.run(cmdarray, capture_output=True)
print(p.stdout)
print(p.stderr)
return p.stdout
class helper_withresults_base(helper_base):
helper_results_dir: Union[Path, None] = None
@classmethod
def get_result_dir(cls):
if cls.helper_results_dir == None:
cls.helper_results_dir = cls.__name__
return Path(__file__).parent.parent.absolute() / "helpers-results" / cls.helper_results_dir

View File

@@ -1,246 +0,0 @@
# 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 contextlib import redirect_stdout
from io import StringIO
import re
import json
from enum import Enum
from contextlib import suppress
import sys
import pandas
import csv
import copy
from pylint.lint import Run as pylint_Run
import pylint_json2html
from .helper_base import helper_withresults_base
class PyLintMetricNotFound(Warning):
pass
class quality_check(helper_withresults_base):
PylintMessageList = dict()
@classmethod
def GetPylintMessageList(cls):
Messagelist = dict()
regex = r"^:([a-zA-Z-]+) \(([^\)]+)\)"
for line in cls.run_cmd([sys.executable, "-m", "pylint", "--list-msgs"]).splitlines():
if res := re.search(regex, line.decode()):
Messagelist[res.group(1)] = res.group(2)
cls.PylintMessageList = Messagelist
@staticmethod
def TryExtractPYReportMetric(line: str, tag: str):
regex = f"^(?:\|{tag}\s*\|)(\d+)(?=\s*|)"
if res := re.search(regex, line):
return float(res.group(1))
raise PyLintMetricNotFound()
@classmethod
def do_job(cls):
print("checking code quality ...")
cls.GetPylintMessageList()
RES_all = dict()
with StringIO() as StdOutput:
JsonContent = ""
with redirect_stdout(StdOutput):
pylint_Run(
[
"--load-plugins=pylint.extensions.mccabe",
"--output-format=json,parseable",
"--disable=invalid-name",
"--ignore=_version.py",
"--reports=y",
"--score=yes",
"--max-line-length=140",
"src." + cls.pyproject["project"]["name"],
],
exit=False,
)
with open(cls.get_result_dir() / "report.json", "w+", encoding="utf-8") as Outfile:
# hacky way of exctracting json + having overall score...
class TScanState(Enum):
TEXT_REPORT = 1
JSON_REPORT = 2
OTHER_REPORT_START = 3
OTHER_REPORT_STATISTICS = 4
OTHER_REPORT_METRICS = 5
OTHER_REPORT_DUPLICATION = 6
OTHER_REPORT_MESSAGES_CAT = 7
OTHER_REPORT_MESSAGES = 8
OTHER_REPORT_END = 99
RES_all["Statistics"] = dict()
RES_all["RawMetrics"] = dict()
RES_all["RawMetricsPercent"] = dict()
RES_all["Duplication"] = dict()
RES_all["MessagesCat"] = dict()
RES_all["Messages"] = dict()
RES_all["GlobalScore"] = -999
RES_all["NbAnalysedStatments"] = -999
RES_all["NbAnalysedLines"] = -999
ScanState = TScanState.TEXT_REPORT
for line in StdOutput.getvalue().split("\n"):
print(line)
if ScanState == TScanState.TEXT_REPORT:
# ignoring this part, we need json
if line == "[":
JsonContent += line
ScanState = TScanState.JSON_REPORT
elif line == "[]":
JsonContent += line
ScanState = TScanState.OTHER_REPORT_START
elif ScanState == TScanState.JSON_REPORT:
JsonContent += line
if line == "]":
ScanState = TScanState.OTHER_REPORT_START
elif ScanState == TScanState.OTHER_REPORT_START:
if res := re.search(r"^(\d+)(?= statements analysed.)", line):
RES_all["NbAnalysedStatments"] = float(res.group(1))
if line == "Statistics by type":
ScanState = TScanState.OTHER_REPORT_STATISTICS
elif ScanState == TScanState.OTHER_REPORT_STATISTICS:
if res := re.search(r"^(\d+)(?= lines have been analyzed)", line):
RES_all["NbAnalysedLines"] = float(res.group(1))
elif line == "Raw metrics":
ScanState = TScanState.OTHER_REPORT_METRICS
else:
with suppress(PyLintMetricNotFound):
RES_all["Statistics"]["module"] = cls.TryExtractPYReportMetric(line, "module")
with suppress(PyLintMetricNotFound):
RES_all["Statistics"]["class"] = cls.TryExtractPYReportMetric(line, "class")
with suppress(PyLintMetricNotFound):
RES_all["Statistics"]["method"] = cls.TryExtractPYReportMetric(line, "method")
with suppress(PyLintMetricNotFound):
RES_all["Statistics"]["function"] = cls.TryExtractPYReportMetric(line, "function")
elif ScanState == TScanState.OTHER_REPORT_METRICS:
if line == "Duplication":
RES_all["RawMetricsPercent"]["code"] = RES_all["RawMetrics"]["code"] / RES_all["NbAnalysedLines"]
RES_all["RawMetricsPercent"]["docstring"] = RES_all["RawMetrics"]["docstring"] / RES_all["NbAnalysedLines"]
RES_all["RawMetricsPercent"]["comment"] = RES_all["RawMetrics"]["comment"] / RES_all["NbAnalysedLines"]
RES_all["RawMetricsPercent"]["empty"] = RES_all["RawMetrics"]["empty"] / RES_all["NbAnalysedLines"]
ScanState = TScanState.OTHER_REPORT_DUPLICATION
else:
with suppress(PyLintMetricNotFound):
RES_all["RawMetrics"]["code"] = cls.TryExtractPYReportMetric(line, "code")
with suppress(PyLintMetricNotFound):
RES_all["RawMetrics"]["docstring"] = cls.TryExtractPYReportMetric(line, "docstring")
with suppress(PyLintMetricNotFound):
RES_all["RawMetrics"]["comment"] = cls.TryExtractPYReportMetric(line, "comment")
with suppress(PyLintMetricNotFound):
RES_all["RawMetrics"]["empty"] = cls.TryExtractPYReportMetric(line, "empty")
elif ScanState == TScanState.OTHER_REPORT_DUPLICATION:
if line == "Messages by category":
ScanState = TScanState.OTHER_REPORT_MESSAGES_CAT
else:
with suppress(PyLintMetricNotFound):
RES_all["Duplication"]["NbDupLines"] = cls.TryExtractPYReportMetric(line, "nb duplicated lines")
with suppress(PyLintMetricNotFound):
RES_all["Duplication"]["PersentDuplicatedLines"] = cls.TryExtractPYReportMetric(
line, "percent duplicated lines"
)
elif ScanState == TScanState.OTHER_REPORT_MESSAGES_CAT:
if line == "Messages":
ScanState = TScanState.OTHER_REPORT_MESSAGES
else:
with suppress(PyLintMetricNotFound):
RES_all["MessagesCat"]["Convention"] = cls.TryExtractPYReportMetric(line, "convention")
with suppress(PyLintMetricNotFound):
RES_all["MessagesCat"]["Refactor"] = cls.TryExtractPYReportMetric(line, "refactor")
with suppress(PyLintMetricNotFound):
RES_all["MessagesCat"]["Warning"] = cls.TryExtractPYReportMetric(line, "warning")
with suppress(PyLintMetricNotFound):
RES_all["MessagesCat"]["Error"] = cls.TryExtractPYReportMetric(line, "error")
elif ScanState == TScanState.OTHER_REPORT_MESSAGES:
# approx match because the number of '-' depend on screen width..
if line.startswith("--------"):
ScanState = TScanState.OTHER_REPORT_END
else:
for PylintMessage in cls.PylintMessageList.keys():
with suppress(PyLintMetricNotFound):
RES_all["Messages"][PylintMessage] = cls.TryExtractPYReportMetric(line, PylintMessage)
elif ScanState == TScanState.OTHER_REPORT_END:
if res := re.search(r"(?<=Your code has been rated at )(\d+(?:\.\d+)?)/10", line):
RES_all["GlobalScore"] = float(res.group(1))
print(RES_all["GlobalScore"])
else:
raise RuntimeError("Invalid ScanState")
Outfile.write(JsonContent)
with open(cls.get_result_dir() / "metrics.json", "w") as json_file:
json.dump(RES_all, json_file)
# exporting all Data in one csv, unused atm because jenkins seems not able to select columns from csv an keep displaying all...
# => to export a working full csv we need to a 'flat' dict (no more nested dict)
RES_all_trim = copy.deepcopy(RES_all)
del RES_all_trim["Messages"]
flat_RES_all = pandas.json_normalize(RES_all_trim, sep="_").to_dict(orient="records")[0]
with open(cls.get_result_dir() / "metrics.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=flat_RES_all.keys())
writer.writeheader()
writer.writerow(flat_RES_all)
# splited csv exports for jenkins plots: RawMetricsPercent
RES_all_percent = RES_all["RawMetricsPercent"]
with open(cls.get_result_dir() / "metrics_rawpercent.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=RES_all_percent.keys())
writer.writeheader()
writer.writerow(RES_all_percent)
# splited csv exports for jenkins plots: Statistics + Duplication + NbAnalysedStatments + NbAnalysedLines
RES_all_stats = copy.deepcopy(RES_all["Statistics"])
RES_all_stats["NbDupLines"] = RES_all["Duplication"]["NbDupLines"]
RES_all_stats["PersentDuplicatedLines"] = RES_all["Duplication"]["PersentDuplicatedLines"]
RES_all_stats["NbAnalysedStatments"] = RES_all["NbAnalysedStatments"]
RES_all_stats["NbAnalysedLines"] = RES_all["NbAnalysedLines"]
with open(cls.get_result_dir() / "metrics_Statistics.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=RES_all_stats.keys())
writer.writeheader()
writer.writerow(RES_all_stats)
# splited csv exports for jenkins plots: Statistics + Duplication
RES_all_MessagesCat = RES_all["MessagesCat"]
with open(cls.get_result_dir() / "metrics_MessagesCat.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=RES_all_MessagesCat.keys())
writer.writeheader()
writer.writerow(RES_all_MessagesCat)
# splited csv exports for jenkins plots: GlobalScore
RES_GlobalScore = {"GlobalScore": RES_all["GlobalScore"]}
with open(cls.get_result_dir() / "metrics_GlobalScore.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=RES_GlobalScore.keys())
writer.writeheader()
writer.writerow(RES_GlobalScore)
# converting the report using pylint_json2html (/!\ internal API, but as their is no leading '_' ...)
with open(cls.get_result_dir() / "report.html", "w+", encoding="utf-8") as Outfile:
raw_data = json.loads(JsonContent)
report = pylint_json2html.Report(raw_data)
Outfile.write(report.render())
print("Done")

View File

@@ -1,61 +0,0 @@
# 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
from mypy import api
from .helper_base import helper_withresults_base
class types_check(helper_withresults_base):
JUnitReportName = "junit.xml"
@classmethod
def do_job(cls):
print("checking code typing ...")
result = api.run(
[ # project path
"-m",
"src." + str(cls.pyproject["project"]["name"]),
# analysis configuration
"--ignore-missing-imports",
"--strict-equality",
# 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",
str(cls.get_result_dir()),
"--junit-xml",
str(cls.get_result_dir()) + "/" + cls.JUnitReportName,
]
)
if result[0]:
print("\nType checking report:\n")
print(result[0]) # stdout
if result[1]:
print("\nError report:\n")
print(result[1]) # stderr
print("\nExit status:", result[2])
print("Done")

View File

@@ -1,81 +0,0 @@
# 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 datetime
import unittest
import xmlrunner
from junitparser import JUnitXml
from junit2htmlreport import parser as junit2html_parser
from .helper_base import helper_withresults_base
class unit_test(helper_withresults_base):
enable_coverage_check: bool = False
enable_xml_export: bool = True
enable_full_xml_export: bool = True
FullReportName: str = "full_report"
CoverageReportName: str = "test_coverage"
@classmethod
def do_job(cls):
if cls.enable_coverage_check == True:
import coverage
# preparing unittest framework
test_loader = unittest.TestLoader()
if cls.enable_coverage_check == True:
# we start coverage now because module files discovery is part of the coverage measurement
CoverageReportPath = Path(str(cls.get_result_dir()) + "_coverage")
cls._reset_dir(CoverageReportPath)
cov = coverage.Coverage(cover_pylib=False, branch=True, source_pkgs=["src." + cls.pyproject["project"]["name"]])
cov.start()
package_tests = test_loader.discover(
start_dir=str(cls.project_rootdir_path / "test"), top_level_dir=str(cls.project_rootdir_path / "test")
)
if cls.enable_xml_export:
testRunner = xmlrunner.XMLTestRunner(output=str(str(cls.get_result_dir())))
else:
testRunner = unittest.TextTestRunner()
# running the test
testRunner.run(package_tests)
print("Test Finished")
if cls.enable_coverage_check == True:
cov.stop()
cov.save()
cov.html_report(directory=str(CoverageReportPath))
cov.xml_report(outfile=(CoverageReportPath / f"{cls.CoverageReportName}.xml"))
# computing results (Only if xml available)
if cls.enable_full_xml_export == True:
print("Full reports generation...")
FullReportPath = Path(str(cls.get_result_dir()) + "_full")
cls._reset_dir(FullReportPath)
FullJUnitReport = JUnitXml()
for fname in [fname for fname in os.listdir(cls.get_result_dir()) if fname.endswith(".xml")]:
FullJUnitReport += JUnitXml.fromfile(str(cls.get_result_dir() / fname))
current_datetime = datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")
full_report_base_name = f'{cls.pyproject["project"]["name"]}-{cls.FullReportName}-{current_datetime}'
FullJUnitReport.write(str(FullReportPath / f"{full_report_base_name}.xml"))
report = junit2html_parser.Junit(FullReportPath / f"{full_report_base_name}.xml")
html = report.html()
with open(FullReportPath / f"{full_report_base_name}.html", "wb") as outfile:
outfile.write(html.encode("utf-8"))
print("Done")

View File

@@ -0,0 +1,5 @@
from chacha_cicd_helper.__main__ import fct_main
import sys
if __name__ == "__main__":
fct_main(sys.argv[1:])

View File

@@ -1,92 +1,121 @@
# 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
- navigation.path
- navigation.top
- navigation.section
- content.code.annotate
- navigation.expand
- 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:
path:
- src
options:
filters:
- '!^_[^_]'
inherited_members: false
show_if_no_docstring: true
show_signature_annotations: true
show_source: false
show_category_heading: true
group_by_category: true
show_root_full_path: false
merge_init_into_class: true
separate_signature: true
heading_level: 2
docstring_section_style: spacy
show_root_toc_entry: false
- 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\cl_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

@@ -15,7 +15,7 @@ version_scheme= "post-release"
[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"]
@@ -46,7 +46,21 @@ include-package-data = true
where = ["src"]
[tool.setuptools.package-data]
"pygitversionhelper.data" = ["*.*"]
"pysimpleini" = ["py.typed"]
# [[tool.mypy.overrides]]
# module = ""
# ignore_missing_imports = true
[tool.coverage.run]
cover_pylib = false
branch = true
data_file="helpers-results/cl_unit_test_raw_coverage/.coverage"
# debug = ["config","multiproc","process"]
parallel = true
concurrency = [
'thread'
]
[project.urls]
Homepage = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper/"
@@ -54,13 +68,13 @@ Documentation = "https://chacha.ddns.net/mkdocs-web/chacha/pygitversionhelper/
Tracker = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper/issues"
[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"]
test = ["chacha_cicd_helper"]
coverage-check = ["chacha_cicd_helper"]
complexity-check = ["chacha_cicd_helper"]
quality-check = ["chacha_cicd_helper"]
type-check = ["chacha_cicd_helper"]
doc-gen = ["chacha_cicd_helper"]
#[project.scripts]
#my-script = "my_package.module:function"
# [project.scripts]
# my-script = "my_package.module:function"

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,71 @@ 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
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
def _exec(cmd: str, root: str | os.PathLike | None = None, raw: bool = False) -> 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,126 +99,119 @@ 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 (str): 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:
the commit message
"""
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 +219,57 @@ 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 +281,49 @@ 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,33 +337,31 @@ 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
"""
if tag is None:
tag = cls.getLastTag(**kwargs)
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 +370,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 +405,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 +422,65 @@ 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 +516,113 @@ 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)
def getCurrentFormatedVersion(cls, **kwargs: Unpack[TKwargs]) -> str:
"""same as getCurrentVersion() with formated_output kwarg forced activated.
@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)
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 +633,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 +662,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 +690,33 @@ 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,35 +727,36 @@ 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:
formated version string
"""
VersionStd = cls._getVersionStd(**kwargs)
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

@@ -0,0 +1 @@
# PlaceHolder

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("/")