From c53689eb2a544ac30dda40b8dec6c519a03a0224 Mon Sep 17 00:00:00 2001 From: hwipl <33433250+hwipl@users.noreply.github.com> Date: Thu, 19 Dec 2019 15:18:51 +0100 Subject: [PATCH] setup.py: read version from server.py In setup.py, read the nuqql-slixmppd version from nuqql_slixmppd/server.py. Signed-off-by: hwipl <33433250+hwipl@users.noreply.github.com> --- setup.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 362b42b..bbe112c 100755 --- a/setup.py +++ b/setup.py @@ -4,9 +4,13 @@ nuqql-slixmppd setup file """ +import os +import re +import codecs + from setuptools import setup -VERSION = "0.4" +# setup parameters DESCRIPTION = "XMPP client network daemon using slixmpp" with open("README.md", 'r') as f: LONG_DESCRIPTION = f.read() @@ -15,9 +19,35 @@ "License :: OSI Approved :: MIT License", ] + +# setup helpers +def read(*parts): + """ + Read encoded file + """ + + here = os.path.abspath(os.path.dirname(__file__)) + with codecs.open(os.path.join(here, *parts), 'r') as enc_file: + return enc_file.read() + + +def find_version(*file_paths): + """ + Find version in encoded file + """ + + version_file = read(*file_paths) + version_pattern = r"^VERSION = ['\"]([^'\"]*)['\"]" + version_match = re.search(version_pattern, version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + + +# run setup setup( name="nuqql-slixmppd", - version=VERSION, + version=find_version("nuqql_slixmppd", "server.py"), description=DESCRIPTION, license="MIT", long_description=LONG_DESCRIPTION,