From 00fdf932b7380004f08cf38354fb732b5715163a Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Tue, 14 Feb 2023 14:05:35 +0100 Subject: [PATCH] Polish version retrieval and long description loading --- setup.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/setup.py b/setup.py index 30f5e17..aefac89 100644 --- a/setup.py +++ b/setup.py @@ -1,33 +1,30 @@ from setuptools import setup, find_packages -import os import re import pathlib +HERE = pathlib.Path(__file__).parent.absolute() PACKAGE = "qibotn" # Returns the qibotn version -def get_version(): - """ Gets the version from the package's __init__ file - if there is some problem, let it happily fail """ - VERSIONFILE = os.path.join("src", PACKAGE, "__init__.py") - initfile_lines = open(VERSIONFILE, "rt").readlines() - VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]" - for line in initfile_lines: - mo = re.search(VSRE, line, re.M) - if mo: - return mo.group(1) +def version(): + """Gets the version from the package's __init__ file + if there is some problem, let it happily fail""" + version_file = HERE / "src" / PACKAGE / "__init__.py" + version_regex = r"^__version__ = ['\"]([^'\"]*)['\"]" + + initfile = version_file.read_text(encoding="utf-8") + matched = re.search(version_regex, initfile, re.M) + + if matched is not None: + return matched.group(1) + return "0.0.0" # load long description from README -this_directory = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f: - long_description = f.read() - - setup( name="qibotn", - version=get_version(), + version=version(), description="A tensor-network translation module for quantum computing", author="The Qibo team", author_email="", @@ -58,6 +55,6 @@ setup( ], }, python_requires=">=3.7.0", - long_description=long_description, - long_description_content_type='text/markdown', + long_description=(HERE / "README.md").read_text(encoding="utf-8"), + long_description_content_type="text/markdown", )