Skip to content

Commit 4eb75c7

Browse files
authored
Merge pull request #424 from effigies/fix/wrapper-version
FIX: Patch version for smriprep-docker
2 parents e682dc7 + 2ba6c42 commit 4eb75c7

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

wrapper/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools", "setuptools_scm"]
3+
build-backend = "setuptools.build_meta"

wrapper/setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[metadata]
2-
version = attr: smriprep_docker.__version__
32
url = https://github.com/nipreps/smriprep
43
author = The NiPreps developers
54
author_email = [email protected]

wrapper/setup.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
1-
#!/usr/bin/env python
21
import sys
2+
33
from setuptools import setup
4+
from setuptools.command.build_py import build_py
5+
from setuptools.command.sdist import sdist
6+
from setuptools_scm import get_version
47

58
# Give setuptools a hint to complain if it's too old a version
69
# 30.3.0 allows us to put most metadata in setup.cfg
710
# Should match pyproject.toml
811
# Not going to help us much without numpy or new pip, but gives us a shot
9-
SETUP_REQUIRES = ["setuptools >= 30.3.0"]
12+
SETUP_REQUIRES = ['setuptools >= 30.3.0']
1013
# This enables setuptools to install wheel on-the-fly
11-
SETUP_REQUIRES += ["wheel"] if "bdist_wheel" in sys.argv else []
14+
SETUP_REQUIRES += ['wheel'] if 'bdist_wheel' in sys.argv else []
15+
16+
try:
17+
VERSION = get_version(root='..', relative_to=__file__)
18+
except LookupError: # PY27 will not be able to build with a correct version, probably
19+
# Note that `python setup.py *` will work, but `pip install` generally won't
20+
VERSION = '99.99.99'
21+
22+
23+
def update_version(target_file, version):
24+
with open(target_file) as fp:
25+
contents = fp.read()
26+
updated = contents.replace('__version__ = "99.99.99"', '__version__ = "%s"' % version)
27+
with open(target_file, 'w') as fp:
28+
fp.write(updated)
29+
30+
31+
class PatchVersionSdist(sdist):
32+
def make_release_tree(self, base_dir, files):
33+
sdist.make_release_tree(self, base_dir, files)
34+
target_file = base_dir + '/smriprep_docker.py'
35+
update_version(target_file, VERSION)
36+
37+
38+
class PatchVersionBuild(build_py):
39+
def run(self):
40+
build_py.run(self)
41+
target_file = self.build_lib + '/smriprep_docker.py'
42+
update_version(target_file, VERSION)
1243

1344

14-
if __name__ == "__main__":
15-
setup(name="smriprep-docker", setup_requires=SETUP_REQUIRES)
45+
if __name__ == '__main__':
46+
setup(
47+
name='smriprep-docker',
48+
version=VERSION,
49+
setup_requires=SETUP_REQUIRES,
50+
cmdclass={
51+
'build_py': PatchVersionBuild,
52+
'sdist': PatchVersionSdist,
53+
},
54+
)

0 commit comments

Comments
 (0)