From 61abf1cdf622d8c9fb4f03eb6b06c4ddc1677362 Mon Sep 17 00:00:00 2001 From: Christopher Engelhard Date: Jul 24 2020 16:41:16 +0000 Subject: single-source program version --- diff --git a/setup.py b/setup.py index 08f5db1..d3b363b 100644 --- a/setup.py +++ b/setup.py @@ -22,6 +22,20 @@ def readme(): with open('README.md') as f: return f.read() +# get __version__ from a file +def read(rel_path): + here = os.path.abspath(os.path.dirname(__file__)) + with codecs.open(os.path.join(here, rel_path), 'r') as fp: + return fp.read() + +def get_version(rel_path): + for line in read(rel_path).splitlines(): + if line.startswith('__version__'): + delim = '"' if '"' in line else "'" + return line.split(delim)[1] + else: + raise RuntimeError("Unable to find version string.") + # setuptools configuration setup( name='hellocopr', @@ -32,7 +46,9 @@ setup( author='Christopher Engelhard', author_email='ce@lcts.de', license='GPLv3', - version='1.0.0', + + # extract version from source + version=get_version("src/hellocopr/__init__.py"), # tell distutils packages are under src directory package_dir={ diff --git a/src/hellocopr/__init__.py b/src/hellocopr/__init__.py index fd5e448..7b9010a 100644 --- a/src/hellocopr/__init__.py +++ b/src/hellocopr/__init__.py @@ -13,3 +13,5 @@ # # You should have received a copy of the GNU General Public License # along with hellocopr. If not, see . + +__version__ = '1.0.0' diff --git a/src/hellocopr/hellocopr.py b/src/hellocopr/hellocopr.py index d2016c9..d2eddbb 100644 --- a/src/hellocopr/hellocopr.py +++ b/src/hellocopr/hellocopr.py @@ -16,10 +16,9 @@ from colorama import init +from hellocopr import __version__ from hellocopr.colors import red, green, normal -__version__ = '1.0.0' - init() def hello():