From a34b1f6ddd44c512ab647dd934c7e9959d95d358 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 13 Nov 2025 17:07:23 +0100 Subject: [PATCH] Bugfix: setVersion.py -- ability to handle suffixes Turns out that in practice there will be (at least temporarily) some version-tags including a suffix: the RC-versions! Now there is the special twist, that Git does not allow '~' in Tag names, and thus `git-buildpackage` introduced an additional layer of translation. So we are forced to revert that translation, which is possible, since the basic Debian version syntax disallows '_' in version numbers (because '_' is used to separate the package name from the version number). It seems prudent to implement that as an preprocessing step and thus keep it out of the regular version number syntax. Furthermore we need the ability to handle existing suffixes, which (as we know now) can be picked up from the Git history. * my decision is to allow both pass-through and suppressing them * use `--suffix=False` to suppress / remove any existing suffix * the latter now allows us also to automate the setting of the final Release version --- admin/buildVersion.py | 50 ++++++++++++++-- wiki/thinkPad.ichthyo.mm | 121 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 162 insertions(+), 9 deletions(-) diff --git a/admin/buildVersion.py b/admin/buildVersion.py index cf1309cd5..690c289e3 100755 --- a/admin/buildVersion.py +++ b/admin/buildVersion.py @@ -47,7 +47,7 @@ def parseAndBuild(): ,choices=['maj','min','rev'], const='rev' ,help='bump the version detected from Git (optionally bump a specific component)') parser.add_argument ('--suffix','-s' - ,help='append (or replace) a suffix (by default attached with ~)') + ,help='append (or replace) a suffix (attached with ~); False -> remove suffix') parser.add_argument ('--snapshot' ,action='store_true' ,help='mark as development snapshot by appending ~dev.YYYYMMDDhhmm, using UTC date from HEAD commit') @@ -72,11 +72,30 @@ def getTimestampFromGit(): -def rebuild (version, bump=None, suffix=None, snapshot=False): - mat = re.fullmatch (VER_SYNTAX, version) +def parseVerNr (verStr): + """ parse a version spec from a git tag, + possibly preprocess to translate _ -> ~ + """ + NOT_SFX = r'(?:[^_\W]|[\.\+])+' + DECODE = r'('+NOT_SFX+')(?:_('+NOT_SFX+'))?' + # + mat = re.fullmatch (DECODE, verStr) if not mat: - __FAIL ('invalid version syntax in "'+version+'"') + __FAIL ('version string contains invalid characters: "'+verStr+'"') + verStr = mat.group(1) + if mat.group(2): + verStr += '~'+mat.group(2) + # + # check syntax of translated version spec + mat = re.fullmatch (VER_SYNTAX, verStr) + if not mat: + __FAIL ('invalid version syntax in "'+verStr+'"') + else: + return mat + +def rebuild (version, bump=None, suffix=None, snapshot=False): + mat = parseVerNr (version) maj = mat.group(1) min = mat.group(2) rev = mat.group(3) @@ -97,7 +116,10 @@ def rebuild (version, bump=None, suffix=None, snapshot=False): if snapshot: suf = 'dev.'+getTimestampFromGit() elif suffix: - suf = suffix + if not evalBool(suffix): + suf = None + else: + suf = suffix version = maj if min: @@ -128,10 +150,26 @@ def runGit (argStr): proc = subprocess.run (argList, check=True, capture_output=True, encoding='utf-8', env={'LC_ALL':'C'}) return proc.stdout.rstrip() # Note: sanitised env except: - __FAIL ('invoking git-describe') + __FAIL ('invoking git '+argStr) +def evalBool (val) ->bool: + """ evaluate as bool value + @author: Tim Poulsen + @note: Adapted from the original, published 2023, CC-By-SA-4 + https://www.timpoulsen.com/2023/python-bool-from-any.html + """ + try: + return float(val) > 0 + except: + if type(val) is str: + return val.lower() not in ['false', 'no', 'n', 'none', 'null'] + else: + # rely on Python's type coercion rules + return bool(val) + + def __ERR (*args, **kwargs): print (*args, file=sys.stderr, **kwargs) diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index e64b0ffe9..b567c5944 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -166402,7 +166402,7 @@ that situation will improve in forseeable future. - + @@ -166697,7 +166697,7 @@ that situation will improve in forseeable future. - + @@ -166721,11 +166721,121 @@ that situation will improve in forseeable future. + + + + +

+ ...da in Git-Tags keine Tilde erlaubt ist, hat git-buildpackage hier eine Übersetzung in '_' eingeführt +

+ +
+ + + + + + + + +

+ ...denn dummerweise ist '_' ein word-constituent-char, d.h. die vorhergehenden Versions-Komponenten würden einen Trenner durch '_' einfach mit konsumieren +

+ +
+
+ + + + +

+ Gemäß Debian-Policy ist das nämlich der Trenner zum Paketnamen, und darf daher in der nachfolgenden Versionsnummer nicht nochmal vorkommen (d.h. der letzte Underscore trennt den Namen von der versionsnr) +

+ +
+
+
+ + + + + + +

+ ist so möglich, da Underscore anderweitig nicht erlaubt ist (und Grenzfälle können hier unberücksichtigt bleiben, da letztlich in Lumiera nur sinnvolle und valide Versionsnummern vergeben werden dürfen; als zusätzilcher Filter dient das mandatory-prefix 'v*' im Tag +

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +

+ Und zwar temporär, während man auf dem Release-Zweig ist, kann es ein RC-Tag geben. Wenngleich auch die (von mir intendierte) Git-flow policy verlangt, daß solche RC-Tags mit dem Release selber wieder gelöscht werden — man wird sie aber zulassen müssen, damit später mal eine CI korrekt mit Release-Candidates umgehen kann. Die Realität ist komplex. Seufz. +

+ +
+ + +
+ + + + +

+ Drei Varianten wären denkbar, diese hier erscheint mir am praktischten, und natürlichsten (und ist einfach umzusetzen, ohne den Parser komplexer zu machen +

+ +
+ + + + + + +
    +
  • + man kann argparse.SUPPRESS verwenden +
  • +
  • + man nargs='?' setzen, und zudem einen Default angeben; damit ließe sich der Wert zur Option seinerseits optional machen... +
  • +
+

+ Dadruch würde aber der Aufruf komplexer, da nun der 'suffix' key möglicherweise nicht mehr im resultierenden dictionary nach Parser-Auswertung enthalten wäre. +

+ +
+
+
+
+
@@ -178045,7 +178155,12 @@ Since then others have made contributions, see the log for the history. - + + + + + +