From 5826e9fdc9697531ca270c24c52c8bccacafefe1 Mon Sep 17 00:00:00 2001 From: Rafael Leira Date: Fri, 24 Jun 2022 12:02:41 +0200 Subject: [PATCH] update setup script and generate versions automatically --- MANIFEST.in | 2 + pystorcli/__init__.py | 1 + pystorcli/version.py | 1 + setup.py | 118 ++++++++++++++++++++++++++++++++---------- 4 files changed, 96 insertions(+), 26 deletions(-) create mode 100644 MANIFEST.in create mode 100644 pystorcli/version.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..c0dc63a --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include README.md +recursive-include docs * diff --git a/pystorcli/__init__.py b/pystorcli/__init__.py index a7fabc7..aaf1851 100644 --- a/pystorcli/__init__.py +++ b/pystorcli/__init__.py @@ -15,6 +15,7 @@ from . import common from . import exc +from .version import __version__ _SINGLETON_MODULE_LOCK = threading.Lock() diff --git a/pystorcli/version.py b/pystorcli/version.py new file mode 100644 index 0000000..8879c6c --- /dev/null +++ b/pystorcli/version.py @@ -0,0 +1 @@ +__version__ = "0.3.7" diff --git a/setup.py b/setup.py index d1d9dda..67746ad 100644 --- a/setup.py +++ b/setup.py @@ -1,33 +1,99 @@ +# Copyright 2018 Martin Dojcak +# Copyright 2022 Rafael Leira, Naudit HPCN S.L. +# +# This program is licensed under BSD 3-clause license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +################################################################ + +from setuptools import setup +from subprocess import Popen, PIPE import os -import setuptools +import re + + +def read_file(path): + with open(os.path.join(os.path.dirname(__file__), path)) as fp: + return fp.read() + + +def _get_version_match(content): + # Search for lines of the form: # __version__ = 'ver' + regex = r"^__version__ = ['\"]([^'\"]*)['\"]" + version_match = re.search(regex, content, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string in '__init__.py'.") + + +def get_version(path): + try: + p = Popen(['git', 'describe', '--always', '--tags'], + stdout=PIPE, stderr=PIPE) + p.stderr.close() + line = p.stdout.readlines()[0] + describe = line.strip()[1:].decode('utf-8').split('-') + if len(describe) == 1: + return describe[0] + else: + return describe[0]+'.'+describe[1] + + except Exception as e: + print(e) + return _get_version_match(read_file(path)) + + +def write_version(path): + ''' + Write the version on variavle __version__ in version.py and returns the version + ''' + version = get_version(os.path.join(path, '__init__.py')) + + with open(os.path.join(path, 'version.py'), 'w') as f: + f.write('__version__ = "{}"\n'.format(version)) + + return version + + +def get_long_description(): + 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() + + return long_description -def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() +REQUIREMENTS = [ +] +CLASSIFIERS = [ + "Programming Language :: Python :: 3", + 'Intended Audience :: Developers', + 'Intended Audience :: Information Technology', + 'Intended Audience :: System Administrators', + 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', + 'Natural Language :: English', + 'Operating System :: POSIX', + 'Topic :: System :: Hardware :: Hardware Drivers', + 'Topic :: System :: Installation/Setup', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Programming Language :: Python', +] -setuptools.setup( - name="pystorcli", - version="0.3.6", - author="Martin Dojcak", - author_email="martin@dojcak.sk", - description="StorCLI module wrapper", - long_description=read('README.md'), +setup( + name="PyStorCLI2", + version=write_version('pystorcli'), + author="Rafael Leira", + author_email="rafael.leira@naudit.es", + description="StorCLI module wrapper 2", + long_description=get_long_description(), long_description_content_type="text/markdown", - url="https://github.com/Chillisystems/pystorcli", - packages=setuptools.find_packages(), + url="https://github.com/Naudit/pystorcli2", + packages=['pystorcli'], scripts=['bin/pystorcli-metrics'], - classifiers=( - "Programming Language :: Python :: 3", - 'Intended Audience :: Developers', - 'Intended Audience :: Information Technology', - 'Intended Audience :: System Administrators', - 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', - 'Natural Language :: English', - 'Operating System :: POSIX', - 'Topic :: System :: Hardware :: Hardware Drivers', - 'Topic :: System :: Installation/Setup', - 'Topic :: Software Development :: Libraries :: Python Modules', - 'Programming Language :: Python', - ), -) \ No newline at end of file + classifiers=CLASSIFIERS, + install_requires=REQUIREMENTS, +)