From 264c51de2ea2bd54ac2820400b0b3ed49d54fc72 Mon Sep 17 00:00:00 2001 From: cclecle Date: Sun, 19 Mar 2023 17:51:11 +0000 Subject: [PATCH 1/6] update CI/CD --- Jenkinsfile | 7 +++++-- pyproject.toml | 4 ---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7e4d9bb..1bd9045 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -394,7 +394,10 @@ pipeline { def CurrentDateTime=java.time.LocalDateTime.now() withCredentials([string( credentialsId: _MkDocsWebCredentials,variable: 'MKDOCSTOKEN' )]) { - sh(script: """#!/usr/bin/env python3 + sh(script: """#!/bin/sh - + |. ~/BUILD_ENV/bin/activate + |exec python - << '__EOWRAPPER__' + | |from simple_rest_client.api import API |from simple_rest_client.resource import Resource |import json @@ -478,7 +481,7 @@ pipeline { |response=requests.post("http://${_MkDocsWebURL}/API.php?REQ=pushDoc",data=reqData,files=files) |if response.status_code != 200: | raise RuntimeError(f"Wrong server response: {response.status_code}") - | + |__EOWRAPPER__ """.stripMargin()) } } diff --git a/pyproject.toml b/pyproject.toml index 5d00a65..fb3f01f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,10 +49,6 @@ where = ["src"] [tool.setuptools.package-data] "pygitversionhelper.data" = ["*.*"] -#[tool.setuptools_scm] -#write_to = "src/pygitversionhelper/_version.py" -#version_scheme = "python-simplified-semver" - [project.urls] Homepage = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper" Documentation = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper/wiki" -- 2.47.3 From 17f74d6675ccb29882f4b22da6ee8e1e12094ab5 Mon Sep 17 00:00:00 2001 From: cclecle Date: Sun, 19 Mar 2023 17:57:20 +0000 Subject: [PATCH 2/6] test gitversionhelper calls --- Jenkinsfile | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1bd9045..5bba7f5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -129,7 +129,7 @@ pipeline { sh(". ~/BUILD_ENV/bin/activate && pip install --upgrade setuptools build pip copier jinja2-slug toml \"setuptools-git-versioning<2\"") - + sh(". ~/BUILD_ENV/bin/activate && pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master") } } @@ -173,6 +173,23 @@ pipeline { echo("PY_PROJECT_VERSION: . . . . . . . . . $PY_PROJECT_VERSION") PY_PROJECT_VERSION_STRIPPED=ExtractBaseVersion(PY_PROJECT_VERSION) + sh(script: """#!/bin/sh - + |. ~/BUILD_ENV/bin/activate + |exec python - << '__EOWRAPPER__' + | + |from pygitversionhelper import gitversionhelper + | + |print(f"most recent repository tag: {gitversionhelper.tag.getLastTag()}") + |print(f"most recent repository tag: {gitversionhelper.tag.getLastTag(same_branch=True)}") + |print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag()}") + |print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag(same_branch=True)}") + |print(f"most recent repository version: {gitversionhelper.tag.getLastVersion()}") + |print(f"most recent repository version: {gitversionhelper.tag.getLastVersion(formated_output=True)}") + |print(f"most recent repository version: {gitversionhelper.tag.getCurrentVersion()}") + | + |__EOWRAPPER__ + """.stripMargin()) + // specific handling to test the template itself // => little hacky... creating a new git repo with a commit/tag corresponding to HEAD of the official one if(_PROJECT_NAME=="pyChaChaDummyProject") //specific case to test the template itself -- 2.47.3 From e9e25793d8fb18617219e0fba07ebe32452efdeb Mon Sep 17 00:00:00 2001 From: cclecle Date: Sun, 19 Mar 2023 17:57:28 +0000 Subject: [PATCH 3/6] fix doc bullets --- docs-static/usage.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs-static/usage.md b/docs-static/usage.md index 18b1cdb..bd8ed28 100644 --- a/docs-static/usage.md +++ b/docs-static/usage.md @@ -82,18 +82,18 @@ Get the last found version in the repository [return formated string]: print(f"most recent repository version: {gitversionhelper.tag.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 +* 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"most recent repository version: {gitversionhelper.tag.getCurrentVersion()}") 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 +* 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: @@ -108,6 +108,6 @@ kwargs available to those function: ## Limitations There is unfortunately some technical limitation : -- MultiThreading and async behavior is not tested. -- Multiple tag on the same commit is not supported. -- Branch filter when searching for a version is only tested with -no-ff strategy \ No newline at end of file +* MultiThreading and async behavior is not tested. +* Multiple tag on the same commit is not supported. +* Branch filter when searching for a version is only tested with -no-ff strategy \ No newline at end of file -- 2.47.3 From c5962d533bc6eea49f3504a412ab2f4bb2389ee8 Mon Sep 17 00:00:00 2001 From: cclecle Date: Sun, 19 Mar 2023 17:59:27 +0000 Subject: [PATCH 4/6] fix tag -> version api --- Jenkinsfile | 6 +++--- docs-static/usage.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5bba7f5..d837710 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -183,9 +183,9 @@ pipeline { |print(f"most recent repository tag: {gitversionhelper.tag.getLastTag(same_branch=True)}") |print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag()}") |print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag(same_branch=True)}") - |print(f"most recent repository version: {gitversionhelper.tag.getLastVersion()}") - |print(f"most recent repository version: {gitversionhelper.tag.getLastVersion(formated_output=True)}") - |print(f"most recent repository version: {gitversionhelper.tag.getCurrentVersion()}") + |print(f"most recent repository version: {gitversionhelper.version.getLastVersion()}") + |print(f"most recent repository version: {gitversionhelper.version.getLastVersion(formated_output=True)}") + |print(f"most recent repository version: {gitversionhelper.version.getCurrentVersion()}") | |__EOWRAPPER__ """.stripMargin()) diff --git a/docs-static/usage.md b/docs-static/usage.md index bd8ed28..d86bdd7 100644 --- a/docs-static/usage.md +++ b/docs-static/usage.md @@ -75,11 +75,11 @@ Get the distance from HEAD to last tag [only on same branch]: Get the last found version in the repository [return MetaVersion object]: - print(f"most recent repository version: {gitversionhelper.tag.getLastVersion()}") + 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.tag.getLastVersion(formated_output=True)}") + 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"] @@ -88,7 +88,7 @@ Others kwargs available to this function: Get the current version of the repository, automatically bump it if the last one is not tagged [returns MetaVersion object]: - print(f"most recent repository version: {gitversionhelper.tag.getCurrentVersion()}") + print(f"most recent repository version: {gitversionhelper.version.getCurrentVersion()}") kwargs available to this function: * All same args as getLastVersion() -- 2.47.3 From 3c0e5bebc29ea61a4047ca8c88eb297abeacc960 Mon Sep 17 00:00:00 2001 From: cclecle Date: Sun, 19 Mar 2023 18:02:02 +0000 Subject: [PATCH 5/6] update doc --- docs-static/usage.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs-static/usage.md b/docs-static/usage.md index d86bdd7..9158789 100644 --- a/docs-static/usage.md +++ b/docs-static/usage.md @@ -88,8 +88,12 @@ Others kwargs available to this function: Get the current version of the repository, automatically bump it if the last one is not tagged [returns MetaVersion object]: - print(f"most recent repository version: {gitversionhelper.version.getCurrentVersion()}") - + print(f"current repository version: {gitversionhelper.version.getCurrentVersion()}") + +Or with formated output: + + print(f"current repository version: {gitversionhelper.version.getCurrentVersion(formated_output=True)}") + 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 -- 2.47.3 From f5c97757b6cfd4dbfe8caf5411d0e19488c87ead Mon Sep 17 00:00:00 2001 From: cclecle Date: Sun, 19 Mar 2023 18:22:26 +0000 Subject: [PATCH 6/6] make setuptools-git-versioning use pygitversionhelper + add getCurrentFormatedVersion() --- Jenkinsfile | 49 +++++++++++----------- pyproject.toml | 5 +-- src/pygitversionhelper/gitversionhelper.py | 8 ++++ 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d837710..4cb7379 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -126,11 +126,14 @@ pipeline { sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python BUILD_ENV") sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python TEST_ENV") + sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python TOOLS_ENV") sh(". ~/BUILD_ENV/bin/activate && pip install --upgrade setuptools build pip copier jinja2-slug toml \"setuptools-git-versioning<2\"") - sh(". ~/BUILD_ENV/bin/activate && pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master") + sh(". ~/TOOLS_ENV/bin/activate && pip install simple_rest_client requests") + sh(". ~/TOOLS_ENV/bin/activate && pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master") + } } @@ -156,25 +159,9 @@ pipeline { // using git to get the latest tag on this branch def latestTag = sh(returnStdout: true, script: "git tag --sort=-creatordate | head -n 1").trim() echo("latestTag:. . . . . . . . . . . . $latestTag ") - - // using setuptools_git_versioning to get the generated version number based on Git tags and logs - // TODO: read dev_template from toml - PY_PROJECT_VERSION = sh(script: """#!/bin/sh - - |. ~/BUILD_ENV/bin/activate - |exec python - << '__EOWRAPPER__' - | - |from setuptools_git_versioning import version_from_git - | - |print(str(version_from_git(tag_filter="^\\d+\\.\\d+\\.\\d+\$",dev_template = "{tag}.post{ccount}")),end ="") - | - |__EOWRAPPER__ - """.stripMargin(), - returnStdout: true) - echo("PY_PROJECT_VERSION: . . . . . . . . . $PY_PROJECT_VERSION") - PY_PROJECT_VERSION_STRIPPED=ExtractBaseVersion(PY_PROJECT_VERSION) - + sh(script: """#!/bin/sh - - |. ~/BUILD_ENV/bin/activate + |. ~/TOOLS_ENV/bin/activate |exec python - << '__EOWRAPPER__' | |from pygitversionhelper import gitversionhelper @@ -183,13 +170,28 @@ pipeline { |print(f"most recent repository tag: {gitversionhelper.tag.getLastTag(same_branch=True)}") |print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag()}") |print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag(same_branch=True)}") - |print(f"most recent repository version: {gitversionhelper.version.getLastVersion()}") |print(f"most recent repository version: {gitversionhelper.version.getLastVersion(formated_output=True)}") - |print(f"most recent repository version: {gitversionhelper.version.getCurrentVersion()}") + |print(f"current repository version: {gitversionhelper.version.getCurrentVersion(formated_output=True)}") | |__EOWRAPPER__ """.stripMargin()) - + + // using setuptools_git_versioning to get the generated version number based on Git tags and logs + // TODO: read dev_template from toml + PY_PROJECT_VERSION = sh(script: """#!/bin/sh - + |. ~/BUILD_ENV/bin/activate + |exec python - << '__EOWRAPPER__' + | + |from pygitversionhelper import gitversionhelper + | + |print(gitversionhelper.version.getCurrentVersion(formated_output=True,version_std="PEP440",bump_type="dev",bump_dev_strategy="post"),end ="") + | + |__EOWRAPPER__ + """.stripMargin(), + returnStdout: true) + echo("PY_PROJECT_VERSION: . . . . . . . . . $PY_PROJECT_VERSION") + PY_PROJECT_VERSION_STRIPPED=ExtractBaseVersion(PY_PROJECT_VERSION) + // specific handling to test the template itself // => little hacky... creating a new git repo with a commit/tag corresponding to HEAD of the official one if(_PROJECT_NAME=="pyChaChaDummyProject") //specific case to test the template itself @@ -405,14 +407,13 @@ pipeline { def GITEA_LOGIN_TOKEN=credentials("GiteaCHACHAPush") } steps { - sh("python3 -m pip install simple_rest_client requests") dir("gitrepo") { script { def CurrentDateTime=java.time.LocalDateTime.now() withCredentials([string( credentialsId: _MkDocsWebCredentials,variable: 'MKDOCSTOKEN' )]) { sh(script: """#!/bin/sh - - |. ~/BUILD_ENV/bin/activate + |. ~/TOOLS_ENV/bin/activate |exec python - << '__EOWRAPPER__' | |from simple_rest_client.api import API diff --git a/pyproject.toml b/pyproject.toml index fb3f01f..8181d3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,13 +7,12 @@ # work. If not, see . [build-system] -requires = ["setuptools>=63", "wheel", "setuptools-git-versioning<2"] +requires = ["setuptools>=63", "wheel", "setuptools-git-versioning<2","pygitversionhelper"] build-backend = "setuptools.build_meta" [tool.setuptools-git-versioning] enabled = true -dev_template = "{tag}.post{ccount}" -tag_filter = "^\\d+\\.\\d+\\.\\d+$" +version_callback = "pygitversionhelper.gitversionhelper.version.getCurrentFormatedVersion" [project] name = "pygitversionhelper" diff --git a/src/pygitversionhelper/gitversionhelper.py b/src/pygitversionhelper/gitversionhelper.py index 9b0dfab..6e8d48f 100644 --- a/src/pygitversionhelper/gitversionhelper.py +++ b/src/pygitversionhelper/gitversionhelper.py @@ -494,6 +494,14 @@ class gitversionhelper: # pylint: disable=too-few-public-methods return _v.doFormatVersion(**kwargs) return _v + @classmethod + def getCurrentFormatedVersion(cls,**kwargs) -> str : + """ + Same as getCurrentVersion() with formated_output kwarg activated + """ + kwargs["formated_output"]=True + return cls.getCurrentVersion(kwargs) + @classmethod def _parseTag(cls,tag,**kwargs): # pylint: disable=R0914, R0912, R0915 """get the last version from tags -- 2.47.3