From 73ac351bdd1f67af994d6d65cf8a1184c3958a0d Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Fri, 27 Sep 2019 23:18:50 +0200 Subject: [PATCH] Fix version handling See https://packaging.python.org/guides/single-sourcing-package-version/. --- bin/etherpump | 4 ++-- etherpump/__init__.py | 3 ++- setup.py | 24 ++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/bin/etherpump b/bin/etherpump index 31a2c8e..ca54605 100755 --- a/bin/etherpump +++ b/bin/etherpump @@ -2,7 +2,7 @@ import sys -from etherpump import VERSION +from etherpump import __VERSION__ usage = """Usage: etherpump CMD @@ -36,7 +36,7 @@ try: print(usage) sys.exit(0) elif any(arg in args for arg in ['--version', '-v']): - print('etherpump {}'.format(VERSION)) + print('etherpump {}'.format(__VERSION__)) sys.exit(0) except IndexError: diff --git a/etherpump/__init__.py b/etherpump/__init__.py index 992440f..22da45f 100644 --- a/etherpump/__init__.py +++ b/etherpump/__init__.py @@ -1,4 +1,5 @@ import os DATAPATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data") -VERSION = '0.0.2' + +__VERSION__ = '0.0.2' diff --git a/setup.py b/setup.py index ffb4ef8..3e47cae 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,35 @@ #!/usr/bin/env python3 +import codecs +import os +import re + from setuptools import find_packages, setup -from etherpump import VERSION + +def read(*parts): + current_file = os.path.abspath(os.path.dirname(__file__)) + with codecs.open(os.path.join(current_file, *parts), 'r') as fp: + return fp.read() + + +def find_version(*file_paths): + version_file = read(*file_paths) + 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.") + with open('README.md', 'r') as handle: long_description = handle.read() + setup( name='etherpump', - version=VERSION, + version=find_version('etherpump', '__init__.py'), author='Varia members', author_email='info@varia.zone', packages=find_packages(),