1
1
''' Test package information in various install settings
2
+
3
+ The routines here install the package in various settings and print out the
4
+ corresponding version info from the installation.
5
+
6
+ The typical use for this module is as a makefile target, as in::
7
+
8
+ # Print out info for possible install methods
9
+ check-version-info:
10
+ python -c 'from nisext.testers import info_from_here; info_from_here("mypackage")'
11
+
2
12
'''
3
13
4
14
import os
@@ -32,7 +42,7 @@ def sys_print_info(mod_name, pkg_path):
32
42
shutil .rmtree (tmpdir )
33
43
34
44
35
- def zip_extract_all (fname ):
45
+ def zip_extract_all (fname , path = None ):
36
46
''' Extract all members from zipfile
37
47
38
48
Deals with situation where the directory is stored in the zipfile as a name,
@@ -42,7 +52,61 @@ def zip_extract_all(fname):
42
52
members = zf .namelist ()
43
53
# Remove members that are just bare directories
44
54
members = [m for m in members if not m .endswith ('/' )]
45
- zf .extractall (members = members )
55
+ for zipinfo in members :
56
+ zf .extract (zipinfo , path , None )
57
+
58
+
59
+ def install_from_to (from_dir , to_dir , py_lib_sdir ):
60
+ """ Install package in `from_dir` to standard location in `to_dir`
61
+
62
+ Return path to directory containing package directory. The package directory
63
+ is the directory containing __init__.py
64
+ """
65
+ site_pkgs_path = os .path .join (to_dir , py_lib_sdir )
66
+ py_lib_locs = ' --install-purelib=%s --install-platlib=%s' % (
67
+ site_pkgs_path , site_pkgs_path )
68
+ pwd = os .path .abspath (os .getcwd ())
69
+ try :
70
+ os .chdir (from_dir )
71
+ my_call ('python setup.py --quiet install --prefix=%s %s' % (to_dir ,
72
+ py_lib_locs ))
73
+ finally :
74
+ os .chdir (pwd )
75
+ return site_pkgs_path
76
+
77
+
78
+ def check_installed_files (repo_mod_path , install_mod_path ):
79
+ """ Check files in `repo_mod_path` are installed at `install_mod_path`
80
+
81
+ At the moment, all this does is check that all the ``*.py`` files in
82
+ `repo_mod_path` are installed at `install_mod_path`.
83
+
84
+ Parameters
85
+ ----------
86
+ repo_mod_path : str
87
+ repository path containing package files, e.g. <nibabel-repo>/nibabel>
88
+ install_mod_path : str
89
+ path at which package has been installed. This is the path where the
90
+ root package ``__init__.py`` lives.
91
+
92
+ Return
93
+ ------
94
+ uninstalled : list
95
+ list of files that should have been installed, but have not been
96
+ installed
97
+ """
98
+ repo_mod_path = os .path .abspath (repo_mod_path )
99
+ uninstalled = []
100
+ # Walk directory tree to get py files
101
+ for dirpath , dirnames , filenames in os .walk (repo_mod_path ):
102
+ out_dirpath = dirpath .replace (repo_mod_path , install_mod_path )
103
+ for fname in filenames :
104
+ if not fname .lower ().endswith ('.py' ):
105
+ continue
106
+ equiv_fname = os .path .join (out_dirpath , fname )
107
+ if not os .path .isfile (equiv_fname ):
108
+ uninstalled .append (pjoin (dirpath , fname ))
109
+ return uninstalled
46
110
47
111
48
112
def contexts_print_info (mod_name , repo_path , install_path ):
@@ -54,7 +118,8 @@ def contexts_print_info(mod_name, repo_path, install_path):
54
118
* with setup.py install from repository directory
55
119
* just running code from repository directory
56
120
57
- and prints out result of get_info in each case
121
+ and prints out result of get_info in each case. There will be many files
122
+ written into `install_path` that you may want to clean up somehow.
58
123
59
124
Parameters
60
125
----------
@@ -69,21 +134,29 @@ def contexts_print_info(mod_name, repo_path, install_path):
69
134
py_lib_locs = ' --install-purelib=%s --install-platlib=%s' % (
70
135
site_pkgs_path , site_pkgs_path )
71
136
# first test archive
72
- os .chdir ( repo_path )
137
+ pwd = os .path . abspath ( os . getcwd () )
73
138
out_fname = pjoin (install_path , 'test.zip' )
74
- my_call ('git archive --format zip -o %s master' % out_fname )
75
- os .chdir (install_path )
76
- zip_extract_all ('test.zip' )
77
- my_call ('python setup.py --quiet install --prefix=%s %s' % (install_path ,
78
- py_lib_locs ))
139
+ try :
140
+ os .chdir (repo_path )
141
+ my_call ('git archive --format zip -o %s HEAD' % out_fname )
142
+ finally :
143
+ os .chdir (pwd )
144
+ install_from = pjoin (install_path , mod_name )
145
+ zip_extract_all (out_fname , install_from )
146
+ site_pkgs_path = install_from_to (install_from ,
147
+ install_path ,
148
+ PY_LIB_SDIR )
79
149
sys_print_info (mod_name , site_pkgs_path )
80
- # remove installation
81
- shutil .rmtree (site_pkgs_path )
82
150
# now test install into a directory from the repository
83
- os . chdir (repo_path )
84
- my_call ( 'python setup.py --quiet install --prefix=%s %s' % ( install_path ,
85
- py_lib_locs ) )
151
+ site_pkgs_path = install_from_to (repo_path ,
152
+ install_path ,
153
+ PY_LIB_SDIR )
86
154
sys_print_info (mod_name , site_pkgs_path )
155
+ # Take the opportunity to audit the py files
156
+ repo_mod_path = os .path .join (repo_path , mod_name )
157
+ install_mod_path = os .path .join (site_pkgs_path , mod_name )
158
+ print 'Files not taken across by the installation:'
159
+ print check_installed_files (repo_mod_path , install_mod_path )
87
160
# test from development tree
88
161
sys_print_info (mod_name , repo_path )
89
162
return
@@ -106,3 +179,5 @@ def info_from_here(mod_name):
106
179
contexts_print_info (mod_name , repo_path , install_path )
107
180
finally :
108
181
shutil .rmtree (install_path )
182
+
183
+
0 commit comments