* 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::
* 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
#
# 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()
--- /dev/null
+# 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)))
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:]]),
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(
--- /dev/null
+3.2.0.alpha.0