aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-03-23 13:07:20 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-03-23 13:07:20 -0400
commitf168ac9ac958a60e3c8fd656649939061f617501 (patch)
treed464a1940b8403872ba3654e3b73e176beb620c7
parentda3e51194c649b29b98f23c1af1b50c8578cdd5c (diff)
downloadb4-f168ac9ac958a60e3c8fd656649939061f617501.tar.gz
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 <konstantin@linuxfoundation.org>
-rw-r--r--b4/__init__.py4
-rw-r--r--b4/command.py2
-rw-r--r--setup.py12
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',