Compare commits
1 Commits
0.0.1.post
...
0.0.1.post
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46ee6dec57 |
@@ -8,7 +8,8 @@
|
||||
|
||||
"""
|
||||
This module is the main gitversionhelper file, containing all the code.
|
||||
This project aim to be kept compact and focused on helping doing handy things with git when it deal with project versions/tags.
|
||||
This project aim to be kept compact and focused on helping doing handy
|
||||
things with git when it deal with project versions/tags.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -56,8 +57,8 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
Return:
|
||||
True if it is dirty
|
||||
"""
|
||||
return True if _exec(f"git status --short") else False
|
||||
|
||||
return True if _exec("git status --short") else False
|
||||
|
||||
class tag:
|
||||
"""
|
||||
class containing methods focusing on tags
|
||||
@@ -102,7 +103,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
Return:
|
||||
the tag
|
||||
"""
|
||||
if (tag is None):
|
||||
if tag is None:
|
||||
tag = cls.getLastTag(**kwargs)
|
||||
return int(_exec(f"git rev-list {tag}..HEAD --count")[0])
|
||||
|
||||
@@ -139,7 +140,12 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
raw:str = "0.1.0"
|
||||
|
||||
def __init__(self,major=0,minor=1,patch=0,pre_count=0,post_count=0,raw="0.1.0"):
|
||||
self.major,self.minor,self.patch,self.pre_count,self.post_count,self.raw = major,minor,patch,pre_count,post_count,raw
|
||||
self.major = major
|
||||
self.minor = minor
|
||||
self.patch = patch
|
||||
self.pre_count = pre_count
|
||||
self.post_count = post_count
|
||||
self.raw = raw
|
||||
|
||||
@classmethod
|
||||
def _getBumpDevStrategy(cls,**kwargs) -> str:
|
||||
@@ -212,7 +218,11 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
_v.pre_count=0
|
||||
_v.post_count=0
|
||||
|
||||
_v.raw="{major}.{minor}.{patch}{revpattern}{revcount}".format(major=_v.major,minor=_v.minor,patch=_v.patch,revpattern="",revcount="")
|
||||
_v.raw="{major}.{minor}.{patch}{revpattern}{revcount}".format(major=_v.major,\
|
||||
minor=_v.minor,\
|
||||
patch=_v.patch,\
|
||||
revpattern="",\
|
||||
revcount="")
|
||||
return _v
|
||||
|
||||
def doFormatVersion(self,**kwargs):
|
||||
@@ -228,7 +238,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
Kwargs given version_std or the default one.
|
||||
"""
|
||||
VersionStd = cls.DefaultInputFormat
|
||||
if (cls.__OptDict["version_std"] in kwargs):
|
||||
if cls.__OptDict["version_std"] in kwargs:
|
||||
if kwargs[cls.__OptDict["version_std"]] in cls.VersionStds:
|
||||
VersionStd = kwargs[cls.__OptDict["version_std"]]
|
||||
else:
|
||||
@@ -247,14 +257,15 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
the last version
|
||||
"""
|
||||
VersionStd = cls._getVersionStd(**kwargs)
|
||||
_r=re.compile(r"^\s*" + cls.VersionStds[VersionStd]["regex"] + r"\s*$", re.VERBOSE | re.IGNORECASE)
|
||||
_r=re.compile(r"^\s*" + cls.VersionStds[VersionStd]["regex"] + r"\s*$", re.VERBOSE | \
|
||||
re.IGNORECASE)
|
||||
|
||||
lastTag = gitversionhelper.tag.getLastTag(**kwargs)
|
||||
|
||||
_m = re.match(_r,lastTag)
|
||||
if not _m:
|
||||
raise RuntimeError("no valid version found in tags")
|
||||
if VersionStd is "PEP440":
|
||||
if VersionStd == "PEP440":
|
||||
ver=_m.group("release").split(".")
|
||||
ver += ["0"] * (3 - len(ver))
|
||||
ver[0]=int(ver[0])
|
||||
@@ -263,8 +274,11 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
major, minor, patch = tuple(ver)
|
||||
pre_count = int(_m.group("pre_n")) if _m.group("pre_n") else 0
|
||||
post_count = int(_m.group("post_n2")) if _m.group("post_n2") else 0
|
||||
elif VersionStd is "SemVer":
|
||||
major, minor, patch = int(_m.group("major")),int(_m.group("minor")),int(_m.group("patch")),(_m.group("prerelease") if _m.group("prerelease") else ""), ""
|
||||
elif VersionStd == "SemVer":
|
||||
major, minor, patch = int(_m.group("major")),\
|
||||
int(_m.group("minor")),\
|
||||
int(_m.group("patch")),\
|
||||
(_m.group("prerelease") if _m.group("prerelease") else ""), ""
|
||||
pre_count = 0
|
||||
post_count = 0
|
||||
|
||||
@@ -272,8 +286,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
|
||||
if ((cls.__OptDict["formated_output"] in kwargs) and (kwargs[cls.__OptDict["formated_output"]] is True)):
|
||||
return cls.doFormatVersion(_v,**kwargs)
|
||||
else:
|
||||
return _v
|
||||
return _v
|
||||
|
||||
@classmethod
|
||||
def doFormatVersion(cls,inputversion:MetaVersion,**kwargs):
|
||||
@@ -295,12 +308,12 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
|
||||
if (cls.__OptDict["output_format"] in kwargs):
|
||||
OutputFormat=kwargs[cls.__OptDict["output_format"]]
|
||||
if OutputFormat is None:
|
||||
if VersionStd is "PEP440":
|
||||
if VersionStd == "PEP440":
|
||||
OutputFormat = "{major}.{minor}.{patch}{revpattern}{revcount}"
|
||||
if post_count > 0:
|
||||
revpattern=".post"
|
||||
revcount=f"{post_count}"
|
||||
elif VersionStd is "SemVer":
|
||||
elif VersionStd == "SemVer":
|
||||
OutputFormat = "{major}.{minor}.{patch}{revpattern}{revcount}"
|
||||
if post_count > 0:
|
||||
pre_count = pre_count + post_count
|
||||
|
||||
Reference in New Issue
Block a user