]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Use a static file for versioning
authorStephen Finucane <stephen@that.guru>
Wed, 5 Jun 2019 22:33:05 +0000 (23:33 +0100)
committerStephen Finucane <stephen@that.guru>
Mon, 18 Jul 2022 16:37:42 +0000 (17:37 +0100)
This means you don't have to install all dependencies simply to read the
version.

Signed-off-by: Stephen Finucane <stephen@that.guru>
docs/development/releasing.rst
patchwork/__init__.py
patchwork/tests/test_version.py [new file with mode: 0644]
patchwork/version.py
version.txt [new file with mode: 0644]

index 9c18e2021e793ed4fd9822fd927848da4ee0462e..8cde157f9c0c714eac2c0cb64c3a9c481675c7ad 100644 (file)
@@ -67,8 +67,7 @@ The follow steps apply to all releases:
 
 * Documentation references latest supported version of Django
 
-* 'alpha' tag has been removed from ``__version__`` in
-  ``patchwork/__init__.py``
+* 'alpha' tag has been removed from the version in in ``version.txt``
 
 * Commit has been tagged with an `annotated tag`__. The tag should take the
   form `v[MAJOR].[MINOR].[PATCH]`, e.g. `v2.0.1`. The message should read::
@@ -88,7 +87,7 @@ The following only apply to full releases, or those where the **MAJOR** or
 * A new branch called ``stable/MAJOR.MINOR`` has been created from the tagged
   commit
 
-Once released, bump the version found in ``patchwork/__init__.py`` once again.
+Once released, bump the version found in ``version.txt`` once again.
 
 __ https://git-scm.com/book/en/v2/Git-Basics-Tagging
 __ https://github.com/getpatchwork/patchwork/releases/new
index 8bdaa7f129e65d6cc28272aebe900eb9c417e21c..95ece87d03f10de5aa565cd183335ed10719cc04 100644 (file)
@@ -3,8 +3,9 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
+from patchwork.version import get_str_version
 from patchwork.version import get_latest_version
 
-VERSION = (3, 2, 0, 'alpha', 0)
+VERSION = get_str_version()
 
-__version__ = get_latest_version(VERSION)
+__version__ = get_latest_version()
diff --git a/patchwork/tests/test_version.py b/patchwork/tests/test_version.py
new file mode 100644 (file)
index 0000000..f9a994f
--- /dev/null
@@ -0,0 +1,35 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2022 Stephen Finucane <stephen@that.guru>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import re
+import unittest
+
+from patchwork import version
+
+from django import test
+
+
+class TestVersion(test.TestCase):
+    @unittest.skipIf(
+        version.get_git_version() == '',
+        "this doesn't appear to be a git repo so we can't run git-based tests",
+    )
+    def test_validate_version(self):
+        str_version = version.get_str_version()
+        git_version = version.get_git_version()
+
+        str_re = r'v\d\.\d\.\d(\.alpha-0)?'  # v1.2.3-alpha-0
+        git_re = r'v\d\.\d\.\d(\.post\d+-\w+)?'  # v1.2.3.post1-abc123
+
+        str_match = re.match(str_re, version.format_str_version(str_version))
+        git_match = re.match(git_re, version.format_git_version(git_version))
+
+        # both should match a specific pattern at a minimum
+        self.assertIsNotNone(str_match)
+        self.assertIsNotNone(git_match)
+
+        # if the tag is missing from one, it should be missing from the other
+        # (and vice versa)
+        self.assertEqual(bool(str_match.group(1)), bool(git_match.group(1)))
index d1913138925dd7c4562cd50be8a649afaca2fb46..01bdfaabb3c9dd4de75c0eec827e92c1948f826c 100644 (file)
@@ -10,21 +10,21 @@ import os
 ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir)
 
 
-def get_latest_version(version):
+def get_latest_version():
     """Returns the most recent version available.
 
     This is either the hard-coded version or, if using Git, the version
     per the most recent Git tag.
     """
-    git_version = format_git_version(get_raw_git_version())
-    str_version = format_version(version)
+    git_version = format_git_version(get_git_version())
+    str_version = format_str_version(get_str_version())
 
     return git_version or str_version
 
 
-def format_version(version):
+def format_str_version(version):
     """Format version tuple."""
-    return '.'.join(
+    return 'v' + '.'.join(
         [
             '.'.join([str(x) for x in version[:3]]),
             '-'.join([str(x) for x in version[3:]]),
@@ -41,7 +41,15 @@ def format_git_version(version):
         return version
 
 
-def get_raw_git_version():
+def get_str_version():
+    """Retrieve the version from version.txt."""
+    with open(os.path.join(ROOT_DIR, 'version.txt')) as fh:
+        version = fh.readline().strip()
+
+    return version.split('.')
+
+
+def get_git_version():
     """Returns the raw git version via 'git-describe'."""
     try:
         git_version = subprocess.check_output(
diff --git a/version.txt b/version.txt
new file mode 100644 (file)
index 0000000..2c1cf68
--- /dev/null
@@ -0,0 +1 @@
+3.2.0.alpha.0