From f168ac9ac958a60e3c8fd656649939061f617501 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Mon, 23 Mar 2020 13:07:20 -0400 Subject: Use a better single-sourced version setup Fun read: https://packaging.python.org/guides/single-sourcing-package-version/ Anyway, I hated this way the least. Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 4 ++-- b4/command.py | 2 +- setup.py | 12 ++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/b4/__init__.py b/b4/__init__.py index 237131a..467da13 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -21,7 +21,7 @@ from email import charset charset.add_charset('utf-8', None) emlpolicy = email.policy.EmailPolicy(utf8=True, cte_type='8bit', max_line_length=None) -VERSION = '0.3.4-dev' +__VERSION__ = '0.3.4-dev' ATTESTATION_FORMAT_VER = '0.1' logger = logging.getLogger('b4') @@ -1323,7 +1323,7 @@ def get_requests_session(): global REQSESSION if REQSESSION is None: REQSESSION = requests.session() - REQSESSION.headers.update({'User-Agent': 'b4/%s' % VERSION}) + REQSESSION.headers.update({'User-Agent': 'b4/%s' % __VERSION__}) return REQSESSION diff --git a/b4/command.py b/b4/command.py index c2dc2b0..a2c7c28 100644 --- a/b4/command.py +++ b/b4/command.py @@ -55,7 +55,7 @@ def cmd(): description='A tool to work with public-inbox patches', formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) - parser.add_argument('--version', action='version', version=b4.VERSION) + parser.add_argument('--version', action='version', version=b4.__VERSION__) parser.add_argument('-d', '--debug', action='store_true', default=False, help='Add more debugging info to the output') parser.add_argument('-q', '--quiet', action='store_true', default=False, diff --git a/setup.py b/setup.py index 5b37505..ed24367 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import os -import b4 +import re from setuptools import setup # Utility function to read the README file. @@ -14,10 +14,18 @@ def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() +def find_version(source): + version_file = read(source) + version_match = re.search(r"^__VERSION__ = ['\"]([^'\"]*)['\"]", version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + + NAME = 'b4' setup( - version=b4.VERSION, + version=find_version('b4/__init__.py'), url='https://git.kernel.org/pub/scm/utils/b4/b4.git', name=NAME, description='A tool to work with public-inbox and patch archives', -- cgit v1.2.3