|
11 | 11 |
|
12 | 12 | import sys
|
13 | 13 | from glob import glob
|
| 14 | +from os.path import join as pjoin |
14 | 15 |
|
15 |
| -# Import build helpers |
16 | 16 | try:
|
17 |
| - from nisext.sexts import package_check, get_comrec_build |
| 17 | + from ConfigParser import ConfigParser |
18 | 18 | except ImportError:
|
19 |
| - raise RuntimeError('Need nisext package from nibabel installation' |
20 |
| - ' - please install nibabel first') |
| 19 | + from configparser import ConfigParser |
| 20 | + |
| 21 | +from distutils.command.build_py import build_py |
| 22 | + |
| 23 | +def get_comrec_build(pkg_dir, build_cmd=build_py): |
| 24 | + """ Return extended build command class for recording commit |
| 25 | +
|
| 26 | + The extended command tries to run git to find the current commit, getting |
| 27 | + the empty string if it fails. It then writes the commit hash into a file |
| 28 | + in the `pkg_dir` path, named ``COMMIT_INFO.txt``. |
| 29 | +
|
| 30 | + In due course this information can be used by the package after it is |
| 31 | + installed, to tell you what commit it was installed from if known. |
| 32 | +
|
| 33 | + To make use of this system, you need a package with a COMMIT_INFO.txt file - |
| 34 | + e.g. ``myproject/COMMIT_INFO.txt`` - that might well look like this:: |
| 35 | +
|
| 36 | + # This is an ini file that may contain information about the code state |
| 37 | + [commit hash] |
| 38 | + # The line below may contain a valid hash if it has been substituted |
| 39 | + during 'git archive' archive_subst_hash=$Format:%h$ |
| 40 | + # This line may be modified by the install process |
| 41 | + install_hash= |
| 42 | +
|
| 43 | + The COMMIT_INFO file above is also designed to be used with git substitution |
| 44 | + - so you probably also want a ``.gitattributes`` file in the root directory |
| 45 | + of your working tree that contains something like this:: |
| 46 | +
|
| 47 | + myproject/COMMIT_INFO.txt export-subst |
| 48 | +
|
| 49 | + That will cause the ``COMMIT_INFO.txt`` file to get filled in by ``git |
| 50 | + archive`` - useful in case someone makes such an archive - for example with |
| 51 | + via the github 'download source' button. |
| 52 | +
|
| 53 | + Although all the above will work as is, you might consider having something |
| 54 | + like a ``get_info()`` function in your package to display the commit |
| 55 | + information at the terminal. See the ``pkg_info.py`` module in the nipy |
| 56 | + package for an example. |
| 57 | + """ |
| 58 | + class MyBuildPy(build_cmd): |
| 59 | + ''' Subclass to write commit data into installation tree ''' |
| 60 | + def run(self): |
| 61 | + build_cmd.run(self) |
| 62 | + import subprocess |
| 63 | + proc = subprocess.Popen('git rev-parse HEAD', |
| 64 | + stdout=subprocess.PIPE, |
| 65 | + stderr=subprocess.PIPE, |
| 66 | + shell=True) |
| 67 | + repo_commit, _ = proc.communicate() |
| 68 | + # Fix for python 3 |
| 69 | + repo_commit = str(repo_commit) |
| 70 | + # We write the installation commit even if it's empty |
| 71 | + cfg_parser = ConfigParser() |
| 72 | + cfg_parser.read(pjoin(pkg_dir, 'COMMIT_INFO.txt')) |
| 73 | + cfg_parser.set('commit hash', 'install_hash', repo_commit) |
| 74 | + out_pth = pjoin(self.build_lib, pkg_dir, 'COMMIT_INFO.txt') |
| 75 | + cfg_parser.write(open(out_pth, 'wt')) |
| 76 | + return MyBuildPy |
21 | 77 |
|
22 | 78 | from build_docs import cmdclass, INFO_VARS
|
23 | 79 |
|
@@ -55,12 +111,6 @@ def configuration(parent_package='',top_path=None):
|
55 | 111 | if not 'extra_setuptools_args' in globals():
|
56 | 112 | extra_setuptools_args = dict()
|
57 | 113 |
|
58 |
| -# Hard and soft dependency checking |
59 |
| -package_check('networkx', INFO_VARS['NETWORKX_MIN_VERSION']) |
60 |
| -package_check('nibabel', INFO_VARS['NIBABEL_MIN_VERSION']) |
61 |
| -package_check('numpy', INFO_VARS['NUMPY_MIN_VERSION']) |
62 |
| -package_check('scipy', INFO_VARS['SCIPY_MIN_VERSION']) |
63 |
| -package_check('traits', INFO_VARS['TRAITS_MIN_VERSION']) |
64 | 114 |
|
65 | 115 | ################################################################################
|
66 | 116 | # Import the documentation building classes.
|
@@ -91,13 +141,11 @@ def main(**extra_args):
|
91 | 141 | author_email=INFO_VARS['AUTHOR_EMAIL'],
|
92 | 142 | platforms=INFO_VARS['PLATFORMS'],
|
93 | 143 | version=INFO_VARS['VERSION'],
|
94 |
| - requires=INFO_VARS['REQUIRES'], |
| 144 | + install_requires=INFO_VARS['REQUIRES'], |
95 | 145 | configuration = configuration,
|
96 | 146 | cmdclass = cmdclass,
|
97 | 147 | scripts = glob('bin/*'),
|
98 | 148 | **extra_args)
|
99 | 149 |
|
100 |
| - |
101 |
| - |
102 | 150 | if __name__ == "__main__":
|
103 | 151 | main(**extra_setuptools_args)
|
0 commit comments