Skip to content

Commit 5a6858f

Browse files
authored
Merge pull request #180 from bnavigator/setuptools_scm
Use setuptools_scm instead of custom version determination code
2 parents e162b5f + c785268 commit 5a6858f

File tree

9 files changed

+65
-230
lines changed

9 files changed

+65
-230
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if (CMAKE_VERSION VERSION_GREATER "3.11.99")
66
cmake_policy(SET CMP0074 NEW)
77
endif()
88

9-
project(slycot VERSION ${SLYCOT_VERSION} LANGUAGES NONE)
9+
project(slycot LANGUAGES NONE)
1010

1111
enable_language(C)
1212
enable_language(Fortran)
@@ -22,6 +22,5 @@ message(STATUS "NumPy included from: ${NumPy_INCLUDE_DIR}")
2222
message(STATUS "F2PY included from: ${F2PY_INCLUDE_DIR}")
2323
message(STATUS "LAPACK: ${LAPACK_LIBRARIES}")
2424
message(STATUS "BLAS: ${BLAS_LIBRARIES}")
25-
message(STATUS "Slycot version: ${SLYCOT_VERSION}")
2625

2726
add_subdirectory(slycot)

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ include conda-recipe/*
99
include slycot/CMakeLists.txt
1010
include slycot/tests/CMakeLists.txt
1111
include slycot/*.py
12-
include slycot/version.py.in
1312
include slycot/src/*.f
1413
include slycot/tests/*.py
1514
graft slycot/src/SLICOT-Reference

conda-recipe/meta.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ requirements:
2727
- libcblas * *netlib
2828
- liblapack * *netlib
2929
- python
30-
- numpy!=1.23.0
30+
- numpy !=1.23.0
3131
- pip
3232
- scikit-build >=0.14.1
33+
- setuptools >=45
34+
- setuptools_scm >=6.3
3335

3436
run:
3537
- python {{ PY_VER }}

pyproject.toml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,54 @@
11
[build-system]
22
requires = [
3-
"setuptools",
3+
"setuptools>=45",
4+
"setuptools_scm>=6.3",
45
"wheel",
56
"scikit-build>=0.14.1",
67
"cmake",
78
"numpy!=1.23.0"]
89
build-backend = "setuptools.build_meta"
10+
11+
[project]
12+
name = "slycot"
13+
description = "A wrapper for the SLICOT control and systems library"
14+
readme = "README.rst"
15+
authors = [{ name = "Enrico Avventi et al." }]
16+
maintainers = [{ name = "Slycot developers", email = "[email protected]"}]
17+
license = {text = "GPL-2.0 AND BSD-3-Clause"}
18+
classifiers = [
19+
"Development Status :: 4 - Beta",
20+
"Intended Audience :: Science/Research",
21+
"Intended Audience :: Developers",
22+
"License :: OSI Approved",
23+
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
24+
"License :: OSI Approved :: BSD License",
25+
"Programming Language :: C",
26+
"Programming Language :: Fortran",
27+
"Programming Language :: Python",
28+
"Programming Language :: Python :: 3.7",
29+
"Programming Language :: Python :: 3.8",
30+
"Programming Language :: Python :: 3.9",
31+
"Programming Language :: Python :: 3.10",
32+
"Topic :: Software Development",
33+
"Topic :: Scientific/Engineering",
34+
"Operating System :: Microsoft :: Windows",
35+
"Operating System :: POSIX",
36+
"Operating System :: Unix",
37+
"Operating System :: MacOS",
38+
]
39+
requires-python = ">=3.7"
40+
dependencies = [
41+
"numpy",
42+
]
43+
dynamic = ["version"]
44+
45+
[project.urls]
46+
homepage = "https://github.com/python-control/Slycot"
47+
48+
49+
[tool.setuptools_scm]
50+
write_to = "slycot/version.py"
51+
52+
[tool.pytest.ini_options]
53+
# run the tests with compiled and installed package
54+
addopts = "--pyargs slycot"

setup.cfg.in

Lines changed: 0 additions & 10 deletions
This file was deleted.

setup.py

Lines changed: 12 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -8,111 +8,18 @@
88

99
import builtins
1010
import os
11-
import sys
1211
import subprocess
13-
import re
14-
import platform
15-
try:
16-
import configparser
17-
except ImportError:
18-
import ConfigParser as configparser
1912

2013
try:
2114
from skbuild import setup
2215
from skbuild.command.sdist import sdist
2316
except ImportError:
2417
raise ImportError('scikit-build must be installed before running setup.py')
2518

26-
DOCLINES = __doc__.split("\n")
27-
28-
CLASSIFIERS = """\
29-
Development Status :: 4 - Beta
30-
Intended Audience :: Science/Research
31-
Intended Audience :: Developers
32-
License :: OSI Approved
33-
License :: OSI Approved :: GNU General Public License v2 (GPLv2)
34-
Programming Language :: C
35-
Programming Language :: Fortran
36-
Programming Language :: Python
37-
Programming Language :: Python :: 3.7
38-
Programming Language :: Python :: 3.8
39-
Programming Language :: Python :: 3.9
40-
Programming Language :: Python :: 3.10
41-
Topic :: Software Development
42-
Topic :: Scientific/Engineering
43-
Operating System :: Microsoft :: Windows
44-
Operating System :: POSIX
45-
Operating System :: Unix
46-
Operating System :: MacOS
47-
"""
48-
49-
# defaults
50-
ISRELEASED = True
51-
# assume a version set by conda, next update with git,
52-
# otherwise count on default
53-
VERSION = 'Unknown'
54-
55-
56-
class GitError(RuntimeError):
57-
"""Exception for git errors occuring in in git_version"""
58-
pass
59-
60-
61-
def git_version(srcdir=None):
62-
"""Return the git version, revision and cycle
63-
64-
Uses rev-parse to get the revision tag to get the version number from the
65-
latest tag and detects (approximate) revision cycles
66-
67-
"""
68-
def _minimal_ext_cmd(cmd, srcdir):
69-
# construct minimal environment
70-
env = {}
71-
for k in ['SYSTEMROOT', 'PATH']:
72-
v = os.environ.get(k)
73-
if v is not None:
74-
env[k] = v
75-
# LANGUAGE is used on win32
76-
env['LANGUAGE'] = 'C'
77-
env['LANG'] = 'C'
78-
env['LC_ALL'] = 'C'
79-
proc = subprocess.Popen(
80-
cmd,
81-
cwd=srcdir,
82-
stdout=subprocess.PIPE,
83-
stderr=subprocess.PIPE,
84-
env=env)
85-
out, err = proc.communicate()
86-
if proc.returncode:
87-
errmsg = err.decode('ascii', errors='ignore').strip()
88-
raise GitError("git err; return code %d, error message:\n '%s'"
89-
% (proc.returncode, errmsg))
90-
return out
91-
92-
try:
93-
GIT_VERSION = VERSION
94-
GIT_REVISION = 'Unknown'
95-
GIT_CYCLE = 0
96-
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'], srcdir)
97-
GIT_REVISION = out.strip().decode('ascii')
98-
out = _minimal_ext_cmd(['git', 'tag'], srcdir)
99-
GIT_VERSION = out.strip().decode('ascii').split('\n')[-1][1:]
100-
out = _minimal_ext_cmd(['git', 'describe', '--tags',
101-
'--long', '--always'], srcdir)
102-
try:
103-
# don't get a good description with shallow clones
104-
GIT_CYCLE = out.strip().decode('ascii').split('-')[1]
105-
except IndexError:
106-
pass
107-
except OSError:
108-
pass
109-
110-
return GIT_VERSION, GIT_REVISION, GIT_CYCLE
111-
112-
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
113-
# update it when the contents of directories change.
114-
if os.path.exists('MANIFEST'):
115-
os.remove('MANIFEST')
19+
try:
20+
from setuptools_scm import get_version
21+
except ImportError:
22+
raise ImportError('setuptools_scm must be installed before running setup.py')
11623

11724
# This is a bit hackish: we are setting a global variable so that the main
11825
# slycot __init__ can detect if it is being loaded by the setup routine, to
@@ -121,69 +28,6 @@ def _minimal_ext_cmd(cmd, srcdir):
12128
builtins.__SLYCOT_SETUP__ = True
12229

12330

124-
def rewrite_setup_cfg(version, gitrevision, release):
125-
toreplace = dict(locals())
126-
data = ''.join(open('setup.cfg.in', 'r').readlines()).split('@')
127-
for k, v in toreplace.items():
128-
idx = data.index(k)
129-
data[idx] = v
130-
cfg = open('setup.cfg', 'w')
131-
cfg.write(''.join(data))
132-
cfg.close()
133-
134-
135-
def get_version_info(srcdir=None):
136-
global ISRELEASED
137-
GIT_CYCLE = 0
138-
139-
# Adding the git rev number needs to be done inside write_version_py(),
140-
# otherwise the import of slycot.version messes up
141-
# the build under Python 3.
142-
if os.environ.get('CONDA_BUILD', False):
143-
FULLVERSION = os.environ.get('PKG_VERSION', '???')
144-
GIT_REVISION = os.environ.get('GIT_DESCRIBE_HASH', '')
145-
ISRELEASED = True
146-
rewrite_setup_cfg(FULLVERSION, GIT_REVISION, 'yes')
147-
elif os.path.exists('.git'):
148-
FULLVERSION, GIT_REVISION, GIT_CYCLE = git_version(srcdir)
149-
ISRELEASED = (GIT_CYCLE == 0)
150-
rewrite_setup_cfg(FULLVERSION, GIT_REVISION,
151-
(ISRELEASED and 'yes') or 'no')
152-
elif os.path.exists('setup.cfg'):
153-
# valid distribution
154-
setupcfg = configparser.ConfigParser(allow_no_value=True)
155-
setupcfg.read('setup.cfg')
156-
157-
FULLVERSION = setupcfg.get(section='metadata', option='version')
158-
159-
if FULLVERSION is None:
160-
FULLVERSION = "Unknown"
161-
162-
GIT_REVISION = setupcfg.get(section='metadata', option='gitrevision')
163-
164-
if GIT_REVISION is None:
165-
GIT_REVISION = ""
166-
167-
return FULLVERSION, GIT_REVISION
168-
else:
169-
170-
# try to find a version number from the dir name
171-
dname = os.getcwd().split(os.sep)[-1]
172-
173-
m = re.search(r'[0-9.]+', dname)
174-
if m:
175-
FULLVERSION = m.group()
176-
GIT_REVISION = ''
177-
178-
else:
179-
FULLVERSION = VERSION
180-
GIT_REVISION = "Unknown"
181-
182-
if not ISRELEASED:
183-
FULLVERSION += '.' + str(GIT_CYCLE)
184-
185-
return FULLVERSION, GIT_REVISION
186-
18731
def check_submodules():
18832
""" verify that the submodules are checked out and clean
18933
use `git submodule update --init`; on failure
@@ -212,43 +56,11 @@ def run(self):
21256
check_submodules()
21357
sdist.run(self)
21458

215-
def setup_package():
216-
src_path = os.path.dirname(os.path.abspath(__file__))
217-
sys.path.insert(0, src_path)
218-
219-
# Rewrite the version file everytime
220-
VERSION, gitrevision = get_version_info(src_path)
221-
222-
metadata = dict(
223-
name='slycot',
224-
packages=['slycot', 'slycot.tests'],
225-
cmake_languages=('C', 'Fortran'),
226-
version=VERSION,
227-
maintainer="Slycot developers",
228-
maintainer_email="[email protected]",
229-
description=DOCLINES[0],
230-
long_description=open('README.rst').read(),
231-
url='https://github.com/python-control/Slycot',
232-
author='Enrico Avventi et al.',
233-
license='GPL-2.0',
234-
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
235-
platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
236-
cmdclass={"sdist": sdist_checked},
237-
cmake_args=['-DSLYCOT_VERSION:STRING=' + VERSION,
238-
'-DGIT_REVISION:STRING=' + gitrevision,
239-
'-DISRELEASE:STRING=' + str(ISRELEASED),
240-
'-DFULL_VERSION=' + VERSION + '.git' + gitrevision[:7]],
241-
zip_safe=False,
242-
install_requires=['numpy'],
243-
python_requires=">=3.7"
244-
)
245-
246-
try:
247-
setup(**metadata)
248-
finally:
249-
del sys.path[0]
250-
return
251-
252-
253-
if __name__ == '__main__':
254-
setup_package()
59+
# These need to stay in setup.py
60+
# https://scikit-build.readthedocs.io/en/latest/usage.html#setuptools-options
61+
setup(
62+
packages=['slycot', 'slycot.tests'],
63+
cmdclass={'sdist': sdist_checked},
64+
cmake_languages=('C', 'Fortran'),
65+
use_scm_version = True,
66+
)

slycot/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,11 @@ set(F2PYSOURCE_DEPS
630630
src/transform.pyf src/synthesis.pyf
631631
src/_helper.pyf)
632632

633-
configure_file(version.py.in version.py @ONLY)
634-
635633
set(PYSOURCE
636634

637635
__init__.py examples.py exceptions.py
638636
analysis.py math.py synthesis.py transform.py
639-
${CMAKE_CURRENT_BINARY_DIR}/version.py)
637+
)
640638

641639
set(SLYCOT_MODULE "_wrapper")
642640

slycot/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
from .transform import tf01md, tf01rd
4646
from .transform import td04ad, tb01pd
4747

48-
# Version information
49-
from .version import version as __version__
48+
from .version import __version__
5049

5150

5251
def test():

slycot/version.py.in

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)