Skip to content

Commit f550c81

Browse files
committed
fix: install to work with pip
1 parent 07143af commit f550c81

File tree

3 files changed

+65
-16
lines changed

3 files changed

+65
-16
lines changed

nipype/info.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def get_nipype_gitversion():
122122
MICRO = _version_micro
123123
ISRELEASE = _version_extra == ''
124124
VERSION = __version__
125-
REQUIRES = ["nibabel (>=1.0)", "networkx (>=1.0)", "numpy (>=1.3)",
126-
"scipy (>=0.7)", "traits (>=4.0)"]
125+
REQUIRES = ["nibabel>=1.0", "networkx>=1.0", "numpy>=1.3",
126+
"python-dateutil>1.0", "scipy>=0.7", "traits>=4.0",
127+
"nose>=1.0"]
127128
STATUS = 'stable'

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ numpy>=1.3
22
scipy>=0.7
33
networkx>=1.0
44
traits>=4.0
5-
dateutil>=1.5
5+
python-dateutil>=1.5
66
nibabel>=1.0
77
nose>=1.0

setup.py

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,69 @@
1111

1212
import sys
1313
from glob import glob
14+
from os.path import join as pjoin
1415

15-
# Import build helpers
1616
try:
17-
from nisext.sexts import package_check, get_comrec_build
17+
from ConfigParser import ConfigParser
1818
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
2177

2278
from build_docs import cmdclass, INFO_VARS
2379

@@ -55,12 +111,6 @@ def configuration(parent_package='',top_path=None):
55111
if not 'extra_setuptools_args' in globals():
56112
extra_setuptools_args = dict()
57113

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'])
64114

65115
################################################################################
66116
# Import the documentation building classes.
@@ -91,13 +141,11 @@ def main(**extra_args):
91141
author_email=INFO_VARS['AUTHOR_EMAIL'],
92142
platforms=INFO_VARS['PLATFORMS'],
93143
version=INFO_VARS['VERSION'],
94-
requires=INFO_VARS['REQUIRES'],
144+
install_requires=INFO_VARS['REQUIRES'],
95145
configuration = configuration,
96146
cmdclass = cmdclass,
97147
scripts = glob('bin/*'),
98148
**extra_args)
99149

100-
101-
102150
if __name__ == "__main__":
103151
main(**extra_setuptools_args)

0 commit comments

Comments
 (0)