Skip to content

Commit

Permalink
BF - refactor / bugfix versioning system, add test script
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-brett committed Aug 15, 2010
1 parent ea8077d commit 719c32d
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
@@ -1 +1 @@
nibabel/version.py export-subst
nibabel/COMMIT_INFO.txt export-subst
6 changes: 6 additions & 0 deletions Makefile
Expand Up @@ -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

5 changes: 4 additions & 1 deletion nibabel/__init__.py
Expand Up @@ -7,6 +7,8 @@
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##

import os

from .version import __version__, long_description as __doc__
__doc__ += """
Quickstart
Expand Down Expand Up @@ -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__))
31 changes: 23 additions & 8 deletions nibabel/info.py
@@ -1,4 +1,5 @@
import os
import sys
import subprocess
from ConfigParser import ConfigParser

Expand All @@ -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
----------
Expand Down Expand Up @@ -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)', '<not 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__)
5 changes: 3 additions & 2 deletions setup.py
Expand Up @@ -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'))

Expand Down Expand Up @@ -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
Expand Down
70 changes: 70 additions & 0 deletions 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)

0 comments on commit 719c32d

Please sign in to comment.