From: Stephen Finucane Date: Wed, 5 Jun 2019 22:33:05 +0000 (+0100) Subject: Use a static file for versioning X-Git-Tag: v3.2.0~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bd537e7120f6dd70dc0454a920ec327372856e0;p=thirdparty%2Fpatchwork.git Use a static file for versioning This means you don't have to install all dependencies simply to read the version. Signed-off-by: Stephen Finucane --- diff --git a/docs/development/releasing.rst b/docs/development/releasing.rst index 9c18e202..8cde157f 100644 --- a/docs/development/releasing.rst +++ b/docs/development/releasing.rst @@ -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 diff --git a/patchwork/__init__.py b/patchwork/__init__.py index 8bdaa7f1..95ece87d 100644 --- a/patchwork/__init__.py +++ b/patchwork/__init__.py @@ -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 index 00000000..f9a994f3 --- /dev/null +++ b/patchwork/tests/test_version.py @@ -0,0 +1,35 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2022 Stephen Finucane +# +# 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))) diff --git a/patchwork/version.py b/patchwork/version.py index d1913138..01bdfaab 100644 --- a/patchwork/version.py +++ b/patchwork/version.py @@ -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 index 00000000..2c1cf683 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +3.2.0.alpha.0