diff --git a/.gitattributes b/.gitattributes index 7c8b7b590f..d32a3d189c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -nibabel/version.py export-subst +nibabel/COMMIT_INFO.txt export-subst diff --git a/Makefile b/Makefile index b95bdbd727..678af3bfa1 100644 --- a/Makefile +++ b/Makefile @@ -224,4 +224,10 @@ bdist_mpkg: $(PYTHON) tools/mpkg_wrapper.py setup.py install +# Print out info for possible install methods +check_version_info: + $(PYTHON) tools/test_pkg_install_info.py nibabel + + .PHONY: orig-src pylint + diff --git a/nibabel/__init__.py b/nibabel/__init__.py index 14fe6075ec..c917ad5a69 100644 --- a/nibabel/__init__.py +++ b/nibabel/__init__.py @@ -7,6 +7,8 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## +import os + from .version import __version__, long_description as __doc__ __doc__ += """ Quickstart @@ -56,4 +58,5 @@ test = Tester().test del Tester -from .info import get_pkg_info +from .info import get_pkg_info as _get_pkg_info +get_info = lambda : _get_pkg_info(os.path.dirname(__file__)) diff --git a/nibabel/info.py b/nibabel/info.py index e2978620da..2ce4d23f71 100644 --- a/nibabel/info.py +++ b/nibabel/info.py @@ -1,4 +1,5 @@ import os +import sys import subprocess from ConfigParser import ConfigParser @@ -20,7 +21,7 @@ def pkg_commit_hash(pkg_path): * A written commit hash value in ``install_hash` * git's output, if we are in a git repository - If all these fail, we raise an error + If all these fail, we return a not-found placeholder tuple Parameters ---------- @@ -54,15 +55,29 @@ def pkg_commit_hash(pkg_path): repo_commit, _ = proc.communicate() if repo_commit: return 'repository', repo_commit.strip() - raise RuntimeError('Cannot find hash information') + return '(none found)', '' def get_pkg_info(pkg_path): - ''' Return string describing the context of this package + ''' Return dict describing the context of this package - ''' - return '''Configuration for %s: - -Commit hash source: %s -Commit hash: %s''' % (pkg_path,) + pkg_commit_hash(pkg_path) + Parameters + ---------- + pkg_path : str + path containing __init__.py for package + Returns + ------- + context : dict + with named parameters of interest + ''' + src, hsh = pkg_commit_hash(pkg_path) + import numpy + return dict( + pkg_path=pkg_path, + commit_source=src, + commit_hash=hsh, + sys_version=sys.version, + sys_executable=sys.executable, + sys_platform=sys.platform, + np_version=numpy.__version__) diff --git a/setup.py b/setup.py index 89ce7cb303..48249ee05e 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ def run(self): # We write the installation commit even if it's empty cfg_parser = ConfigParser() cfg_parser.read(os.path.join('nibabel', 'COMMIT_INFO.txt')) - cfg_parser.set('commit hash', 'install', repo_commit) + cfg_parser.set('commit hash', 'install_hash', repo_commit) out_pth = pjoin(self.build_lib, 'nibabel', 'COMMIT_INFO.txt') cfg_parser.write(open(out_pth, 'wt')) @@ -81,7 +81,8 @@ def main(**extra_args): 'nibabel.tests'], package_data = {'nibabel': [pjoin('tests', 'data', '*'), - pjoin('dicom', 'tests', 'data', '*')]}, + pjoin('dicom', 'tests', 'data', '*'), + ]}, scripts = [pjoin('bin', 'parrec2nii')], cmdclass = cmdclass, **extra_args diff --git a/tools/test_pkg_install_info.py b/tools/test_pkg_install_info.py new file mode 100755 index 0000000000..82a1ea162f --- /dev/null +++ b/tools/test_pkg_install_info.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +''' Test nibabel version options + +Fairly unix specific because of use of 'tar' +''' + +import os +import sys +import shutil +import tempfile +from subprocess import call +from functools import partial + +my_call = partial(call, shell=True) + +py_lib_sdir = 'pylib' + +def test_print(mod_name, pkg_path): + os.chdir(os.path.expanduser('~')) + my_call('python -c "import sys; sys.path.insert(0,\'%s\'); ' + 'import %s; print %s.get_info()"' % (pkg_path, + mod_name, + mod_name)) + + +def run_tests(mod_name, repo_path, install_path): + site_pkgs_path = os.path.join(install_path, py_lib_sdir) + py_lib_locs = ' --install-purelib=%s --install-platlib=%s' % ( + site_pkgs_path, site_pkgs_path) + # first test archive + os.chdir(repo_path) + my_call('git archive --format tar -o %s/test.tar master' % install_path) + os.chdir(install_path) + my_call('tar xf test.tar') + my_call('python setup.py --quiet install --prefix=%s %s' % (install_path, + py_lib_locs)) + test_print(mod_name, site_pkgs_path) + + # remove installation + shutil.rmtree(site_pkgs_path) + # now test install into a directory from the repository + os.chdir(repo_path) + my_call('python setup.py --quiet install --prefix=%s %s' % (install_path, + py_lib_locs)) + test_print(mod_name, site_pkgs_path) + + # test from development tree + test_print(mod_name, repo_path) + return + + +if __name__ == '__main__': + try: + mod_name = sys.argv[1] + except IndexError: + raise OSError("Need module name") + try: + repo_path = sys.argv[2] + except IndexError: + repo_path = os.path.abspath(os.getcwd()) + if not os.path.isfile(os.path.join(repo_path, 'setup.py')): + raise OSError('Need setup.py in repo path %s' % repo_path) + if not os.path.isdir(os.path.join(repo_path, mod_name)): + raise OSError('Need package % in repo path %s' % (mod_name, repo_path)) + os.chdir(repo_path) + install_path = tempfile.mkdtemp() + try: + run_tests(mod_name, repo_path, install_path) + finally: + shutil.rmtree(install_path)