Compare commits
52 Commits
1.0.12.pos
...
1.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| ca7a69ae76 | |||
|
|
114aa31115 | ||
|
|
facd431c59 | ||
| d4b90b1f91 | |||
|
|
a07bcc37c4 | ||
| ac70d4dde4 | |||
|
|
0d1e981b6b | ||
| 6e1c60ee53 | |||
|
|
b01779dd06 | ||
|
|
f7ec5d98a7 | ||
|
|
82d4b1bd70 | ||
|
|
880fa29bbd | ||
|
|
7347106694 | ||
| dd6f24a82e | |||
|
|
e1c1e643c3 | ||
|
|
a5f39d6cb2 | ||
|
|
c6ed7ef0a1 | ||
|
|
0ef5a8f463 | ||
|
|
e06a3b00ae | ||
|
|
d3bf6ddaa6 | ||
|
|
a419af2ade | ||
| 78d7fbe39d | |||
|
|
5f9d513c59 | ||
|
|
5087cf9614 | ||
| 3f5ee5f117 | |||
| 2d16b0e264 | |||
| 088dbf8a90 | |||
| bd49b23b59 | |||
| f5d61d8d04 | |||
| d21c839f07 | |||
| 6542c80e8f | |||
| 4272a55dde | |||
| 382e39e684 | |||
| 34c07e0d9f | |||
| 2c9886b251 | |||
| 782562eef8 | |||
| 82c32ff58c | |||
| 794e54c88b | |||
| 078f5624b2 | |||
| 44c10b88a5 | |||
| a4b7b27a65 | |||
| 77e2be2714 | |||
| f422b9ff7d | |||
| 660270d49b | |||
| 9f442a7b8e | |||
| 8fb9ba8406 | |||
| 38abaa58c5 | |||
| 35d75ea019 | |||
| 0b8651a30a | |||
| c5b3055bfe | |||
| 92a1d1a30f | |||
| f2c0bf1ddd |
45
Jenkinsfile
vendored
45
Jenkinsfile
vendored
@@ -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
|
||||
@@ -148,6 +148,7 @@ pipeline {
|
||||
PY_PROJECT_NAME = "__NOTSET__"
|
||||
PY_PROJECT_VERSION = "__NOTSET__"
|
||||
PY_PROJECT_VERSION_STRIPPED = "__NOTSET__"
|
||||
CHANGELOG = "__NOTSET__"
|
||||
}
|
||||
|
||||
stages {
|
||||
@@ -184,16 +185,14 @@ pipeline {
|
||||
|
||||
sh(". ~/BUILD_ENV/bin/activate && pip install --upgrade setuptools build pip copier jinja2-slug toml")
|
||||
|
||||
sh(". ~/TOOLS_ENV/bin/activate && pip install simple_rest_client requests twine")
|
||||
sh(". ~/TOOLS_ENV/bin/activate && pip install simple_rest_client requests twine packaging")
|
||||
|
||||
script {
|
||||
if(_PROJECT_NAME!="pygitversionhelper") {
|
||||
sh(". ~/TOOLS_ENV/bin/activate && pip install pygitversionhelper")
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO: need to install pygitversionhelper deps from a better way...
|
||||
sh(". ~/TOOLS_ENV/bin/activate && pip install packaging")
|
||||
if(_PROJECT_NAME!="pychangelogfactory") {
|
||||
sh(". ~/TOOLS_ENV/bin/activate && pip install pychangelogfactory")
|
||||
}
|
||||
}
|
||||
sh("git config --global user.email $_MaintainerEmail")
|
||||
@@ -217,6 +216,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()) {
|
||||
@@ -573,6 +598,7 @@ pipeline {
|
||||
|from simple_rest_client.api import API
|
||||
|from simple_rest_client.resource import Resource
|
||||
|
|
||||
|
|
||||
|try:
|
||||
| from pygitversionhelper import gitversionhelper
|
||||
|except ImportError:
|
||||
@@ -619,6 +645,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,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="2"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:pychangelogfactory/helpers}"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc}/helpers"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--complexity-check"/>
|
||||
<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
|
||||
<mapEntry key="PATH" value="C:\Program Files\GTK3-Runtime Win64\bin"/>
|
||||
</mapAttribute>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:pychangelogfactory/helpers}"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc}/helpers"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--doc-gen --doc-gen-pdf"/>
|
||||
<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="2"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:pychangelogfactory/helpers}"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc}/helpers"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--type-check --quality-check"/>
|
||||
<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="2"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:pychangelogfactory/helpers}"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc}/helpers"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value=""/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--unit-test --coverage-check"/>
|
||||
<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
|
||||
|
||||
@@ -3,30 +3,32 @@
|
||||
## Installation
|
||||
|
||||
From pypi repository (prefered):
|
||||
|
||||
python -m pip install pygitversionhelper
|
||||
|
||||
```console
|
||||
/> python -m pip install pygitversionhelper
|
||||
```
|
||||
|
||||
From downloaded .whl file:
|
||||
```console
|
||||
/> python -m pip install pygitversionhelper-<VERSION>-py3-none-any.whl
|
||||
```
|
||||
|
||||
python -m pip install pygitversionhelper-<VERSION>-py3-none-any.whl
|
||||
|
||||
From master git repository:
|
||||
|
||||
python -m pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master
|
||||
|
||||
```console
|
||||
/> python -m pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Import in your project
|
||||
|
||||
Add this line on the top of your python script:
|
||||
|
||||
#from pygitversionhelper import gitversionhelper
|
||||
|
||||
```py
|
||||
from pygitversionhelper import gitversionhelper
|
||||
```
|
||||
[optionnal] If you need to catch exception from this module:
|
||||
|
||||
#from pygitversionhelper import gitversionhelperException
|
||||
|
||||
```py
|
||||
from pygitversionhelper import gitversionhelperException
|
||||
```
|
||||
## Basic API
|
||||
|
||||
All the API commands are static so it is not needed to create instantiate any object.
|
||||
@@ -34,93 +36,100 @@ All the API commands are static so it is not needed to create instantiate any ob
|
||||
They are all executed in the current active directory.
|
||||
|
||||
One easy way to change directory:
|
||||
|
||||
import os
|
||||
os.chdir("<YOUR DIRECTORY>")
|
||||
|
||||
### sublib: repository
|
||||
```py
|
||||
import os
|
||||
os.chdir("<YOUR DIRECTORY>")
|
||||
```
|
||||
### sub-lib: repository
|
||||
|
||||
To check if a repository is dirty:
|
||||
|
||||
if gitversionhelper.repository.isDirty():
|
||||
print("repository is dirty")
|
||||
|
||||
### sublib: tag
|
||||
```py
|
||||
if gitversionhelper.repository.isDirty():
|
||||
print("repository is dirty")
|
||||
```
|
||||
### sub-lib: tag
|
||||
|
||||
List all tags [default to taggerdate order]:
|
||||
|
||||
for tag in gitversionhelper.tag.getTags():
|
||||
print(f"found tag: {tag}")
|
||||
|
||||
```py
|
||||
for tag in gitversionhelper.tag.getTags():
|
||||
print(f"found tag: {tag}")
|
||||
```
|
||||
List all tags [using git refname order]:
|
||||
|
||||
for tag in gitversionhelper.tag.getTags("v:refname"):
|
||||
print(f"found tag: {tag}")
|
||||
|
||||
```py
|
||||
for tag in gitversionhelper.tag.getTags("v:refname"):
|
||||
print(f"found tag: {tag}")
|
||||
```
|
||||
Get the last tag:
|
||||
|
||||
print(f"most recent repository tag: {gitversionhelper.tag.getLastTag()}")
|
||||
|
||||
```py
|
||||
print(f"most recent repository tag: {gitversionhelper.tag.getLastTag()}")
|
||||
```
|
||||
Get the last tag [only on same branch]:
|
||||
|
||||
print(f"most recent repository tag: {gitversionhelper.tag.getLastTag(same_branch=True)}")
|
||||
|
||||
```py
|
||||
print(f"most recent repository tag: {gitversionhelper.tag.getLastTag(same_branch=True)}")
|
||||
```
|
||||
|
||||
Get the distance from HEAD to last tag:
|
||||
|
||||
print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag()}")
|
||||
|
||||
```py
|
||||
print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag()}")
|
||||
```
|
||||
Get the distance from HEAD to last tag [only on same branch]:
|
||||
|
||||
print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag(same_branch=True)}")
|
||||
|
||||
### sublib: version
|
||||
```py
|
||||
print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag(same_branch=True)}")
|
||||
```
|
||||
### sub-lib: version
|
||||
|
||||
Get the last found version in the repository [return MetaVersion object]:
|
||||
|
||||
print(f"most recent repository version: {gitversionhelper.version.getLastVersion()}")
|
||||
|
||||
```py
|
||||
print(f"most recent repository version: {gitversionhelper.version.getLastVersion()}")
|
||||
```
|
||||
Get the last found version in the repository [return formated string]:
|
||||
|
||||
print(f"most recent repository version: {gitversionhelper.version.getLastVersion(formated_output=True)}")
|
||||
|
||||
```py
|
||||
print(f"most recent repository version: {gitversionhelper.version.getLastVersion(formated_output=True)}")
|
||||
```
|
||||
Others kwargs available to this function:
|
||||
|
||||
* version_std: string to force a version standard for rendering ["PEP440" or "SemVer"]
|
||||
* same_branch: boolean to force searching on same branch
|
||||
* ignore\_unknown\_tags: boolean to allow unknown tag to be ignored
|
||||
|
||||
Get the current version of the repository, automatically bump it if the last one is not tagged [returns MetaVersion object]:
|
||||
|
||||
print(f"current repository version: {gitversionhelper.version.getCurrentVersion()}")
|
||||
|
||||
Get the current version of the repository, automatically bump it if the last commit is not tagged [returns MetaVersion object]:
|
||||
```py
|
||||
print(f"current repository version: {gitversionhelper.version.getCurrentVersion()}")
|
||||
```
|
||||
Or with formated output:
|
||||
|
||||
print(f"current repository version: {gitversionhelper.version.getCurrentVersion(formated_output=True)}")
|
||||
|
||||
```py
|
||||
print(f"current repository version: {gitversionhelper.version.getCurrentVersion(formated_output=True)}")
|
||||
```
|
||||
Typical usage in CI/CD env:
|
||||
|
||||
bumped_version = gitversionhelper.version.getCurrentVersion( formated_output=True, \
|
||||
version_std="PEP440", \
|
||||
bump_type="dev", \
|
||||
bump_dev_strategy="post")
|
||||
print(f"current repository version: {bumped_version}")
|
||||
|
||||
```py
|
||||
bumped_version = gitversionhelper.version.getCurrentVersion( formated_output=True, \
|
||||
version_std="PEP440", \
|
||||
bump_type="dev", \
|
||||
bump_dev_strategy="post")
|
||||
print(f"current repository version: {bumped_version}")
|
||||
```
|
||||
kwargs available to this function:
|
||||
|
||||
* All same args as getLastVersion()
|
||||
* bump_type: if version need to be pump, allow to configure next release update type: __major, minor, patch, dev__
|
||||
* bump\_dev\_strategy: if bump\_type is dev, allow to choose dev update strategy: __post, pre-patch, pre-minor, pre-major__
|
||||
|
||||
|
||||
A version object can also be manually formated:
|
||||
```py
|
||||
_version = gitversionhelper.tag.getCurrentVersion()
|
||||
```
|
||||
Then;
|
||||
```py
|
||||
_version.doFormatVersion()
|
||||
```
|
||||
or;
|
||||
```py
|
||||
gitversionhelper.version.doFormatVersion(_version)
|
||||
```
|
||||
kwargs available to this function:
|
||||
|
||||
_version = gitversionhelper.tag.getCurrentVersion()
|
||||
_version.doFormatVersion()
|
||||
#or
|
||||
gitversionhelper.version.doFormatVersion(_version)
|
||||
|
||||
kwargs available to those function:
|
||||
- output_format: string to choose a rendering format ["Auto","PEP440" or "SemVer"]
|
||||
- output_format: string to choose a rendering format ["Auto","PEP440" or "SemVer"]
|
||||
|
||||
## Limitations
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ if __package__ == "helpers":
|
||||
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)
|
||||
@@ -30,7 +29,6 @@ else:
|
||||
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)
|
||||
@@ -59,8 +57,6 @@ if __name__ == "__main__":
|
||||
"-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()
|
||||
@@ -76,7 +72,6 @@ if __name__ == "__main__":
|
||||
# args.coveragecheck = True
|
||||
# args.docgen = True
|
||||
# args.docgenpdf = True
|
||||
# args.changeloggen = True
|
||||
# args.complexitycheck = True
|
||||
|
||||
helpers = []
|
||||
@@ -104,9 +99,6 @@ if __name__ == "__main__":
|
||||
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)
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -50,6 +50,7 @@ class doc_gen(helper_withresults_base):
|
||||
reference_path = doc_path / "reference"
|
||||
cls._reset_dir(reference_path)
|
||||
|
||||
# create one .md per python module
|
||||
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")
|
||||
@@ -57,14 +58,12 @@ class doc_gen(helper_withresults_base):
|
||||
|
||||
parts = list(module_path.parts)
|
||||
|
||||
if parts[-1] == "__init__":
|
||||
parts = parts[:-1]
|
||||
elif parts[-1] == "__main__":
|
||||
if parts[-1] in ("__init__", "__main__"):
|
||||
continue
|
||||
|
||||
cls._reset_dir(os.path.dirname(full_doc_path))
|
||||
cls._create_dir(full_doc_path.parent.resolve())
|
||||
with open(full_doc_path, "w+") as fd:
|
||||
identifier = "src." + ".".join(parts)
|
||||
identifier = ".".join(parts)
|
||||
print("::: " + identifier, file=fd)
|
||||
|
||||
cmdopts = [f"{sys.executable}", "-m", "mkdocs", "-v", "build", "--site-dir", str(site_path), "--clean"]
|
||||
@@ -93,6 +92,7 @@ class doc_gen(helper_withresults_base):
|
||||
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))
|
||||
|
||||
print(" !! start doc generation")
|
||||
res = cls.run_cmd(cmdopts)
|
||||
print(res.decode())
|
||||
print(" !! done")
|
||||
|
||||
@@ -11,6 +11,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
@@ -34,11 +35,17 @@ class helper_base(ABC):
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _reset_dir(dirpath: Path):
|
||||
def _create_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()]
|
||||
|
||||
@staticmethod
|
||||
def _reset_dir(dirpath: Path):
|
||||
dirpath = Path(dirpath)
|
||||
if os.path.exists(dirpath):
|
||||
shutil.rmtree(dirpath)
|
||||
os.makedirs(dirpath)
|
||||
|
||||
@classmethod
|
||||
def reset_result_dir(cls):
|
||||
|
||||
@@ -63,7 +63,7 @@ class quality_check(helper_withresults_base):
|
||||
[
|
||||
"--load-plugins=pylint.extensions.mccabe",
|
||||
"--output-format=json,parseable",
|
||||
"--disable=invalid-name",
|
||||
"--disable=invalid-name,too-few-public-methods,too-many-arguments", # ignore
|
||||
"--ignore=_version.py",
|
||||
"--reports=y",
|
||||
"--score=yes",
|
||||
|
||||
@@ -31,6 +31,7 @@ class types_check(helper_withresults_base):
|
||||
"--explicit-package-bases",
|
||||
# "--strict-equality",
|
||||
# "--check-untyped-defs",
|
||||
"--enable-incomplete-feature=Unpack",
|
||||
# reports generation
|
||||
"--cobertura-xml-report",
|
||||
str(cls.get_result_dir()),
|
||||
|
||||
27
mkdocs.yml
27
mkdocs.yml
@@ -1,11 +1,11 @@
|
||||
docs_dir: docs
|
||||
site_name: pygitversionhelper
|
||||
site_url: 'https://chacha.ddns.net/mkdocs-web/chacha/pygitversionhelper/latest/'
|
||||
site_description: 'A simple simple git version helper in python.'
|
||||
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'
|
||||
repo_url: https://chacha.ddns.net/gitea/chacha/pygitversionhelper
|
||||
use_directory_urls: false
|
||||
copyright: 'CC BY-NC-SA 4.0'
|
||||
copyright: CC BY-NC-SA 4.0
|
||||
theme:
|
||||
name: material
|
||||
features:
|
||||
@@ -14,11 +14,11 @@ theme:
|
||||
- navigation.tabs
|
||||
- navigation.tabs.sticky
|
||||
- navigation.footer
|
||||
- toc.integrate
|
||||
- navigation.path
|
||||
- navigation.top
|
||||
- navigation.section
|
||||
- content.code.annotate
|
||||
- navigation.prune
|
||||
- navigation.expand
|
||||
- toc.follow
|
||||
palette:
|
||||
- media: '(prefers-color-scheme: dark)'
|
||||
@@ -44,19 +44,30 @@ plugins:
|
||||
default_handler: python
|
||||
handlers:
|
||||
python:
|
||||
path:
|
||||
- src
|
||||
options:
|
||||
filters:
|
||||
- '!^_[^_]'
|
||||
inherited_members: true
|
||||
inherited_members: false
|
||||
show_if_no_docstring: true
|
||||
show_signature_annotations: true
|
||||
show_source: false
|
||||
show_category_heading: true
|
||||
group_by_category: true
|
||||
docstring_section_style: spacy
|
||||
show_root_full_path: false
|
||||
merge_init_into_class: true
|
||||
separate_signature: true
|
||||
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\doc_gen\site\pdf\manual.pdf
|
||||
markdown_extensions:
|
||||
- def_list
|
||||
- tables
|
||||
|
||||
@@ -61,6 +61,6 @@ 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-pymdownx-material-extras", "mkdocs-localsearch>=0.9.0", "mkdocstrings[python]>=0.19", "mkdocs-with-pdf>=0.9.3","pyyaml>=6.0","pymdown-extensions>=9","mkdocs-markdownextradata-plugin","mkdocs-mermaid2-plugin"]
|
||||
|
||||
#[project.scripts]
|
||||
#my-script = "my_package.module:function"
|
||||
# [project.scripts]
|
||||
# my-script = "my_package.module:function"
|
||||
|
||||
|
||||
7
src/pygitversionhelper/data/__init__.py
Normal file
7
src/pygitversionhelper/data/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# pygitversionhelper (c) by chacha
|
||||
#
|
||||
# pygitversionhelper is licensed under a
|
||||
# Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Unported License.
|
||||
#
|
||||
# You should have received a copy of the license along with this
|
||||
# work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
|
||||
@@ -5,17 +5,16 @@
|
||||
#
|
||||
# You should have received a copy of the license along with this
|
||||
# work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
|
||||
|
||||
"""
|
||||
This project try to help doing handy operations with git when
|
||||
This project try to help doing handy operations with git when
|
||||
dealing with project versioning and tags on python project -
|
||||
at leat for project using PEP440 or SemVer standards.
|
||||
|
||||
One requirement is to keep it compact and to not cover too much fancy features.
|
||||
This is the reason why it is one single file with nested classes.
|
||||
|
||||
=> Design is on-purpose poorly expandable to keep the scope light.
|
||||
|
||||
This library is maid for repository using tag as version.
|
||||
This library is made for repository that uses tags as version.
|
||||
Support for non-version tags is optional and not well tested.
|
||||
|
||||
This module is the main project file, containing all the code.
|
||||
@@ -23,34 +22,69 @@ This module is the main project file, containing all the code.
|
||||
Read the read me for more information.
|
||||
Check the unittest s for usage samples.
|
||||
|
||||
Note: _Other Parameters_ are **kwargs
|
||||
///Note
|
||||
_Other Parameters_ are **kwargs
|
||||
///
|
||||
|
||||
Attributes:
|
||||
TKwargs: Kwargs type definition for type hints
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, cast, TypedDict, Literal
|
||||
import os
|
||||
import subprocess
|
||||
import re
|
||||
from copy import copy
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from packaging.version import VERSION_PATTERN as packaging_VERSION_PATTERN
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import List, Optional, Any, Dict
|
||||
from typing_extensions import Unpack
|
||||
|
||||
def _exec(cmd: str, root: str | os.PathLike | None = None, raw: bool = False) -> list[str]:
|
||||
"""
|
||||
helper function to handle system cmd execution
|
||||
TKwargs = TypedDict(
|
||||
"TKwargs",
|
||||
{
|
||||
"version_std": Optional[str],
|
||||
"same_branch": Optional[bool],
|
||||
"formated_output": Optional[bool],
|
||||
"bump_type": Optional[str],
|
||||
"bump_dev_strategy": Optional[str],
|
||||
"merged_output": Optional[bool],
|
||||
"ignore_unknown_tags": Optional[bool],
|
||||
"output_format": Optional[str],
|
||||
"ignore_merged": Optional[bool],
|
||||
},
|
||||
total=False,
|
||||
)
|
||||
|
||||
|
||||
def _exec(cmd: str, root: Optional[str | os.PathLike[str]] = None, raw: bool = False) -> str | List[str]:
|
||||
"""helper function to handle system cmd execution
|
||||
Args:
|
||||
cmd: command line to be executed
|
||||
root: root directory where the command need to be executed
|
||||
raw: return bytes if True, str if False or None
|
||||
Returns:
|
||||
a list of command's return lines
|
||||
a list of command's return lines or the raw output
|
||||
|
||||
"""
|
||||
_root: Path
|
||||
if isinstance(root, str):
|
||||
_root = Path(root)
|
||||
elif isinstance(root, os.PathLike):
|
||||
_root = Path(root)
|
||||
else:
|
||||
_root = Path(os.getcwd())
|
||||
|
||||
p = subprocess.run(
|
||||
cmd,
|
||||
text=True,
|
||||
cwd=root,
|
||||
cwd=_root,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
timeout=2,
|
||||
@@ -63,115 +97,99 @@ def _exec(cmd: str, root: str | os.PathLike | None = None, raw: bool = False) ->
|
||||
if int(p.returncode) < 0:
|
||||
raise gitversionhelper.unknownGITError(p.stderr)
|
||||
|
||||
if raw:
|
||||
if raw is True:
|
||||
return p.stdout
|
||||
lines = p.stdout.splitlines()
|
||||
return [line.rstrip() for line in lines if line.rstrip()]
|
||||
|
||||
|
||||
class gitversionhelperException(Exception):
|
||||
"""
|
||||
general Module Exception
|
||||
"""
|
||||
"""general Module Exception"""
|
||||
|
||||
|
||||
class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
"""
|
||||
main gitversionhelper class
|
||||
"""
|
||||
"""main gitversionhelper class"""
|
||||
|
||||
class wrongArguments(gitversionhelperException):
|
||||
"""
|
||||
wrong argument generic exception
|
||||
"""
|
||||
"""wrong argument generic exception"""
|
||||
|
||||
class unknownGITError(gitversionhelperException):
|
||||
"""
|
||||
unknown git error generic exception
|
||||
"""
|
||||
"""unknown git error generic exception"""
|
||||
|
||||
class unknownGITFatalError(unknownGITError):
|
||||
"""
|
||||
unknown fatal git error generic exception
|
||||
"""
|
||||
"""unknown fatal git error generic exception"""
|
||||
|
||||
class repository:
|
||||
"""
|
||||
class containing methods focusing on repository
|
||||
"""
|
||||
"""class containing methods focusing on repository"""
|
||||
|
||||
class repositoryException(gitversionhelperException):
|
||||
"""
|
||||
generic repository exeption
|
||||
"""
|
||||
"""generic repository exeption"""
|
||||
|
||||
class notAGitRepository(repositoryException):
|
||||
"""
|
||||
not a git repository exception
|
||||
"""
|
||||
"""not-a-git-repository repository exception"""
|
||||
|
||||
class repositoryDirty(repositoryException):
|
||||
"""
|
||||
dirty repository exception
|
||||
"""
|
||||
"""dirty-repository repository exception"""
|
||||
|
||||
@classmethod
|
||||
def isDirty(cls) -> bool:
|
||||
"""
|
||||
check if the repository is in dirty state
|
||||
"""check if the repository is in dirty state
|
||||
Returns:
|
||||
True if it is dirty
|
||||
"""
|
||||
return bool(_exec("git status --short"))
|
||||
|
||||
class commit:
|
||||
"""
|
||||
class containing methods focusing on commits
|
||||
"""
|
||||
|
||||
__OptDict = {"same_branch": "same_branch", "merged_output": "merged_output"}
|
||||
"""class containing methods focusing on commits"""
|
||||
|
||||
class commitException(gitversionhelperException):
|
||||
"""
|
||||
generic commit exception
|
||||
"""
|
||||
"""generic commit exception"""
|
||||
|
||||
class commitNotFound(commitException):
|
||||
"""
|
||||
tag not found exception
|
||||
"""
|
||||
"""tag not found exception"""
|
||||
|
||||
@classmethod
|
||||
def getMessagesSinceTag(cls, tag: str, **kwargs) -> str:
|
||||
"""
|
||||
retrieve a commits message history from repository
|
||||
from Latest commit to the given tag
|
||||
def getMessagesSinceTag(cls, tag: str, **kwargs: Unpack[TKwargs]) -> str | List[str]:
|
||||
"""Retrieve a commits message history from repository.
|
||||
|
||||
Start from Latest found commit until the given tag.
|
||||
Args:
|
||||
tag: tag of the commit where search will stop
|
||||
Keyword Arguments:
|
||||
merged_output: output one single merged string
|
||||
same_branch(bool): force searching only in the same branch
|
||||
kwargs/merged_output (bool): Output one single merged string
|
||||
kwargs/same_branch (bool): Force searching only in the same branch
|
||||
kwargs/ignore_merged (bool): ignore merged commits
|
||||
Returns:
|
||||
the commit message
|
||||
"""
|
||||
current_commit_id = cls.getLast(**kwargs)
|
||||
tag_commit_id = cls.getFromTag(tag)
|
||||
|
||||
if (cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True):
|
||||
commits = _exec(f"git rev-list --first-parent --ancestry-path {tag_commit_id}..{current_commit_id}")
|
||||
str_cmd: str
|
||||
if ("same_branch" in kwargs) and (kwargs["same_branch"] is True):
|
||||
str_cmd = f"git rev-list --first-parent {tag_commit_id}..{current_commit_id}" # ok
|
||||
else:
|
||||
commits = _exec(f"git rev-list --ancestry-path {tag_commit_id}..{current_commit_id}")
|
||||
str_cmd = f"git rev-list {tag_commit_id}..{current_commit_id}" # ok
|
||||
|
||||
if ("ignore_merged" in kwargs) and (kwargs["ignore_merged"] is True):
|
||||
str_cmd = str_cmd + " --no-merges" # ok
|
||||
|
||||
try:
|
||||
commits = _exec(str_cmd)
|
||||
except gitversionhelper.unknownGITFatalError as _e:
|
||||
raise cls.commitNotFound("no commit found in commit history") from _e
|
||||
|
||||
result = []
|
||||
for commit in commits:
|
||||
result.append(cls.getMessage(commit))
|
||||
|
||||
if (cls.__OptDict["merged_output"] in kwargs) and (kwargs[cls.__OptDict["merged_output"]] is True):
|
||||
print("JOIN")
|
||||
if ("merged_output" in kwargs) and (kwargs["merged_output"] is True):
|
||||
return os.linesep.join(result)
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def getMessage(cls, commit_hash: str) -> str:
|
||||
"""
|
||||
retrieve a commit message from repository
|
||||
"""retrieve a commit message from repository
|
||||
Args:
|
||||
commit_hash: id of the commit
|
||||
Returns:
|
||||
@@ -179,10 +197,11 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
"""
|
||||
try:
|
||||
res = _exec(
|
||||
f'git log -z --pretty="tformat:%B%-C()" -n 1 {commit_hash}',
|
||||
f'git log -z --pretty="tformat:%B%-C()" -n 1 {commit_hash}', # ok
|
||||
None,
|
||||
True,
|
||||
).rstrip("\x00")
|
||||
)
|
||||
res = cast(str, res).rstrip("\x00")
|
||||
except gitversionhelper.unknownGITFatalError as _e:
|
||||
raise cls.commitNotFound("no commit found in commit history") from _e
|
||||
|
||||
@@ -190,48 +209,51 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
|
||||
@classmethod
|
||||
def getFromTag(cls, tag: str) -> str:
|
||||
"""
|
||||
retrieve a commit from repository associated to a tag
|
||||
"""retrieve a commit from repository associated to a tag
|
||||
Args:
|
||||
tag: tag of the commit
|
||||
Returns:
|
||||
the commit Id
|
||||
"""
|
||||
try:
|
||||
res = _exec(f"git rev-list -n 1 {tag}")
|
||||
res = _exec(f"git rev-list -n 1 {tag}") # ok
|
||||
except gitversionhelper.unknownGITFatalError as _e:
|
||||
raise cls.commitNotFound("no commit found in commit history") from _e
|
||||
|
||||
if len(res) == 0:
|
||||
raise cls.commitNotFound("no commit found in commit history")
|
||||
return res[0]
|
||||
|
||||
@classmethod
|
||||
def getLast(cls, **kwargs) -> str:
|
||||
"""
|
||||
retrieve last commit from repository
|
||||
def getLast(cls, **kwargs: Unpack[TKwargs]) -> str:
|
||||
"""retrieve last commit from repository
|
||||
Keyword Arguments:
|
||||
same_branch(bool): force searching only in the same branch
|
||||
kwargs/same_branch (bool): force searching only in the same branch
|
||||
kwargs/ignore_merged (bool): ignore merged commits
|
||||
Returns:
|
||||
the commit Id
|
||||
"""
|
||||
if (cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True):
|
||||
try:
|
||||
res = _exec("git rev-parse HEAD")
|
||||
except gitversionhelper.unknownGITFatalError as _e:
|
||||
raise cls.commitNotFound("no commit found in commit history") from _e
|
||||
str_cmd: str
|
||||
if ("same_branch" in kwargs) and (kwargs["same_branch"] is True):
|
||||
str_cmd = "git rev-list --max-count=1 --date-order HEAD --first-parent" # ok
|
||||
else:
|
||||
res = _exec('git for-each-ref --sort=-committerdate refs/heads/ --count 1 --format="%(objectname)"')
|
||||
str_cmd = "git log --format=%H --all -n1" # ok
|
||||
|
||||
if ("ignore_merged" in kwargs) and (kwargs["ignore_merged"] is True):
|
||||
str_cmd = str_cmd + " --no-merges" # ok
|
||||
|
||||
try:
|
||||
res = _exec(str_cmd)
|
||||
except gitversionhelper.unknownGITFatalError as _e:
|
||||
raise cls.commitNotFound("no commit found in commit history") from _e
|
||||
|
||||
if len(res) == 0:
|
||||
raise cls.commitNotFound("no commit found in commit history")
|
||||
return res[0]
|
||||
|
||||
class tag:
|
||||
"""
|
||||
class containing methods focusing on tags
|
||||
"""
|
||||
"""class containing methods focusing on tags"""
|
||||
|
||||
__OptDict = {"same_branch": "same_branch"}
|
||||
__validGitTagSort = [
|
||||
"",
|
||||
"v:refname",
|
||||
@@ -243,48 +265,42 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
]
|
||||
|
||||
class tagException(gitversionhelperException):
|
||||
"""
|
||||
generic tag exception
|
||||
"""
|
||||
"""generic tag exception"""
|
||||
|
||||
class tagNotFound(tagException):
|
||||
"""
|
||||
tag not found exception
|
||||
"""
|
||||
"""tag-not-found tag exception"""
|
||||
|
||||
class moreThanOneTag(tagException):
|
||||
"""
|
||||
more than one tag exception
|
||||
"""
|
||||
"""more-than-one-tag tag exception"""
|
||||
|
||||
@classmethod
|
||||
def getTags(cls, sort: str = "taggerdate", **kwargs) -> list[str | None]:
|
||||
"""
|
||||
retrieve all tags from a repository
|
||||
def getTags(cls, Sort: str = "taggerdate", **kwargs: Unpack[TKwargs]) -> List[str]:
|
||||
"""retrieve all tags from a repository
|
||||
Args:
|
||||
sort: sorting constraints (git format)
|
||||
Sort: sorting constraints (git format)
|
||||
Keyword Arguments:
|
||||
kwargs/same_branch (bool): force searching only in the same branch
|
||||
Returns:
|
||||
the tags list
|
||||
"""
|
||||
|
||||
if sort not in cls.__validGitTagSort:
|
||||
raise gitversionhelper.wrongArguments("sort option not in allowed list")
|
||||
if Sort not in cls.__validGitTagSort:
|
||||
raise gitversionhelper.wrongArguments("Sort option not in allowed list")
|
||||
|
||||
if (cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True):
|
||||
if ("same_branch" in kwargs) and (kwargs["same_branch"] is True):
|
||||
currentBranch = _exec("git rev-parse --abbrev-ref HEAD")
|
||||
return list(reversed(_exec(f"git tag --merged {currentBranch[0]} --sort={sort}")))
|
||||
return list(reversed(_exec(f"git tag -l --sort={sort}")))
|
||||
return list(reversed(_exec(f"git tag --merged {currentBranch[0]} --sort={Sort}")))
|
||||
return list(reversed(_exec(f"git tag -l --sort={Sort}")))
|
||||
|
||||
@classmethod
|
||||
def getLastTag(cls, **kwargs) -> str | None:
|
||||
"""
|
||||
retrieve the Latest tag from a repository
|
||||
def getLastTag(cls, **kwargs: Unpack[TKwargs]) -> str:
|
||||
"""retrieve the Latest tag from a repository
|
||||
Keyword Arguments:
|
||||
same_branch(bool): force searching only in the same branch
|
||||
kwargs/same_branch (bool): force searching only in the same branch
|
||||
Returns:
|
||||
the tag
|
||||
"""
|
||||
if (cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True):
|
||||
if ("same_branch" in kwargs) and (kwargs["same_branch"] is True):
|
||||
res = _exec("git describe --tags --first-parent --abbrev=0")
|
||||
else:
|
||||
res = _exec("git rev-list --tags --date-order --max-count=1")
|
||||
@@ -298,13 +314,12 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
return res[0]
|
||||
|
||||
@classmethod
|
||||
def getDistanceFromTag(cls, tag: str = None, **kwargs) -> int:
|
||||
"""
|
||||
retrieve the distance between Latest commit and tag in the repository
|
||||
def getDistanceFromTag(cls, tag: Optional[str] = None, **kwargs: Unpack[TKwargs]) -> int:
|
||||
"""retrieve the distance between Latest commit and tag in the repository
|
||||
Arguments:
|
||||
tag: reference tag, if None the most recent one will be used
|
||||
Keyword Arguments:
|
||||
same_branch(bool): force searching only in the same branch
|
||||
kwargs/same_branch (bool): force searching only in the same branch
|
||||
Returns:
|
||||
the tag
|
||||
"""
|
||||
@@ -313,18 +328,13 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
return int(_exec(f"git rev-list {tag}..HEAD --count")[0])
|
||||
|
||||
class version:
|
||||
"""
|
||||
class containing methods focusing on versions
|
||||
"""
|
||||
"""class containing methods focusing on versions"""
|
||||
|
||||
__OptDict = {
|
||||
"version_std": "version_std",
|
||||
"formated_output": "formated_output",
|
||||
"output_format": "output_format",
|
||||
"ignore_unknown_tags": "ignore_unknown_tags",
|
||||
}
|
||||
DefaultInputFormat = "Auto"
|
||||
VersionStds = {
|
||||
|
||||
TVersionStds = TypedDict("TVersionStds", {"regex": str, "regex_preversion_num": str, "regex_build_num": str}, total=False)
|
||||
|
||||
VersionStds: dict[str, TVersionStds] = {
|
||||
"SemVer": {
|
||||
"regex": r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)"
|
||||
r"(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)"
|
||||
@@ -333,41 +343,32 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
"regex_preversion_num": r"(?:\.)(?P<num>(?:\d+(?!\w))+)",
|
||||
"regex_build_num": r"(?:\.)(?P<num>(?:\d+(?!\w))+)",
|
||||
},
|
||||
"PEP440": {"regex": packaging_VERSION_PATTERN, "Auto": None},
|
||||
"PEP440": {"regex": packaging_VERSION_PATTERN},
|
||||
}
|
||||
__versionReseted = False
|
||||
|
||||
class versionException(gitversionhelperException):
|
||||
"""
|
||||
generic version exception
|
||||
"""
|
||||
"""generic version exception"""
|
||||
|
||||
class noValidVersion(versionException):
|
||||
"""
|
||||
no valid version found exception
|
||||
"""
|
||||
"""no valid version found exception"""
|
||||
|
||||
class PreAndPostVersionUnsupported(versionException):
|
||||
"""
|
||||
pre and post release can not be present at the same time
|
||||
"""
|
||||
"""pre and post release can not be present at the same time"""
|
||||
|
||||
class MetaVersion:
|
||||
"""
|
||||
generic version object
|
||||
"""
|
||||
"""generic version object"""
|
||||
|
||||
__OptDict = {
|
||||
"bump_type": "bump_type",
|
||||
"bump_dev_strategy": "bump_dev_strategy",
|
||||
"formated_output": "formated_output",
|
||||
}
|
||||
DefaultBumpType = "patch"
|
||||
BumpTypes = ["major", "minor", "patch", "dev"]
|
||||
DefaultBumpDevStrategy = "post"
|
||||
BumpDevStrategys = ["post", "pre-patch", "pre-minor", "pre-major"]
|
||||
TBumpTypes = Literal["major", "minor", "patch", "dev"]
|
||||
DefaultBumpType: TBumpTypes = "patch"
|
||||
BumpTypes: set[TBumpTypes] = {"major", "minor", "patch", "dev"}
|
||||
|
||||
version_std: str = "None"
|
||||
TBumpDevStrategies = Literal["post", "pre-patch", "pre-minor", "pre-major"]
|
||||
DefaultBumpDevStrategy: TBumpDevStrategies = "post"
|
||||
BumpDevStrategies: set[TBumpDevStrategies] = {"post", "pre-patch", "pre-minor", "pre-major"}
|
||||
|
||||
TVersionStd = Literal["Auto", "PEP440", "SemVer"]
|
||||
version_std: TVersionStd = "Auto"
|
||||
major: int = 0
|
||||
minor: int = 1
|
||||
patch: int = 0
|
||||
@@ -377,13 +378,13 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
version_std,
|
||||
major=0,
|
||||
minor=1,
|
||||
patch=0,
|
||||
pre_count=0,
|
||||
post_count=0,
|
||||
raw="0.1.0",
|
||||
version_std: TVersionStd = "Auto",
|
||||
major: int = 0,
|
||||
minor: int = 1,
|
||||
patch: int = 0,
|
||||
pre_count: int = 0,
|
||||
post_count: int = 0,
|
||||
raw: str = "0.1.0",
|
||||
): # pylint: disable=R0913
|
||||
self.version_std = version_std
|
||||
self.major = major
|
||||
@@ -394,50 +395,55 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
self.raw = raw
|
||||
|
||||
@classmethod
|
||||
def _getBumpDevStrategy(cls, **kwargs) -> str:
|
||||
"""
|
||||
get selected bump_dev_strategy
|
||||
def _getBumpDevStrategy(cls, **kwargs: Unpack[TKwargs]) -> str:
|
||||
"""get selected bump_dev_strategy
|
||||
Keyword Arguments:
|
||||
bump_dev_strategy(str): the given bump_dev_strategy (can be None)
|
||||
kwargs/bump_dev_strategy (str): the given bump_dev_strategy (can be None)
|
||||
Returns:
|
||||
Kwargs given bump_dev_strategy or the default one.
|
||||
"""
|
||||
BumpDevStrategy = cls.DefaultBumpDevStrategy
|
||||
if cls.__OptDict["bump_dev_strategy"] in kwargs:
|
||||
if kwargs[cls.__OptDict["bump_dev_strategy"]] in cls.BumpDevStrategys:
|
||||
BumpDevStrategy = kwargs[cls.__OptDict["bump_dev_strategy"]]
|
||||
BumpDevStrategy: str = cls.DefaultBumpDevStrategy
|
||||
|
||||
if kwargs and ("bump_dev_strategy" in kwargs):
|
||||
if kwargs["bump_dev_strategy"] in cls.BumpDevStrategies:
|
||||
BumpDevStrategy = kwargs["bump_dev_strategy"]
|
||||
else:
|
||||
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['bump_type']} requested")
|
||||
raise gitversionhelper.wrongArguments(f"invalid {'bump_type'} requested")
|
||||
return BumpDevStrategy
|
||||
|
||||
@classmethod
|
||||
def _getBumpType(cls, **kwargs) -> str:
|
||||
"""
|
||||
get selected bump_type
|
||||
def _getBumpType(cls, **kwargs: Unpack[TKwargs]) -> str:
|
||||
"""get selected bump_type
|
||||
Keyword Arguments:
|
||||
bump_type(str): the given bump_type (can be None)
|
||||
kwargs/bump_type (str): the given bump_type (can be None)
|
||||
Returns:
|
||||
Kwargs given bump_type or the default one.
|
||||
"""
|
||||
BumpType = cls.DefaultBumpType
|
||||
if cls.__OptDict["bump_type"] in kwargs:
|
||||
if kwargs[cls.__OptDict["bump_type"]] in cls.BumpTypes:
|
||||
BumpType = kwargs[cls.__OptDict["bump_type"]]
|
||||
BumpType: str = cls.DefaultBumpType
|
||||
if "bump_type" in kwargs:
|
||||
if kwargs["bump_type"] in cls.BumpTypes:
|
||||
BumpType = kwargs["bump_type"]
|
||||
else:
|
||||
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['bump_type']} requested")
|
||||
raise gitversionhelper.wrongArguments(f"invalid {'bump_type'} requested")
|
||||
return BumpType
|
||||
|
||||
def bump(self, amount: int = 1, **kwargs) -> gitversionhelper.version.MetaVersion | str: # pylint: disable=R0912
|
||||
"""
|
||||
bump the version to the next one
|
||||
def bump( # pylint: disable=R1260,R0912
|
||||
self, amount: int = 1, **kwargs: Unpack[TKwargs]
|
||||
) -> gitversionhelper.version.MetaVersion | str:
|
||||
"""bump the version to the next one
|
||||
Args:
|
||||
amount: number of revision to bump
|
||||
Keyword Arguments:
|
||||
bump_type(str): the given bump_type (can be None)
|
||||
bump_dev_strategy(str): the given bump_dev_strategy (can be None)
|
||||
kwargs/bump_type (str): the given bump_type (can be None)
|
||||
kwargs/bump_dev_strategy (str): the given bump_dev_strategy (can be None)
|
||||
Returns:
|
||||
the bumped version
|
||||
"""
|
||||
BumpType = self._getBumpType(**kwargs)
|
||||
|
||||
BumpType: str = self._getBumpType(**kwargs)
|
||||
|
||||
BumpDevStrategy = self._getBumpDevStrategy(**kwargs)
|
||||
|
||||
_v = copy(self)
|
||||
|
||||
if BumpType == "dev":
|
||||
@@ -473,88 +479,97 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
_v.patch = _v.patch + amount
|
||||
_v.pre_count = 0
|
||||
_v.post_count = 0
|
||||
|
||||
_v.raw = _v.doFormatVersion(**kwargs)
|
||||
|
||||
if (self.__OptDict["formated_output"] in kwargs) and (kwargs[self.__OptDict["formated_output"]] is True):
|
||||
if ("formated_output" in kwargs) and (kwargs["formated_output"] is True):
|
||||
return _v.doFormatVersion(**kwargs)
|
||||
return _v
|
||||
|
||||
def doFormatVersion(self, **kwargs) -> str:
|
||||
"""
|
||||
output a formated version string
|
||||
def doFormatVersion(self, **kwargs: Unpack[TKwargs]) -> str:
|
||||
"""output a formated version string
|
||||
Keyword Arguments:
|
||||
output_format: output format to render ("Auto" or "PEP440" or "SemVer")
|
||||
kwargs/output_format: output format to render ("Auto" or "PEP440" or "SemVer")
|
||||
Returns:
|
||||
formated version string
|
||||
"""
|
||||
return gitversionhelper.version.doFormatVersion(self, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def _getVersionStd(cls, **kwargs) -> str:
|
||||
"""
|
||||
get selected version_std
|
||||
def _getVersionStd(cls, **kwargs: Unpack[TKwargs]) -> gitversionhelper.version.MetaVersion.TVersionStd:
|
||||
"""get selected version_std
|
||||
Keyword Arguments:
|
||||
version_std(str): the given version_std (can be None)
|
||||
kwargs/version_std (str): the given version_std (can be None)
|
||||
Returns:
|
||||
Kwargs given version_std or the default one.
|
||||
"""
|
||||
VersionStd = cls.DefaultInputFormat
|
||||
if cls.__OptDict["version_std"] in kwargs:
|
||||
if kwargs[cls.__OptDict["version_std"]] in cls.VersionStds:
|
||||
VersionStd = kwargs[cls.__OptDict["version_std"]]
|
||||
VersionStd: str = cls.DefaultInputFormat
|
||||
if "version_std" in kwargs:
|
||||
if kwargs["version_std"] in cls.VersionStds:
|
||||
VersionStd = kwargs["version_std"]
|
||||
else:
|
||||
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['version_std']} requested")
|
||||
return VersionStd
|
||||
raise gitversionhelper.wrongArguments(f"invalid {'version_std'} requested")
|
||||
return cast(gitversionhelper.version.MetaVersion.TVersionStd, VersionStd)
|
||||
|
||||
@classmethod
|
||||
def getCurrentVersion(cls, **kwargs) -> MetaVersion | str:
|
||||
"""
|
||||
get the current version or bump depending of repository state
|
||||
def getCurrentVersion(cls, **kwargs: Unpack[TKwargs]) -> gitversionhelper.version.MetaVersion | str:
|
||||
"""get the current version or bump depending of repository state.
|
||||
Keyword Arguments:
|
||||
version_std(str): the given version_std (can be None)
|
||||
same_branch(bool): force searching only in the same branch
|
||||
formated_output(bool) : output a formated version string
|
||||
bump_type(str): the given bump_type (can be None)
|
||||
bump_dev_strategy(str): the given bump_dev_strategy (can be None)
|
||||
kwargs/version_std (str): the given version_std (can be None)
|
||||
kwargs/same_branch (bool): force searching only in the same branch
|
||||
kwargs/formated_output (bool): output a formated version string
|
||||
kwargs/bump_type (str): the given bump_type (can be None)
|
||||
kwargs/bump_dev_strategy (str): the given bump_dev_strategy (can be None)
|
||||
kwargs/output_format (str): output format to render ("Auto" or "PEP440" or "SemVer")
|
||||
Returns:
|
||||
the last version
|
||||
"""
|
||||
if gitversionhelper.repository.isDirty() is not False:
|
||||
raise gitversionhelper.repository.repositoryDirty("The repository is dirty and a current version can not be generated.")
|
||||
|
||||
saved_kwargs = copy(kwargs)
|
||||
if "formated_output" in kwargs:
|
||||
del saved_kwargs["formated_output"]
|
||||
|
||||
_v = cls.getLastVersion(**saved_kwargs)
|
||||
_v = cast(gitversionhelper.version.MetaVersion, cls.getLastVersion(**saved_kwargs))
|
||||
|
||||
if not cls.__versionReseted:
|
||||
amount = gitversionhelper.tag.getDistanceFromTag(_v.raw, **kwargs)
|
||||
_v = _v.bump(amount, **saved_kwargs)
|
||||
amount = gitversionhelper.tag.getDistanceFromTag(_v.raw, **saved_kwargs)
|
||||
_v = cast(gitversionhelper.version.MetaVersion, _v.bump(amount, **saved_kwargs))
|
||||
|
||||
if (cls.__OptDict["formated_output"] in kwargs) and (kwargs[cls.__OptDict["formated_output"]] is True):
|
||||
if ("formated_output" in kwargs) and (kwargs["formated_output"] is True):
|
||||
return _v.doFormatVersion(**kwargs)
|
||||
return _v
|
||||
|
||||
@classmethod
|
||||
def getCurrentFormatedVersion(cls, **kwargs) -> str:
|
||||
"""
|
||||
Same as getCurrentVersion() with formated_output kwarg activated
|
||||
"""
|
||||
kwargs["formated_output"] = True
|
||||
return cls.getCurrentVersion(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def _parseTag(cls, tag, **kwargs): # pylint: disable=R0914, R0912, R0915
|
||||
"""get the last version from tags
|
||||
Arguments:
|
||||
tag: the tag to be parsed
|
||||
def getCurrentFormatedVersion(cls, **kwargs: Unpack[TKwargs]) -> str:
|
||||
"""same as getCurrentVersion() with formated_output kwarg forced activated.
|
||||
Keyword Arguments:
|
||||
version_std(str): the given version_std (can be None)
|
||||
ignore_unknown_tags(bool): skip tags with not decoded versions (default to False)
|
||||
kwargs/version_std (str): the given version_std (can be None)
|
||||
kwargs/same_branch (bool): force searching only in the same branch
|
||||
kwargs/bump_type (str): the given bump_type (can be None)
|
||||
kwargs/bump_dev_strategy (str): the given bump_dev_strategy (can be None)
|
||||
kwargs/output_format (str): output format to render ("Auto" or "PEP440" or "SemVer")
|
||||
Returns:
|
||||
the last version
|
||||
"""
|
||||
VersionStd = cls._getVersionStd(**kwargs)
|
||||
kwargs["formated_output"] = True
|
||||
return cast(str, cls.getCurrentVersion(**kwargs))
|
||||
|
||||
@classmethod
|
||||
def _parseTag( # pylint: disable=R1260,R0914,R0912,R0915
|
||||
cls, tag: str, **kwargs: Unpack[TKwargs]
|
||||
) -> gitversionhelper.version.MetaVersion:
|
||||
"""get version from tags.
|
||||
Arguments:
|
||||
tag: the tag to be parsed
|
||||
Keyword Arguments:
|
||||
kwargs/version_std (str): the given version_std (can be None)
|
||||
Returns:
|
||||
MetaVersion object
|
||||
"""
|
||||
_m: Optional[re.Match[str]]
|
||||
VersionStd: gitversionhelper.version.MetaVersion.TVersionStd = cls._getVersionStd(**kwargs)
|
||||
bAutoVersionStd = False
|
||||
if VersionStd == "Auto":
|
||||
bAutoVersionStd = True
|
||||
@@ -565,14 +580,12 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
re.VERBOSE | re.IGNORECASE,
|
||||
)
|
||||
_m = re.match(_r, tag)
|
||||
if not _m:
|
||||
if _m is None:
|
||||
pass
|
||||
else:
|
||||
major, minor, patch = (
|
||||
int(_m.group("major")),
|
||||
int(_m.group("minor")),
|
||||
int(_m.group("patch")),
|
||||
)
|
||||
major = int(_m.group("major"))
|
||||
minor = int(_m.group("minor"))
|
||||
patch = int(_m.group("patch"))
|
||||
|
||||
pre_count = 0
|
||||
if _pre := _m.group("prerelease"):
|
||||
@@ -596,19 +609,25 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
re.VERBOSE | re.IGNORECASE,
|
||||
)
|
||||
_m = re.match(_r, tag)
|
||||
if not _m:
|
||||
if _m is None:
|
||||
pass
|
||||
else:
|
||||
ver = _m.group("release").split(".")
|
||||
ver += ["0"] * (3 - len(ver))
|
||||
ver[0] = int(ver[0])
|
||||
ver[1] = int(ver[1])
|
||||
ver[2] = int(ver[2])
|
||||
major, minor, patch = tuple(ver)
|
||||
pre_count = int(_m.group("pre_n")) if _m.group("pre_n") else 0
|
||||
post_count = int(_m.group("post_n2")) if _m.group("post_n2") else 0
|
||||
bFound = True
|
||||
VersionStd = "PEP440"
|
||||
res: str = _m.group("release")
|
||||
if isinstance(res, str):
|
||||
|
||||
ver = res.split(".")
|
||||
ver += ["0"] * (3 - len(ver))
|
||||
|
||||
ver_int: List[int] = [0, 0, 0]
|
||||
ver_int[0] = int(ver[0])
|
||||
ver_int[1] = int(ver[1])
|
||||
ver_int[2] = int(ver[2])
|
||||
major, minor, patch = tuple(ver_int)
|
||||
|
||||
pre_count = int(_m.group("pre_n")) if _m.group("pre_n") else 0
|
||||
post_count = int(_m.group("post_n2")) if _m.group("post_n2") else 0
|
||||
bFound = True
|
||||
VersionStd = "PEP440"
|
||||
|
||||
if not bFound:
|
||||
raise gitversionhelper.version.noValidVersion("no valid version found in tags")
|
||||
@@ -618,30 +637,30 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
return cls.MetaVersion(VersionStd, major, minor, patch, pre_count, post_count, tag)
|
||||
|
||||
@classmethod
|
||||
def getLastVersion(cls, **kwargs) -> MetaVersion | str: # pylint: disable=R0914, R0912, R0915
|
||||
def getLastVersion(cls, **kwargs: Unpack[TKwargs]) -> gitversionhelper.version.MetaVersion | str: # pylint: disable=R1260
|
||||
"""get the last version from tags
|
||||
Keyword Arguments:
|
||||
version_std(str): the given version_std (can be None)
|
||||
same_branch(bool): force searching only in the same branch
|
||||
formated_output(bool) : output a formated version string
|
||||
ignore_unknown_tags(bool): skip tags with not decoded versions (default to False)
|
||||
kwargs/version_std (str): the given version_std (can be None)
|
||||
kwargs/same_branch (bool): force searching only in the same branch
|
||||
kwargs/formated_output (bool): output a formated version string
|
||||
kwargs/ignore_unknown_tags (bool): skip tags with not decoded versions (default to False)
|
||||
Returns:
|
||||
the last version
|
||||
the last version in MetaVersion object or string
|
||||
"""
|
||||
lastTag = cls.MetaVersion.raw
|
||||
lastTag: str = cls.MetaVersion.raw
|
||||
cls.__versionReseted = False
|
||||
try:
|
||||
lastTag = gitversionhelper.tag.getLastTag(**kwargs)
|
||||
lastTag = cast(str, gitversionhelper.tag.getLastTag(**kwargs))
|
||||
except gitversionhelper.tag.tagNotFound:
|
||||
logging.warning("tag not found, reseting versionning")
|
||||
cls.__versionReseted = True
|
||||
|
||||
_v = None
|
||||
_v: Optional[gitversionhelper.version.MetaVersion] = None
|
||||
try:
|
||||
_v = cls._parseTag(lastTag, **kwargs)
|
||||
except gitversionhelper.version.noValidVersion as _ex:
|
||||
if (cls.__OptDict["ignore_unknown_tags"] in kwargs) and (kwargs[cls.__OptDict["ignore_unknown_tags"]] is True):
|
||||
tags = gitversionhelper.tag.getTags(sort="taggerdate", **kwargs)
|
||||
if ("ignore_unknown_tags" in kwargs) and (kwargs["ignore_unknown_tags"] is True):
|
||||
tags = gitversionhelper.tag.getTags(Sort="taggerdate", **kwargs)
|
||||
_v = None
|
||||
for _tag in tags:
|
||||
try:
|
||||
@@ -652,16 +671,15 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
if _v is None:
|
||||
raise gitversionhelper.version.noValidVersion() from _ex
|
||||
|
||||
if (cls.__OptDict["formated_output"] in kwargs) and (kwargs[cls.__OptDict["formated_output"]] is True):
|
||||
if ("formated_output" in kwargs) and (kwargs["formated_output"] is True):
|
||||
return _v.doFormatVersion(**kwargs)
|
||||
return _v
|
||||
|
||||
@classmethod
|
||||
def doFormatVersion(cls, inputversion: MetaVersion, **kwargs) -> str:
|
||||
"""
|
||||
output a formated version string
|
||||
def doFormatVersion(cls, inputversion: MetaVersion, **kwargs: Unpack[TKwargs]) -> str:
|
||||
"""output a formated version string from a MetaVersion object
|
||||
Keyword Arguments:
|
||||
output_format: output format to render ("Auto" or "PEP440" or "SemVer")
|
||||
kwargs/output_format (str): output format to render ("Auto" or "PEP440" or "SemVer")
|
||||
Args:
|
||||
inputversion: version to be rendered
|
||||
Returns:
|
||||
@@ -672,15 +690,13 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
if VersionStd == "Auto":
|
||||
VersionStd = inputversion.version_std
|
||||
|
||||
OutputFormat = None
|
||||
revpattern = ""
|
||||
revcount = ""
|
||||
post_count = inputversion.post_count
|
||||
pre_count = inputversion.pre_count
|
||||
patch = inputversion.patch
|
||||
|
||||
if cls.__OptDict["output_format"] in kwargs:
|
||||
OutputFormat = kwargs[cls.__OptDict["output_format"]]
|
||||
OutputFormat = kwargs.get("output_format")
|
||||
|
||||
if OutputFormat is None:
|
||||
OutputFormat = "{major}.{minor}.{patch}{revpattern}{revcount}"
|
||||
|
||||
@@ -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("/")
|
||||
|
||||
Reference in New Issue
Block a user