diff -r ac1a026edd58 -r 6fcda59daff8 src/setup.py --- a/src/setup.py Fri Nov 16 17:01:19 2018 +0100 +++ b/src/setup.py Sat Nov 24 09:31:16 2018 +0100 @@ -1,11 +1,73 @@ import os +import re +import sys +from distutils.command.install import INSTALL_SCHEMES +from distutils.command.install_data import install_data +from shutil import move +from tempfile import mkstemp + +from setuptools import Command + try: from setuptools import setup except ImportError: from distutils.core import setup -from distutils.command.install_data import install_data -from distutils.command.install import INSTALL_SCHEMES -import sys + + +""" +See: https://dankeder.com/posts/adding-custom-commands-to-setup-py/ +""" +class SetVersion(Command): + """ + Set the version for the project + """ + description = "Set the version for the project" + # command_consumes_arguments = True + user_options = [ + ('version=', 'v', 'version str') + ] + + def initialize_options(self): + """Set default values for options.""" + # Each user option must be listed here with their default value. + self.version = None + + def finalize_options(self): + """Post-process options.""" + if self.version is None: + raise Exception("Parameter --version is missing") + version_matches = re.match(r"(\d+).(\d+)(?:\.(\d+))?(?:(?:.(dev))|(?:(a|b|rc)(.*)))?", self.version) + if version_matches is None: + raise Exception("Parameter --version is not a version string (see )") + version_list = version_matches.groups() + version_tag = {'a': 'alpha', 'b': 'beta', 'rc': 'rc'}.get(version_list[4],'final') + version_ext = int(version_list[5] or 0) + if version_list[3] and version_list[3] == 'dev': + version_tag = 'alpha' + version_ext = 0 + + self.version_tuple = ( + int(version_list[0]), + int(version_list[1]), + int(version_list[2] or 0), + version_tag, + version_ext, + ) + + def run(self): + filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)),"irinotes","__init__.py") + print("Changing VERSION in %s to %r" % (filepath, self.version_tuple)) + fh, abs_path = mkstemp() + with os.fdopen(fh,'w') as temp_file: + with open(filepath, 'r') as initfiles: + for l in initfiles: + if re.match(r"\s*VERSION\s*=\s*\(\d+\s*,\s*\d+\s*,\s*\d+,\s*\".+\",\s*.+\s*\)", l): + temp_file.write("VERSION = %r" % (self.version_tuple,)) + else: + temp_file.write(l) + os.remove(filepath) + move(abs_path, filepath) + class osx_install_data(install_data): @@ -109,6 +171,8 @@ with open('README', 'r') as f: long_description = f.read() + cmdclasses = {**cmdclasses, **{ 'set_version': SetVersion }} + setup( script_name=setup_script_name, script_args=setup_script_args, @@ -140,7 +204,7 @@ "Unipath", "dj-database-url", "six", - "django-auditlog == 0.4.5dev", + "django-auditlog @ https://github.com/IRI-Research/django-auditlog/tarball/master#egg=django-auditlog-0.4.5+IRI", "django-extensions", "djangorestframework >= 3.6", "django-rest-auth[with_social]", @@ -153,9 +217,9 @@ "drf-nested-routers", "markdown" ], - dependency_links=[ - "https://github.com/IRI-Research/django-auditlog/tarball/master#egg=django-auditlog-0.4.5dev" - ] + # dependency_links=[ + # "https://github.com/IRI-Research/django-auditlog/tarball/master#egg=django-auditlog-0.4.5dev" + # ] )