diff --git a/setup.py b/setup.py index 5e0e596..8b55751 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ import configparser import os +import re import subprocess import zipfile from io import BytesIO @@ -7,19 +8,42 @@ from setuptools import find_packages, setup +HERE = os.path.abspath(os.path.dirname(__file__)) TOMATO_DIR = "src" -# Get version -with open(os.path.join(TOMATO_DIR, "tomato", "__init__.py")) as version_file: - __version__ = version_file.read().strip() -# Get the long description from the README file -here = os.path.abspath(os.path.dirname(__file__)) -try: - with open(os.path.join(here, "README.md"), encoding="utf-8") as f: - long_description = f.read() -except FileNotFoundError: # not necessary, e.g. in Docker - long_description = "" +def get_version(): + """ Read version from __init__.py + + Raises: + ValueError: if __init__ is not read, or __version__ is not in __init__ + + Returns: + str -- value of __version__ as defined in __init__.py + """ + version_file2 = os.path.join(HERE, TOMATO_DIR, "tomato", "__init__.py") + with open(version_file2) as f: + init_contents = f.read().strip() + + exp = r"^__version__ = ['\"]([^'\"]*)['\"]" + mo = re.search(exp, init_contents, re.M) + if mo: + return mo.group(1) + else: + raise ValueError("Unable to find version string in %s." % (f,)) + + +def get_long_description(): + """Get the long description from the README file + + Returns: + str -- the README content in the markdown format + """ + try: + with open(os.path.join(HERE, "README.md"), encoding="utf-8") as f: + return f.read() + except FileNotFoundError: # not necessary, e.g. in Docker + return "" class BinarySetup: @@ -99,20 +123,20 @@ def _download_binary(fpath, bin_url, sys_os): setup( name="tomato", - version=__version__, + version=get_version(), author="Sertan Senturk", author_email="contact AT sertansenturk DOT com", maintainer="Sertan Senturk", maintainer_email="contact AT sertansenturk DOT com", url="https://github.com/sertansenturk/tomato", description="Turkish-Ottoman Makam (M)usic Analysis TOolbox", - long_description=long_description, + long_description=get_long_description(), long_description_content_type="text/markdown", download_url=( "https://github.com/sertansenturk/tomato.git" - if "dev" in __version__ + if "dev" in get_version() else "https://github.com/sertansenturk/tomato/releases/tag/" - "v{0:s}".format(__version__) + "v{0:s}".format(get_version()) ), classifiers=[ "Development Status :: 4 - Beta", diff --git a/src/tomato/__init__.py b/src/tomato/__init__.py index ef91994..9e78220 100644 --- a/src/tomato/__init__.py +++ b/src/tomato/__init__.py @@ -1 +1 @@ -__version__ = '0.14.0' +__version__ = "0.14.0"