From 9dc7e7a7728c232b4834ba97df5529c850314c82 Mon Sep 17 00:00:00 2001 From: Rene van Paassen Date: Tue, 23 Apr 2019 21:21:23 +0200 Subject: [PATCH 1/3] Fix-ups for release Add Python, Fortran, and CMakeLists to MANIFEST.in for source packaging. In setup.py, generate a setup.cfg to record version information in source package. Fix git interfacing used to find out version; in the absence of git, fall back to directory name for version name. --- MANIFEST.in | 7 +++++ setup.cfg.in | 6 ++++ setup.py | 85 +++++++++++++++++++++++++++++++--------------------- 3 files changed, 64 insertions(+), 34 deletions(-) create mode 100644 setup.cfg.in diff --git a/MANIFEST.in b/MANIFEST.in index eb4698f8..6b812bc3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,3 +4,10 @@ include CREDITS include gpl-2.0.txt include README.rst include MANIFEST.in +include CMakeLists.txt +include slycot/CMakeLists.txt +include slycot/tests/CMakeLists.txt +include slycot/*.py +include slycot/version.py.in +include slycot/src/*.f +include slycot/tests/*.py diff --git a/setup.cfg.in b/setup.cfg.in new file mode 100644 index 00000000..9067d0c0 --- /dev/null +++ b/setup.cfg.in @@ -0,0 +1,6 @@ +[metadata] + +name = slycot +version = @version@ +gitrevision = @gitrevision@ +release = @release@ diff --git a/setup.py b/setup.py index 9d50bd33..e96946ce 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,10 @@ import os import sys import subprocess - +try: + import configparser +except ImportError: + import ConfigParser as configparser if sys.version_info[:2] < (2, 6) or (3, 0) <= sys.version_info[0:2] < (3, 2): raise RuntimeError("Python version 2.6, 2.7 or >= 3.2 required.") @@ -43,12 +46,16 @@ """ # defaults -ISRELEASED = False +ISRELEASED = True # assume a version set by conda, next update with git, # otherwise count on default -VERSION = '0.3.3' +VERSION = 'Unkown' -# Return the git revision as a string +# Return the git version, revision and cycle +# +# Uses rev-parse to get the revision +# tag to get the version number from the latest tag +# and detects (approximate) revision cycles def git_version(srcdir=None): def _minimal_ext_cmd(cmd, srcdir): # construct minimal environment @@ -71,12 +78,12 @@ def _minimal_ext_cmd(cmd, srcdir): try: GIT_VERSION = VERSION GIT_REVISION = 'Unknown' - CIT_CYCLE = 0 + GIT_CYCLE = 0 out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'], srcdir) GIT_REVISION = out.strip().decode('ascii') out = _minimal_ext_cmd(['git', 'tag'], srcdir) GIT_VERSION = out.strip().decode('ascii').split('\n')[-1][1:] - out = _minimal_ext_cmd(['git', 'describe', '--tags'], srcdir) + out = _minimal_ext_cmd(['git', 'describe', '--tags', '--long'], srcdir) GIT_CYCLE = out.strip().decode('ascii').split('-')[1] except OSError: pass @@ -94,49 +101,60 @@ def _minimal_ext_cmd(cmd, srcdir): # a lot more robust than what was previously being used. builtins.__SLYCOT_SETUP__ = True +def rewrite_setup_cfg(version, gitrevision, release): + toreplace = dict(locals()) + data = ''.join(open('setup.cfg.in', 'r').readlines()).split('@') + for k, v in toreplace.items(): + idx = data.index(k) + data[idx] = v + cfg = open('setup.cfg', 'w') + cfg.write(''.join(data)) + cfg.close() def get_version_info(srcdir=None): global ISRELEASED + GIT_CYCLE = 0 # Adding the git rev number needs to be done inside write_version_py(), # otherwise the import of slycot.version messes up # the build under Python 3. if os.environ.get('CONDA_BUILD', False): FULLVERSION = os.environ.get('PKG_VERSION', '???') - GIT_REVISION = '' - GIT_CYCLE = 0 + GIT_REVISION = os.environ.get('GIT_DESCRIBE_HASH', '') ISRELEASED = True + rewrite_setup_cfg(FULLVERSION, GIT_REVISION, 'yes') elif os.path.exists('.git'): - FULLVERSION, GIT_REVISION, GIT_CYCLE = git_version(srcdir) - elif os.path.exists('slycot/version.py'): - # must be a source distribution, use existing version file - try: - from slycot.version import git_revision as GIT_REVISION - except ImportError: - raise ImportError("Unable to import git_revision. Try removing " - "slycot/version.py and the build directory " - "before building.") + FULLVERSION, GIT_REVISION, GIT_CYCLE = git_version(srcdir) + ISRELEASED = (GIT_CYCLE == 0) + rewrite_setup_cfg(FULLVERSION, GIT_REVISION, + (ISRELEASED and 'yes') or 'no') + elif os.path.exists('setup.cfg'): + # valid distribution + setupcfg = configparser.ConfigParser() + setupcfg.read('setup.cfg') + FULLVERSION = setupcfg['metadata'].get('version', 'Unknown') + GIT_REVISION = setupcfg['metadata'].get('gitrevision', '') + return FULLVERSION, GIT_REVISION else: - FULLVERSION = VERSION - GIT_REVISION = "Unknown" + + # try to find a version number from the dir name + dname = os.getcwd().split(os.sep)[-1] + import re + + m = re.search(r'[0-9.]+', dname) + if m: + FULLVERSION = m.group() + GIT_REVISION = '' + + else: + FULLVERSION = VERSION + GIT_REVISION = "Unknown" if not ISRELEASED: FULLVERSION += '.' + str(GIT_CYCLE) return FULLVERSION, GIT_REVISION -def configuration(parent_package='', top_path=None): - from numpy.distutils.misc_util import Configuration - config = Configuration(None, parent_package, top_path) - config.set_options(ignore_setup_xxx_py=True, - assume_default_configuration=True, - delegate_options_to_subpackages=True, - quiet=True) - config.add_subpackage('slycot') - config.get_version('slycot/version.py') # sets config.version - return config - - def check_submodules(): """ verify that the submodules are checked out and clean use `git submodule update --init`; on failure @@ -158,8 +176,7 @@ def check_submodules(): if line.startswith('-') or line.startswith('+'): raise ValueError('Submodule not clean: %s' % line) -from distutils.command.sdist import sdist - +from skbuild.command.sdist import sdist class sdist_checked(sdist): """ check submodules on sdist to prevent incomplete tarballs """ @@ -188,7 +205,7 @@ def setup_package(): long_description="\n".join(DOCLINES[2:]), url='https://github.com/python-control/Slycot', author='Enrico Avventi et al.', - license='GPLv2', + license='GPL-2.0', classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f], platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"], cmdclass={"sdist": sdist_checked}, From f0f07c6ef2b9eca1eb682c607369983bce32710b Mon Sep 17 00:00:00 2001 From: Rory Yorke Date: Sun, 28 Apr 2019 11:46:25 +0200 Subject: [PATCH 2/3] Build: report Git errors; handle shallow clones in 'git describe' --- setup.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index e96946ce..7754dc0e 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,11 @@ ISRELEASED = True # assume a version set by conda, next update with git, # otherwise count on default -VERSION = 'Unkown' +VERSION = 'Unknown' + +class GitError(RuntimeError): + """Exception for git errors occuring in in git_version""" + pass # Return the git version, revision and cycle # @@ -68,11 +72,17 @@ def _minimal_ext_cmd(cmd, srcdir): env['LANGUAGE'] = 'C' env['LANG'] = 'C' env['LC_ALL'] = 'C' - out = subprocess.Popen( + proc = subprocess.Popen( cmd, cwd=srcdir, stdout=subprocess.PIPE, - env=env).communicate()[0] + stderr=subprocess.PIPE, + env=env) + out, err = proc.communicate() + if proc.returncode: + errmsg = err.decode('ascii',errors='ignore').strip() + raise GitError("git err; return code %d, error message:\n '%s'" + % (proc.returncode, errmsg)) return out try: @@ -83,8 +93,12 @@ def _minimal_ext_cmd(cmd, srcdir): GIT_REVISION = out.strip().decode('ascii') out = _minimal_ext_cmd(['git', 'tag'], srcdir) GIT_VERSION = out.strip().decode('ascii').split('\n')[-1][1:] - out = _minimal_ext_cmd(['git', 'describe', '--tags', '--long'], srcdir) - GIT_CYCLE = out.strip().decode('ascii').split('-')[1] + out = _minimal_ext_cmd(['git', 'describe', '--tags', '--long','--always'], srcdir) + try: + # don't get a good description with shallow clones, e.g., on Travis + GIT_CYCLE = out.strip().decode('ascii').split('-')[1] + except IndexError: + pass except OSError: pass From 894245a4b9296e2cb7bf3606649d221b99e7790f Mon Sep 17 00:00:00 2001 From: Rory Yorke Date: Wed, 1 May 2019 07:51:23 +0200 Subject: [PATCH 3/3] Include setup.cfg.in in source distribution --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index 6b812bc3..631e5327 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,6 +4,7 @@ include CREDITS include gpl-2.0.txt include README.rst include MANIFEST.in +include setup.cfg.in include CMakeLists.txt include slycot/CMakeLists.txt include slycot/tests/CMakeLists.txt