dev-version: change the scheme of non tagged version stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 09 Nov 2024 00:59:59 +0100
branchstable
changeset 52184 9048a0d782e1
parent 52183 96b113d22b34
child 52185 4496f059cf5c
dev-version: change the scheme of non tagged version We update the dev version scheme to make it more suitable for nightly build. See inline documentation for details.
setup.py
--- a/setup.py	Tue Nov 12 12:52:13 2024 +0100
+++ b/setup.py	Sat Nov 09 00:59:59 2024 +0100
@@ -396,9 +396,38 @@
             "only(parents(),'%s')" % ltag,
         ]
         changessince = len(hg.run(changessincecmd).splitlines())
-        version = '%s+hg%s.%s' % (ltag, changessince, hgid)
+        branch = hg.run(["branch"]).strip()
+        if branch == b'stable':
+            post_nb = 0
+        elif branch == b'default':
+            # we use 1 here to be greater than 0 to make sure change from
+            # default are considered newer than change on stable
+            post_nb = 1
+        else:
+            # what is this branch ? probably a local variant ?
+            post_nb = 2
+
+        # logic of the scheme
+        # - '.postX' to mark the version as "above" the tagged version
+        #   X is 0 for stable, 1 for default, 2 for anything else
+        # - use '.devY'
+        #   Y is the number of extra revision compared to the tag. So that
+        #   revision with more change are "above" previous ones.
+        # - '+hg.NODEID.local.DATE' if there is any uncommitted changes.
+        ltag = ltag.replace('6.9', '6.9.0')
+        version = '%s.post%d.dev%d+hg.%s' % (ltag, post_nb, changessince, hgid)
     if version.endswith('+'):
-        version = version[:-1] + 'local' + time.strftime('%Y%m%d')
+        version = version[:-1] + '.local.' + time.strftime('%Y%m%d')
+    # try to give warning early about bad version if possible
+    try:
+        from packaging.version import Version
+
+        Version(version)
+    except ImportError:
+        pass
+    except ValueError as exc:
+        eprint(r"/!\ generated version is invalid")
+        eprint(r"/!\ error: %s" % exc)
     return version