1
1
''' Test package information in various install settings
2
2
3
- The routines here install the package in various settings and print out the
4
- corresponding version info from the installation.
3
+ The routines here install the package from source directories, zips or eggs, and
4
+ check these installations by running tests, checking version information,
5
+ looking for files that were not copied over.
5
6
6
- The typical use for this module is as a makefile target, as in::
7
+ The typical use for this module is as a Makefile target. For example, here are
8
+ the Makefile targets from nibabel::
9
+
10
+ # Check for files not installed
11
+ check-files:
12
+ $(PYTHON) -c 'from nisext.testers import check_files; check_files("nibabel")'
7
13
8
14
# Print out info for possible install methods
9
15
check-version-info:
10
- python -c 'from nisext.testers import info_from_here; info_from_here("mypackage")'
16
+ $(PYTHON) -c 'from nisext.testers import info_from_here; info_from_here("nibabel")'
17
+
18
+ # Run tests from installed code
19
+ installed-tests:
20
+ $(PYTHON) -c 'from nisext.testers import tests_installed; tests_installed("nibabel")'
21
+
22
+ # Run tests from installed code
23
+ sdist-tests:
24
+ $(PYTHON) -c 'from nisext.testers import sdist_tests; sdist_tests("nibabel")'
25
+
26
+ # Run tests from binary egg
27
+ bdist-egg-tests:
28
+ $(PYTHON) -c 'from nisext.testers import bdist_egg_tests; bdist_egg_tests("nibabel")'
11
29
12
30
'''
13
31
@@ -66,7 +84,7 @@ def zip_extract_all(fname, path=None):
66
84
zf .extract (zipinfo , path , None )
67
85
68
86
69
- def install_from_to (from_dir , to_dir , py_lib_sdir , bin_sdir = 'bin' ):
87
+ def install_from_to (from_dir , to_dir , py_lib_sdir = PY_LIB_SDIR , bin_sdir = 'bin' ):
70
88
""" Install package in `from_dir` to standard location in `to_dir`
71
89
72
90
Parameters
@@ -76,7 +94,7 @@ def install_from_to(from_dir, to_dir, py_lib_sdir, bin_sdir='bin'):
76
94
to_dir : str
77
95
prefix path to which files will be installed, as in ``python setup.py
78
96
install --prefix=to_dir``
79
- py_lib_sdir : str
97
+ py_lib_sdir : str, optional
80
98
subdirectory within `to_dir` to which library code will be installed
81
99
bin_sdir : str, optional
82
100
subdirectory within `to_dir` to which scripts will be installed
@@ -93,67 +111,30 @@ def install_from_to(from_dir, to_dir, py_lib_sdir, bin_sdir='bin'):
93
111
os .chdir (pwd )
94
112
95
113
96
- def check_installed_files (repo_mod_path , install_mod_path ):
97
- """ Check files in `repo_mod_path` are installed at `install_mod_path`
98
-
99
- At the moment, all this does is check that all the ``*.py`` files in
100
- `repo_mod_path` are installed at `install_mod_path`.
101
-
102
- Parameters
103
- ----------
104
- repo_mod_path : str
105
- repository path containing package files, e.g. <nibabel-repo>/nibabel>
106
- install_mod_path : str
107
- path at which package has been installed. This is the path where the
108
- root package ``__init__.py`` lives.
109
-
110
- Return
111
- ------
112
- uninstalled : list
113
- list of files that should have been installed, but have not been
114
- installed
115
- """
116
- return missing_from (repo_mod_path , install_mod_path , filter = r"\.py$" )
117
-
118
-
119
- def missing_from (path0 , path1 , filter = None ):
120
- """ Return filenames present in `path0` but not in `path1`
114
+ def install_from_zip (zip_fname , install_path , pkg_finder = None ,
115
+ py_lib_sdir = PY_LIB_SDIR ,
116
+ script_sdir = 'bin' ):
117
+ """ Install package from zip file `zip_fname`
121
118
122
119
Parameters
123
120
----------
124
- path0 : str
125
- path which contains all files of interest
126
- path1 : str
127
- path which should contain all files of interest
128
- filter : None or str or regexp, optional
129
- A successful result from ``filter.search(fname)`` means the file is of
130
- interest. None means all files are of interest
131
-
132
- Returns
133
- -------
134
- path1_missing : list
135
- list of all files missing from `path1` that are in `path0` at the same
136
- relative path.
121
+ zip_fname : str
122
+ filename of zip file containing package code
123
+ install_path : str
124
+ output prefix at which to install package
125
+ pkg_finder : None or callable, optional
126
+ If None, assume zip contains ``setup.py`` at the top level. Otherwise,
127
+ find directory containing ``setup.py`` with ``pth =
128
+ pkg_finder(unzip_path)`` where ``unzip_path`` is the path to which we
129
+ have unzipped the zip file contents.
130
+ py_lib_sdir : str, optional
131
+ subdirectory to which to write the library code from the package. Thus
132
+ if package called ``nibabel``, the written code will be in
133
+ ``<install_path>/<py_lib_sdir>/nibabel
134
+ script_sdir : str, optional
135
+ subdirectory to which we write the installed scripts. Thus scripts will
136
+ be written to ``<install_path>/<script_sdir>
137
137
"""
138
- if not filter is None :
139
- filter = re .compile (filter )
140
- repo_mod_path = os .path .abspath (path0 )
141
- uninstalled = []
142
- # Walk directory tree to get py files
143
- for dirpath , dirnames , filenames in os .walk (path0 ):
144
- out_dirpath = dirpath .replace (path0 , path1 )
145
- for fname in filenames :
146
- if not filter is None and filter .search (fname ) is None :
147
- continue
148
- equiv_fname = os .path .join (out_dirpath , fname )
149
- if not os .path .isfile (equiv_fname ):
150
- uninstalled .append (pjoin (dirpath , fname ))
151
- return uninstalled
152
-
153
-
154
- def install_from_zip (zip_fname , install_path , pkg_finder = None ,
155
- py_lib_sdir = PY_LIB_SDIR ,
156
- script_sdir = 'bin' ):
157
138
unzip_path = tempfile .mkdtemp ()
158
139
try :
159
140
# Zip may unpack module into current directory
@@ -251,6 +232,63 @@ def tests_installed(mod_name, source_path=None):
251
232
tests_installed .__test__ = False
252
233
253
234
235
+ def check_installed_files (repo_mod_path , install_mod_path ):
236
+ """ Check files in `repo_mod_path` are installed at `install_mod_path`
237
+
238
+ At the moment, all this does is check that all the ``*.py`` files in
239
+ `repo_mod_path` are installed at `install_mod_path`.
240
+
241
+ Parameters
242
+ ----------
243
+ repo_mod_path : str
244
+ repository path containing package files, e.g. <nibabel-repo>/nibabel>
245
+ install_mod_path : str
246
+ path at which package has been installed. This is the path where the
247
+ root package ``__init__.py`` lives.
248
+
249
+ Return
250
+ ------
251
+ uninstalled : list
252
+ list of files that should have been installed, but have not been
253
+ installed
254
+ """
255
+ return missing_from (repo_mod_path , install_mod_path , filter = r"\.py$" )
256
+
257
+
258
+ def missing_from (path0 , path1 , filter = None ):
259
+ """ Return filenames present in `path0` but not in `path1`
260
+
261
+ Parameters
262
+ ----------
263
+ path0 : str
264
+ path which contains all files of interest
265
+ path1 : str
266
+ path which should contain all files of interest
267
+ filter : None or str or regexp, optional
268
+ A successful result from ``filter.search(fname)`` means the file is of
269
+ interest. None means all files are of interest
270
+
271
+ Returns
272
+ -------
273
+ path1_missing : list
274
+ list of all files missing from `path1` that are in `path0` at the same
275
+ relative path.
276
+ """
277
+ if not filter is None :
278
+ filter = re .compile (filter )
279
+ uninstalled = []
280
+ # Walk directory tree to get py files
281
+ for dirpath , dirnames , filenames in os .walk (path0 ):
282
+ out_dirpath = dirpath .replace (path0 , path1 )
283
+ for fname in filenames :
284
+ if not filter is None and filter .search (fname ) is None :
285
+ continue
286
+ equiv_fname = os .path .join (out_dirpath , fname )
287
+ if not os .path .isfile (equiv_fname ):
288
+ uninstalled .append (pjoin (dirpath , fname ))
289
+ return uninstalled
290
+
291
+
254
292
def check_files (mod_name , repo_path = None , scripts_sdir = 'bin' ):
255
293
""" Print library and script files not picked up during install
256
294
"""
@@ -278,8 +316,9 @@ def check_files(mod_name, repo_path=None, scripts_sdir='bin'):
278
316
print "Missed script files: " , ', ' .join (script_misses )
279
317
280
318
281
-
282
319
def get_sdist_finder (mod_name ):
320
+ """ Return function finding sdist source directory for `mod_name`
321
+ """
283
322
def pf (pth ):
284
323
pkg_dirs = glob (pjoin (pth , mod_name + '-*' ))
285
324
if len (pkg_dirs ) != 1 :
@@ -327,6 +366,34 @@ def bdist_egg_tests(mod_name, repo_path=None):
327
366
328
367
329
368
def make_dist (repo_path , out_dir , setup_params , zipglob ):
369
+ """ Create distutils distribution file
370
+
371
+ Parameters
372
+ ----------
373
+ repo_path : str
374
+ path to repository containing code and ``setup.py``
375
+ out_dir : str
376
+ path to which to write new distribution file
377
+ setup_params: str
378
+ parameters to pass to ``setup.py`` to create distribution.
379
+ zipglob : str
380
+ glob identifying expected output file.
381
+
382
+ Returns
383
+ -------
384
+ out_fname : str
385
+ filename of generated distribution file
386
+
387
+ Examples
388
+ --------
389
+ Make, return a zipped sdist::
390
+
391
+ make_dist('/path/to/repo', '/tmp/path', 'sdist --formats=zip', '*.zip')
392
+
393
+ Make, return a binary egg::
394
+
395
+ make_dist('/path/to/repo', '/tmp/path', 'bdist_egg', '*.egg')
396
+ """
330
397
pwd = os .path .abspath (os .getcwd ())
331
398
try :
332
399
os .chdir (repo_path )
@@ -335,8 +402,8 @@ def make_dist(repo_path, out_dir, setup_params, zipglob):
335
402
zips = glob (pjoin (out_dir , zipglob ))
336
403
if len (zips ) != 1 :
337
404
raise OSError ('There must be one and only one %s file, '
338
- 'but I found "%s"' %
339
- (zipglob , ': ' .join (zips )))
405
+ 'but I found "%s"' %
406
+ (zipglob , ': ' .join (zips )))
340
407
finally :
341
408
os .chdir (pwd )
342
409
return zips [0 ]
0 commit comments