Skip to content

Commit 7dab9f6

Browse files
committed
use setuptools_scm
1 parent e162b5f commit 7dab9f6

File tree

10 files changed

+27
-175
lines changed

10 files changed

+27
-175
lines changed

.coveragerc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
source = slycot
33
omit =
44
*/tests/*
5-
*/version.py
65

76

87
# please do not add any sections after this block

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,14 +27,16 @@ 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_scm >=6.3
3334

3435
run:
3536
- python {{ PY_VER }}
3637
- {{ pin_compatible('numpy') }}
3738
- libflang # [win]
39+
- importlib_metadata # [py<38]
3840

3941
test:
4042
requires:

pyproject.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
[build-system]
22
requires = [
33
"setuptools",
4+
"setuptools_scm>=6.3",
45
"wheel",
56
"scikit-build>=0.14.1",
67
"cmake",
7-
"numpy!=1.23.0"]
8+
"numpy!=1.23.0",
9+
"importlib-metadata; python_version < '3.8'"]
810
build-backend = "setuptools.build_meta"
11+
12+
[tool.setuptools_scm]
13+
14+
[tool.pytest.ini_options]
15+
# run the tests with compiled and installed package
16+
addopts = "--pyargs slycot"

setup.cfg.in

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

setup.py

Lines changed: 8 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
import subprocess
1313
import re
1414
import platform
15-
try:
16-
import configparser
17-
except ImportError:
18-
import ConfigParser as configparser
1915

2016
try:
2117
from skbuild import setup
2218
from skbuild.command.sdist import sdist
2319
except ImportError:
2420
raise ImportError('scikit-build must be installed before running setup.py')
2521

22+
try:
23+
from setuptools_scm import get_version
24+
except ImportError:
25+
raise ImportError('setuptools_scm must be installed before running setup.py')
26+
2627
DOCLINES = __doc__.split("\n")
2728

2829
CLASSIFIERS = """\
@@ -46,144 +47,13 @@
4647
Operating System :: MacOS
4748
"""
4849

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')
116-
11750
# This is a bit hackish: we are setting a global variable so that the main
11851
# slycot __init__ can detect if it is being loaded by the setup routine, to
11952
# avoid attempting to load components that aren't built yet. While ugly, it's
12053
# a lot more robust than what was previously being used.
12154
builtins.__SLYCOT_SETUP__ = True
12255

12356

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-
18757
def check_submodules():
18858
""" verify that the submodules are checked out and clean
18959
use `git submodule update --init`; on failure
@@ -216,14 +86,12 @@ def setup_package():
21686
src_path = os.path.dirname(os.path.abspath(__file__))
21787
sys.path.insert(0, src_path)
21888

219-
# Rewrite the version file everytime
220-
VERSION, gitrevision = get_version_info(src_path)
22189

22290
metadata = dict(
22391
name='slycot',
22492
packages=['slycot', 'slycot.tests'],
22593
cmake_languages=('C', 'Fortran'),
226-
version=VERSION,
94+
use_scm_version=True,
22795
maintainer="Slycot developers",
22896
maintainer_email="[email protected]",
22997
description=DOCLINES[0],
@@ -234,20 +102,16 @@ def setup_package():
234102
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
235103
platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
236104
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]],
241105
zip_safe=False,
242-
install_requires=['numpy'],
106+
install_requires=["numpy",
107+
"importlib-metadata; python_version < '3.8'"],
243108
python_requires=">=3.7"
244109
)
245110

246111
try:
247112
setup(**metadata)
248113
finally:
249114
del sys.path[0]
250-
return
251115

252116

253117
if __name__ == '__main__':

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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@
4545
from .transform import tf01md, tf01rd
4646
from .transform import td04ad, tb01pd
4747

48-
# Version information
49-
from .version import version as __version__
48+
try:
49+
from importlib.metadata import version
50+
except ImportError:
51+
from importlib_metadata import version
52+
__version__ = version("slycot")
5053

5154

5255
def test():

slycot/version.py.in

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

0 commit comments

Comments
 (0)