|
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 | +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) |
12 | 43 |
|
13 | 44 |
|
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