|
1 |
| -#!/usr/bin/env python |
2 | 1 | import sys
|
| 2 | + |
3 | 3 | 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 |
4 | 7 |
|
5 | 8 | # Give setuptools a hint to complain if it's too old a version
|
6 | 9 | # 30.3.0 allows us to put most metadata in setup.cfg
|
7 | 10 | # Should match pyproject.toml
|
8 | 11 | # 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'] |
10 | 13 | # 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 | + |
| 17 | +VERSION = get_version(root='..', relative_to=__file__) |
| 18 | + |
| 19 | + |
| 20 | +def update_version(target_file, version): |
| 21 | + with open(target_file) as fp: |
| 22 | + contents = fp.read() |
| 23 | + updated = contents.replace('__version__ = "99.99.99"', '__version__ = "{%s}"' % version) |
| 24 | + with open(target_file, 'w') as fp: |
| 25 | + fp.write(updated) |
| 26 | + |
| 27 | + |
| 28 | +class PatchVersionSdist(sdist): |
| 29 | + def make_release_tree(self, base_dir, files): |
| 30 | + super().make_release_tree(base_dir, files) |
| 31 | + target_file = base_dir + '/smriprep_docker.py' |
| 32 | + update_version(target_file, VERSION) |
| 33 | + |
| 34 | + |
| 35 | +class PatchVersionBuild(build_py): |
| 36 | + def run(self): |
| 37 | + super().run() |
| 38 | + target_file = self.build_lib + '/smriprep_docker.py' |
| 39 | + update_version(target_file, VERSION) |
12 | 40 |
|
13 | 41 |
|
14 |
| -if __name__ == "__main__": |
15 |
| - setup(name="smriprep-docker", setup_requires=SETUP_REQUIRES) |
| 42 | +if __name__ == '__main__': |
| 43 | + setup( |
| 44 | + name='smriprep-docker', |
| 45 | + version=VERSION, |
| 46 | + setup_requires=SETUP_REQUIRES, |
| 47 | + cmdclass={ |
| 48 | + 'build_py': PatchVersionBuild, |
| 49 | + 'sdist': PatchVersionSdist, |
| 50 | + }, |
| 51 | + ) |
0 commit comments