Show More
@@ -1,467 +1,446 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """IPython Test Suite Runner. |
|
3 | 3 | |
|
4 | 4 | This module provides a main entry point to a user script to test IPython |
|
5 | 5 | itself from the command line. There are two ways of running this script: |
|
6 | 6 | |
|
7 | 7 | 1. With the syntax `iptest all`. This runs our entire test suite by |
|
8 | 8 | calling this script (with different arguments) or trial recursively. This |
|
9 | 9 | causes modules and package to be tested in different processes, using nose |
|
10 | 10 | or trial where appropriate. |
|
11 | 11 | 2. With the regular nose syntax, like `iptest -vvs IPython`. In this form |
|
12 | 12 | the script simply calls nose, but with special command line flags and |
|
13 | 13 | plugins loaded. |
|
14 | 14 | |
|
15 | 15 | For now, this script requires that both nose and twisted are installed. This |
|
16 | 16 | will change in the future. |
|
17 | 17 | """ |
|
18 | 18 | |
|
19 | 19 | #----------------------------------------------------------------------------- |
|
20 | 20 | # Copyright (C) 2009 The IPython Development Team |
|
21 | 21 | # |
|
22 | 22 | # Distributed under the terms of the BSD License. The full license is in |
|
23 | 23 | # the file COPYING, distributed as part of this software. |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | # Imports |
|
28 | 28 | #----------------------------------------------------------------------------- |
|
29 | 29 | |
|
30 | 30 | # Stdlib |
|
31 | 31 | import os |
|
32 | 32 | import os.path as path |
|
33 | 33 | import signal |
|
34 | 34 | import sys |
|
35 | 35 | import subprocess |
|
36 | 36 | import tempfile |
|
37 | 37 | import time |
|
38 | 38 | import warnings |
|
39 | 39 | |
|
40 | 40 | # Note: monkeypatch! |
|
41 | 41 | # We need to monkeypatch a small problem in nose itself first, before importing |
|
42 | 42 | # it for actual use. This should get into nose upstream, but its release cycle |
|
43 | 43 | # is slow and we need it for our parametric tests to work correctly. |
|
44 | 44 | from IPython.testing import nosepatch |
|
45 | 45 | # Now, proceed to import nose itself |
|
46 | 46 | import nose.plugins.builtin |
|
47 | 47 | from nose.core import TestProgram |
|
48 | 48 | |
|
49 | 49 | # Our own imports |
|
50 | 50 | from IPython.utils.path import get_ipython_module_path |
|
51 | 51 | from IPython.utils.process import find_cmd, pycmd2argv |
|
52 | 52 | from IPython.utils.sysinfo import sys_info |
|
53 | 53 | |
|
54 | 54 | from IPython.testing import globalipapp |
|
55 | 55 | from IPython.testing.plugin.ipdoctest import IPythonDoctest |
|
56 | 56 | |
|
57 | 57 | pjoin = path.join |
|
58 | 58 | |
|
59 | 59 | |
|
60 | 60 | #----------------------------------------------------------------------------- |
|
61 | 61 | # Globals |
|
62 | 62 | #----------------------------------------------------------------------------- |
|
63 | 63 | |
|
64 | 64 | |
|
65 | 65 | #----------------------------------------------------------------------------- |
|
66 | 66 | # Warnings control |
|
67 | 67 | #----------------------------------------------------------------------------- |
|
68 | 68 | |
|
69 | 69 | # Twisted generates annoying warnings with Python 2.6, as will do other code |
|
70 | 70 | # that imports 'sets' as of today |
|
71 | 71 | warnings.filterwarnings('ignore', 'the sets module is deprecated', |
|
72 | 72 | DeprecationWarning ) |
|
73 | 73 | |
|
74 | 74 | # This one also comes from Twisted |
|
75 | 75 | warnings.filterwarnings('ignore', 'the sha module is deprecated', |
|
76 | 76 | DeprecationWarning) |
|
77 | 77 | |
|
78 | 78 | # Wx on Fedora11 spits these out |
|
79 | 79 | warnings.filterwarnings('ignore', 'wxPython/wxWidgets release number mismatch', |
|
80 | 80 | UserWarning) |
|
81 | 81 | |
|
82 | 82 | #----------------------------------------------------------------------------- |
|
83 | 83 | # Logic for skipping doctests |
|
84 | 84 | #----------------------------------------------------------------------------- |
|
85 | 85 | |
|
86 | 86 | def test_for(mod): |
|
87 | 87 | """Test to see if mod is importable.""" |
|
88 | 88 | try: |
|
89 | 89 | __import__(mod) |
|
90 | 90 | except (ImportError, RuntimeError): |
|
91 | 91 | # GTK reports Runtime error if it can't be initialized even if it's |
|
92 | 92 | # importable. |
|
93 | 93 | return False |
|
94 | 94 | else: |
|
95 | 95 | return True |
|
96 | 96 | |
|
97 | 97 | # Global dict where we can store information on what we have and what we don't |
|
98 | 98 | # have available at test run time |
|
99 | 99 | have = {} |
|
100 | 100 | |
|
101 | 101 | have['curses'] = test_for('_curses') |
|
102 | 102 | have['wx'] = test_for('wx') |
|
103 | 103 | have['wx.aui'] = test_for('wx.aui') |
|
104 | 104 | have['zope.interface'] = test_for('zope.interface') |
|
105 | 105 | have['twisted'] = test_for('twisted') |
|
106 | 106 | have['foolscap'] = test_for('foolscap') |
|
107 | have['objc'] = test_for('objc') | |
|
108 | 107 | have['pexpect'] = test_for('pexpect') |
|
109 | 108 | have['gtk'] = test_for('gtk') |
|
110 | 109 | have['gobject'] = test_for('gobject') |
|
111 | 110 | |
|
112 | 111 | #----------------------------------------------------------------------------- |
|
113 | 112 | # Functions and classes |
|
114 | 113 | #----------------------------------------------------------------------------- |
|
115 | 114 | |
|
116 | 115 | def report(): |
|
117 | 116 | """Return a string with a summary report of test-related variables.""" |
|
118 | 117 | |
|
119 | 118 | out = [ sys_info() ] |
|
120 | 119 | |
|
121 | 120 | avail = [] |
|
122 | 121 | not_avail = [] |
|
123 | 122 | |
|
124 | 123 | for k, is_avail in have.items(): |
|
125 | 124 | if is_avail: |
|
126 | 125 | avail.append(k) |
|
127 | 126 | else: |
|
128 | 127 | not_avail.append(k) |
|
129 | 128 | |
|
130 | 129 | if avail: |
|
131 | 130 | out.append('\nTools and libraries available at test time:\n') |
|
132 | 131 | avail.sort() |
|
133 | 132 | out.append(' ' + ' '.join(avail)+'\n') |
|
134 | 133 | |
|
135 | 134 | if not_avail: |
|
136 | 135 | out.append('\nTools and libraries NOT available at test time:\n') |
|
137 | 136 | not_avail.sort() |
|
138 | 137 | out.append(' ' + ' '.join(not_avail)+'\n') |
|
139 | 138 | |
|
140 | 139 | return ''.join(out) |
|
141 | 140 | |
|
142 | 141 | |
|
143 | 142 | def make_exclude(): |
|
144 | 143 | """Make patterns of modules and packages to exclude from testing. |
|
145 | 144 | |
|
146 | 145 | For the IPythonDoctest plugin, we need to exclude certain patterns that |
|
147 | 146 | cause testing problems. We should strive to minimize the number of |
|
148 | 147 | skipped modules, since this means untested code. |
|
149 | 148 | |
|
150 | 149 | These modules and packages will NOT get scanned by nose at all for tests. |
|
151 | 150 | """ |
|
152 | 151 | # Simple utility to make IPython paths more readably, we need a lot of |
|
153 | 152 | # these below |
|
154 | 153 | ipjoin = lambda *paths: pjoin('IPython', *paths) |
|
155 | 154 | |
|
156 | 155 | exclusions = [ipjoin('external'), |
|
157 | ipjoin('frontend', 'process', 'winprocess.py'), | |
|
158 | 156 | # Deprecated old Shell and iplib modules, skip to avoid |
|
159 | 157 | # warnings |
|
160 | 158 | ipjoin('Shell'), |
|
161 | 159 | ipjoin('iplib'), |
|
162 | 160 | pjoin('IPython_doctest_plugin'), |
|
163 | 161 | ipjoin('quarantine'), |
|
164 | 162 | ipjoin('deathrow'), |
|
165 | 163 | ipjoin('testing', 'attic'), |
|
166 | 164 | # This guy is probably attic material |
|
167 | 165 | ipjoin('testing', 'mkdoctests'), |
|
168 | 166 | # Testing inputhook will need a lot of thought, to figure out |
|
169 | 167 | # how to have tests that don't lock up with the gui event |
|
170 | 168 | # loops in the picture |
|
171 | 169 | ipjoin('lib', 'inputhook'), |
|
172 | 170 | # Config files aren't really importable stand-alone |
|
173 | 171 | ipjoin('config', 'default'), |
|
174 | 172 | ipjoin('config', 'profile'), |
|
175 | 173 | ] |
|
176 | 174 | |
|
177 | 175 | if not have['wx']: |
|
178 | exclusions.append(ipjoin('gui')) | |
|
179 | exclusions.append(ipjoin('frontend', 'wx')) | |
|
180 | 176 | exclusions.append(ipjoin('lib', 'inputhookwx')) |
|
181 | 177 | |
|
182 | 178 | if not have['gtk'] or not have['gobject']: |
|
183 | 179 | exclusions.append(ipjoin('lib', 'inputhookgtk')) |
|
184 | 180 | |
|
185 | if not have['wx.aui']: | |
|
186 | exclusions.append(ipjoin('gui', 'wx', 'wxIPython')) | |
|
187 | ||
|
188 | if not have['objc']: | |
|
189 | exclusions.append(ipjoin('frontend', 'cocoa')) | |
|
190 | ||
|
191 | 181 | # These have to be skipped on win32 because the use echo, rm, cd, etc. |
|
192 | 182 | # See ticket https://bugs.launchpad.net/bugs/366982 |
|
193 | 183 | if sys.platform == 'win32': |
|
194 | 184 | exclusions.append(ipjoin('testing', 'plugin', 'test_exampleip')) |
|
195 | 185 | exclusions.append(ipjoin('testing', 'plugin', 'dtexample')) |
|
196 | 186 | |
|
197 | 187 | if not have['pexpect']: |
|
198 | 188 | exclusions.extend([ipjoin('scripts', 'irunner'), |
|
199 | 189 | ipjoin('lib', 'irunner')]) |
|
200 | 190 | |
|
201 | 191 | # This is scary. We still have things in frontend and testing that |
|
202 | 192 | # are being tested by nose that use twisted. We need to rethink |
|
203 | 193 | # how we are isolating dependencies in testing. |
|
204 | 194 | if not (have['twisted'] and have['zope.interface'] and have['foolscap']): |
|
205 | 195 | exclusions.extend( |
|
206 |
[ipjoin(' |
|
|
207 | ipjoin('frontend', 'prefilterfrontend'), | |
|
208 | ipjoin('frontend', 'frontendbase'), | |
|
209 | ipjoin('frontend', 'linefrontendbase'), | |
|
210 | ipjoin('frontend', 'tests', 'test_linefrontend'), | |
|
211 | ipjoin('frontend', 'tests', 'test_frontendbase'), | |
|
212 | ipjoin('frontend', 'tests', 'test_prefilterfrontend'), | |
|
213 | ipjoin('frontend', 'tests', 'test_asyncfrontendbase'), | |
|
214 | ipjoin('testing', 'parametric'), | |
|
196 | [ipjoin('testing', 'parametric'), | |
|
215 | 197 | ipjoin('testing', 'util'), |
|
216 | 198 | ipjoin('testing', 'tests', 'test_decorators_trial'), |
|
217 | 199 | ] ) |
|
218 | 200 | |
|
219 | 201 | # This is needed for the reg-exp to match on win32 in the ipdoctest plugin. |
|
220 | 202 | if sys.platform == 'win32': |
|
221 | 203 | exclusions = [s.replace('\\','\\\\') for s in exclusions] |
|
222 | 204 | |
|
223 | 205 | return exclusions |
|
224 | 206 | |
|
225 | 207 | |
|
226 | 208 | class IPTester(object): |
|
227 | 209 | """Call that calls iptest or trial in a subprocess. |
|
228 | 210 | """ |
|
229 | 211 | #: string, name of test runner that will be called |
|
230 | 212 | runner = None |
|
231 | 213 | #: list, parameters for test runner |
|
232 | 214 | params = None |
|
233 | 215 | #: list, arguments of system call to be made to call test runner |
|
234 | 216 | call_args = None |
|
235 | 217 | #: list, process ids of subprocesses we start (for cleanup) |
|
236 | 218 | pids = None |
|
237 | 219 | |
|
238 | 220 | def __init__(self, runner='iptest', params=None): |
|
239 | 221 | """Create new test runner.""" |
|
240 | 222 | p = os.path |
|
241 | 223 | if runner == 'iptest': |
|
242 | 224 | iptest_app = get_ipython_module_path('IPython.testing.iptest') |
|
243 | 225 | self.runner = pycmd2argv(iptest_app) + sys.argv[1:] |
|
244 | 226 | elif runner == 'trial': |
|
245 | 227 | # For trial, it needs to be installed system-wide |
|
246 | 228 | self.runner = pycmd2argv(p.abspath(find_cmd('trial'))) |
|
247 | 229 | else: |
|
248 | 230 | raise Exception('Not a valid test runner: %s' % repr(runner)) |
|
249 | 231 | if params is None: |
|
250 | 232 | params = [] |
|
251 | 233 | if isinstance(params, str): |
|
252 | 234 | params = [params] |
|
253 | 235 | self.params = params |
|
254 | 236 | |
|
255 | 237 | # Assemble call |
|
256 | 238 | self.call_args = self.runner+self.params |
|
257 | 239 | |
|
258 | 240 | # Store pids of anything we start to clean up on deletion, if possible |
|
259 | 241 | # (on posix only, since win32 has no os.kill) |
|
260 | 242 | self.pids = [] |
|
261 | 243 | |
|
262 | 244 | if sys.platform == 'win32': |
|
263 | 245 | def _run_cmd(self): |
|
264 | 246 | # On Windows, use os.system instead of subprocess.call, because I |
|
265 | 247 | # was having problems with subprocess and I just don't know enough |
|
266 | 248 | # about win32 to debug this reliably. Os.system may be the 'old |
|
267 | 249 | # fashioned' way to do it, but it works just fine. If someone |
|
268 | 250 | # later can clean this up that's fine, as long as the tests run |
|
269 | 251 | # reliably in win32. |
|
270 | 252 | # What types of problems are you having. They may be related to |
|
271 | 253 | # running Python in unboffered mode. BG. |
|
272 | 254 | return os.system(' '.join(self.call_args)) |
|
273 | 255 | else: |
|
274 | 256 | def _run_cmd(self): |
|
275 | 257 | #print >> sys.stderr, '*** CMD:', ' '.join(self.call_args) # dbg |
|
276 | 258 | subp = subprocess.Popen(self.call_args) |
|
277 | 259 | self.pids.append(subp.pid) |
|
278 | 260 | # If this fails, the pid will be left in self.pids and cleaned up |
|
279 | 261 | # later, but if the wait call succeeds, then we can clear the |
|
280 | 262 | # stored pid. |
|
281 | 263 | retcode = subp.wait() |
|
282 | 264 | self.pids.pop() |
|
283 | 265 | return retcode |
|
284 | 266 | |
|
285 | 267 | def run(self): |
|
286 | 268 | """Run the stored commands""" |
|
287 | 269 | try: |
|
288 | 270 | return self._run_cmd() |
|
289 | 271 | except: |
|
290 | 272 | import traceback |
|
291 | 273 | traceback.print_exc() |
|
292 | 274 | return 1 # signal failure |
|
293 | 275 | |
|
294 | 276 | def __del__(self): |
|
295 | 277 | """Cleanup on exit by killing any leftover processes.""" |
|
296 | 278 | |
|
297 | 279 | if not hasattr(os, 'kill'): |
|
298 | 280 | return |
|
299 | 281 | |
|
300 | 282 | for pid in self.pids: |
|
301 | 283 | try: |
|
302 | 284 | print 'Cleaning stale PID:', pid |
|
303 | 285 | os.kill(pid, signal.SIGKILL) |
|
304 | 286 | except OSError: |
|
305 | 287 | # This is just a best effort, if we fail or the process was |
|
306 | 288 | # really gone, ignore it. |
|
307 | 289 | pass |
|
308 | 290 | |
|
309 | 291 | |
|
310 | 292 | def make_runners(): |
|
311 | 293 | """Define the top-level packages that need to be tested. |
|
312 | 294 | """ |
|
313 | 295 | |
|
314 | 296 | # Packages to be tested via nose, that only depend on the stdlib |
|
315 | 297 | nose_pkg_names = ['config', 'core', 'extensions', 'frontend', 'lib', |
|
316 | 298 | 'scripts', 'testing', 'utils' ] |
|
317 | 299 | # The machinery in kernel needs twisted for real testing |
|
318 | 300 | trial_pkg_names = [] |
|
319 | 301 | |
|
320 | if have['wx']: | |
|
321 | nose_pkg_names.append('gui') | |
|
322 | ||
|
323 | 302 | # And add twisted ones if conditions are met |
|
324 | 303 | if have['zope.interface'] and have['twisted'] and have['foolscap']: |
|
325 | 304 | # We only list IPython.kernel for testing using twisted.trial as |
|
326 | 305 | # nose and twisted.trial have conflicts that make the testing system |
|
327 | 306 | # unstable. |
|
328 | 307 | trial_pkg_names.append('kernel') |
|
329 | 308 | |
|
330 | 309 | # For debugging this code, only load quick stuff |
|
331 | 310 | #nose_pkg_names = ['core', 'extensions'] # dbg |
|
332 | 311 | #trial_pkg_names = [] # dbg |
|
333 | 312 | |
|
334 | 313 | # Make fully qualified package names prepending 'IPython.' to our name lists |
|
335 | 314 | nose_packages = ['IPython.%s' % m for m in nose_pkg_names ] |
|
336 | 315 | trial_packages = ['IPython.%s' % m for m in trial_pkg_names ] |
|
337 | 316 | |
|
338 | 317 | # Make runners |
|
339 | 318 | runners = [ (v, IPTester('iptest', params=v)) for v in nose_packages ] |
|
340 | 319 | runners.extend([ (v, IPTester('trial', params=v)) for v in trial_packages ]) |
|
341 | 320 | |
|
342 | 321 | return runners |
|
343 | 322 | |
|
344 | 323 | |
|
345 | 324 | def run_iptest(): |
|
346 | 325 | """Run the IPython test suite using nose. |
|
347 | 326 | |
|
348 | 327 | This function is called when this script is **not** called with the form |
|
349 | 328 | `iptest all`. It simply calls nose with appropriate command line flags |
|
350 | 329 | and accepts all of the standard nose arguments. |
|
351 | 330 | """ |
|
352 | 331 | |
|
353 | 332 | warnings.filterwarnings('ignore', |
|
354 | 333 | 'This will be removed soon. Use IPython.testing.util instead') |
|
355 | 334 | |
|
356 | 335 | argv = sys.argv + [ '--detailed-errors', # extra info in tracebacks |
|
357 | 336 | |
|
358 | 337 | # Loading ipdoctest causes problems with Twisted, but |
|
359 | 338 | # our test suite runner now separates things and runs |
|
360 | 339 | # all Twisted tests with trial. |
|
361 | 340 | '--with-ipdoctest', |
|
362 | 341 | '--ipdoctest-tests','--ipdoctest-extension=txt', |
|
363 | 342 | |
|
364 | 343 | # We add --exe because of setuptools' imbecility (it |
|
365 | 344 | # blindly does chmod +x on ALL files). Nose does the |
|
366 | 345 | # right thing and it tries to avoid executables, |
|
367 | 346 | # setuptools unfortunately forces our hand here. This |
|
368 | 347 | # has been discussed on the distutils list and the |
|
369 | 348 | # setuptools devs refuse to fix this problem! |
|
370 | 349 | '--exe', |
|
371 | 350 | ] |
|
372 | 351 | |
|
373 | 352 | if nose.__version__ >= '0.11': |
|
374 | 353 | # I don't fully understand why we need this one, but depending on what |
|
375 | 354 | # directory the test suite is run from, if we don't give it, 0 tests |
|
376 | 355 | # get run. Specifically, if the test suite is run from the source dir |
|
377 | 356 | # with an argument (like 'iptest.py IPython.core', 0 tests are run, |
|
378 | 357 | # even if the same call done in this directory works fine). It appears |
|
379 | 358 | # that if the requested package is in the current dir, nose bails early |
|
380 | 359 | # by default. Since it's otherwise harmless, leave it in by default |
|
381 | 360 | # for nose >= 0.11, though unfortunately nose 0.10 doesn't support it. |
|
382 | 361 | argv.append('--traverse-namespace') |
|
383 | 362 | |
|
384 | 363 | # Construct list of plugins, omitting the existing doctest plugin, which |
|
385 | 364 | # ours replaces (and extends). |
|
386 | 365 | plugins = [IPythonDoctest(make_exclude())] |
|
387 | 366 | for p in nose.plugins.builtin.plugins: |
|
388 | 367 | plug = p() |
|
389 | 368 | if plug.name == 'doctest': |
|
390 | 369 | continue |
|
391 | 370 | plugins.append(plug) |
|
392 | 371 | |
|
393 | 372 | # We need a global ipython running in this process |
|
394 | 373 | globalipapp.start_ipython() |
|
395 | 374 | # Now nose can run |
|
396 | 375 | TestProgram(argv=argv, plugins=plugins) |
|
397 | 376 | |
|
398 | 377 | |
|
399 | 378 | def run_iptestall(): |
|
400 | 379 | """Run the entire IPython test suite by calling nose and trial. |
|
401 | 380 | |
|
402 | 381 | This function constructs :class:`IPTester` instances for all IPython |
|
403 | 382 | modules and package and then runs each of them. This causes the modules |
|
404 | 383 | and packages of IPython to be tested each in their own subprocess using |
|
405 | 384 | nose or twisted.trial appropriately. |
|
406 | 385 | """ |
|
407 | 386 | |
|
408 | 387 | runners = make_runners() |
|
409 | 388 | |
|
410 | 389 | # Run the test runners in a temporary dir so we can nuke it when finished |
|
411 | 390 | # to clean up any junk files left over by accident. This also makes it |
|
412 | 391 | # robust against being run in non-writeable directories by mistake, as the |
|
413 | 392 | # temp dir will always be user-writeable. |
|
414 | 393 | curdir = os.getcwd() |
|
415 | 394 | testdir = tempfile.gettempdir() |
|
416 | 395 | os.chdir(testdir) |
|
417 | 396 | |
|
418 | 397 | # Run all test runners, tracking execution time |
|
419 | 398 | failed = [] |
|
420 | 399 | t_start = time.time() |
|
421 | 400 | try: |
|
422 | 401 | for (name, runner) in runners: |
|
423 | 402 | print '*'*70 |
|
424 | 403 | print 'IPython test group:',name |
|
425 | 404 | res = runner.run() |
|
426 | 405 | if res: |
|
427 | 406 | failed.append( (name, runner) ) |
|
428 | 407 | finally: |
|
429 | 408 | os.chdir(curdir) |
|
430 | 409 | t_end = time.time() |
|
431 | 410 | t_tests = t_end - t_start |
|
432 | 411 | nrunners = len(runners) |
|
433 | 412 | nfail = len(failed) |
|
434 | 413 | # summarize results |
|
435 | 414 | |
|
436 | 415 | print '*'*70 |
|
437 | 416 | print 'Test suite completed for system with the following information:' |
|
438 | 417 | print report() |
|
439 | 418 | print 'Ran %s test groups in %.3fs' % (nrunners, t_tests) |
|
440 | 419 | |
|
441 | 420 | print 'Status:' |
|
442 | 421 | if not failed: |
|
443 | 422 | print 'OK' |
|
444 | 423 | else: |
|
445 | 424 | # If anything went wrong, point out what command to rerun manually to |
|
446 | 425 | # see the actual errors and individual summary |
|
447 | 426 | print 'ERROR - %s out of %s test groups failed.' % (nfail, nrunners) |
|
448 | 427 | for name, failed_runner in failed: |
|
449 | 428 | print '-'*40 |
|
450 | 429 | print 'Runner failed:',name |
|
451 | 430 | print 'You may wish to rerun this one individually, with:' |
|
452 | 431 | print ' '.join(failed_runner.call_args) |
|
453 | 432 | |
|
454 | 433 | |
|
455 | 434 | |
|
456 | 435 | def main(): |
|
457 | 436 | for arg in sys.argv[1:]: |
|
458 | 437 | if arg.startswith('IPython'): |
|
459 | 438 | # This is in-process |
|
460 | 439 | run_iptest() |
|
461 | 440 | else: |
|
462 | 441 | # This starts subprocesses |
|
463 | 442 | run_iptestall() |
|
464 | 443 | |
|
465 | 444 | |
|
466 | 445 | if __name__ == '__main__': |
|
467 | 446 | main() |
@@ -1,320 +1,310 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """ |
|
4 | 4 | This module defines the things that are used in setup.py for building IPython |
|
5 | 5 | |
|
6 | 6 | This includes: |
|
7 | 7 | |
|
8 | 8 | * The basic arguments to setup |
|
9 | 9 | * Functions for finding things like packages, package data, etc. |
|
10 | 10 | * A function for checking dependencies. |
|
11 | 11 | """ |
|
12 | 12 | |
|
13 | 13 | __docformat__ = "restructuredtext en" |
|
14 | 14 | |
|
15 | 15 | #------------------------------------------------------------------------------- |
|
16 | 16 | # Copyright (C) 2008 The IPython Development Team |
|
17 | 17 | # |
|
18 | 18 | # Distributed under the terms of the BSD License. The full license is in |
|
19 | 19 | # the file COPYING, distributed as part of this software. |
|
20 | 20 | #------------------------------------------------------------------------------- |
|
21 | 21 | |
|
22 | 22 | #------------------------------------------------------------------------------- |
|
23 | 23 | # Imports |
|
24 | 24 | #------------------------------------------------------------------------------- |
|
25 | 25 | |
|
26 | 26 | import os, sys |
|
27 | 27 | |
|
28 | 28 | from glob import glob |
|
29 | 29 | |
|
30 | 30 | from setupext import install_data_ext |
|
31 | 31 | |
|
32 | 32 | #------------------------------------------------------------------------------- |
|
33 | 33 | # Useful globals and utility functions |
|
34 | 34 | #------------------------------------------------------------------------------- |
|
35 | 35 | |
|
36 | 36 | # A few handy globals |
|
37 | 37 | isfile = os.path.isfile |
|
38 | 38 | pjoin = os.path.join |
|
39 | 39 | |
|
40 | 40 | def oscmd(s): |
|
41 | 41 | print ">", s |
|
42 | 42 | os.system(s) |
|
43 | 43 | |
|
44 | 44 | # A little utility we'll need below, since glob() does NOT allow you to do |
|
45 | 45 | # exclusion on multiple endings! |
|
46 | 46 | def file_doesnt_endwith(test,endings): |
|
47 | 47 | """Return true if test is a file and its name does NOT end with any |
|
48 | 48 | of the strings listed in endings.""" |
|
49 | 49 | if not isfile(test): |
|
50 | 50 | return False |
|
51 | 51 | for e in endings: |
|
52 | 52 | if test.endswith(e): |
|
53 | 53 | return False |
|
54 | 54 | return True |
|
55 | 55 | |
|
56 | 56 | #--------------------------------------------------------------------------- |
|
57 | 57 | # Basic project information |
|
58 | 58 | #--------------------------------------------------------------------------- |
|
59 | 59 | |
|
60 | 60 | # release.py contains version, authors, license, url, keywords, etc. |
|
61 | 61 | execfile(pjoin('IPython','core','release.py')) |
|
62 | 62 | |
|
63 | 63 | # Create a dict with the basic information |
|
64 | 64 | # This dict is eventually passed to setup after additional keys are added. |
|
65 | 65 | setup_args = dict( |
|
66 | 66 | name = name, |
|
67 | 67 | version = version, |
|
68 | 68 | description = description, |
|
69 | 69 | long_description = long_description, |
|
70 | 70 | author = author, |
|
71 | 71 | author_email = author_email, |
|
72 | 72 | url = url, |
|
73 | 73 | download_url = download_url, |
|
74 | 74 | license = license, |
|
75 | 75 | platforms = platforms, |
|
76 | 76 | keywords = keywords, |
|
77 | 77 | cmdclass = {'install_data': install_data_ext}, |
|
78 | 78 | ) |
|
79 | 79 | |
|
80 | 80 | |
|
81 | 81 | #--------------------------------------------------------------------------- |
|
82 | 82 | # Find packages |
|
83 | 83 | #--------------------------------------------------------------------------- |
|
84 | 84 | |
|
85 | 85 | def add_package(packages,pname,config=False,tests=False,scripts=False, |
|
86 | 86 | others=None): |
|
87 | 87 | """ |
|
88 | 88 | Add a package to the list of packages, including certain subpackages. |
|
89 | 89 | """ |
|
90 | 90 | packages.append('.'.join(['IPython',pname])) |
|
91 | 91 | if config: |
|
92 | 92 | packages.append('.'.join(['IPython',pname,'config'])) |
|
93 | 93 | if tests: |
|
94 | 94 | packages.append('.'.join(['IPython',pname,'tests'])) |
|
95 | 95 | if scripts: |
|
96 | 96 | packages.append('.'.join(['IPython',pname,'scripts'])) |
|
97 | 97 | if others is not None: |
|
98 | 98 | for o in others: |
|
99 | 99 | packages.append('.'.join(['IPython',pname,o])) |
|
100 | 100 | |
|
101 | 101 | def find_packages(): |
|
102 | 102 | """ |
|
103 | 103 | Find all of IPython's packages. |
|
104 | 104 | """ |
|
105 | 105 | packages = ['IPython'] |
|
106 | 106 | add_package(packages, 'config', tests=True, others=['default','profile']) |
|
107 | 107 | add_package(packages, 'core', tests=True) |
|
108 | 108 | add_package(packages, 'deathrow', tests=True) |
|
109 | 109 | add_package(packages , 'extensions') |
|
110 | 110 | add_package(packages, 'external') |
|
111 |
add_package(packages, 'frontend' |
|
|
112 | # Don't include the cocoa frontend for now as it is not stable | |
|
113 | if sys.platform == 'darwin' and False: | |
|
114 | add_package(packages, 'frontend.cocoa', tests=True, others=['plugin']) | |
|
115 | add_package(packages, 'frontend.cocoa.examples') | |
|
116 | add_package(packages, 'frontend.cocoa.examples.IPython1Sandbox') | |
|
117 | add_package(packages, 'frontend.cocoa.examples.IPython1Sandbox.English.lproj') | |
|
118 | add_package(packages, 'frontend.process') | |
|
119 | add_package(packages, 'frontend.wx') | |
|
120 | add_package(packages, 'gui') | |
|
121 | add_package(packages, 'gui.wx') | |
|
111 | add_package(packages, 'frontend') | |
|
122 | 112 | add_package(packages, 'kernel', config=False, tests=True, scripts=True) |
|
123 | 113 | add_package(packages, 'kernel.core', config=False, tests=True) |
|
124 | 114 | add_package(packages, 'lib', tests=True) |
|
125 | 115 | add_package(packages, 'quarantine', tests=True) |
|
126 | 116 | add_package(packages, 'scripts') |
|
127 | 117 | add_package(packages, 'testing', tests=True) |
|
128 | 118 | add_package(packages, 'testing.plugin', tests=False) |
|
129 | 119 | add_package(packages, 'utils', tests=True) |
|
130 | 120 | return packages |
|
131 | 121 | |
|
132 | 122 | #--------------------------------------------------------------------------- |
|
133 | 123 | # Find package data |
|
134 | 124 | #--------------------------------------------------------------------------- |
|
135 | 125 | |
|
136 | 126 | def find_package_data(): |
|
137 | 127 | """ |
|
138 | 128 | Find IPython's package_data. |
|
139 | 129 | """ |
|
140 | 130 | # This is not enough for these things to appear in an sdist. |
|
141 | 131 | # We need to muck with the MANIFEST to get this to work |
|
142 | 132 | package_data = { |
|
143 | 133 | 'IPython.config.userconfig' : ['*'], |
|
144 | 134 | 'IPython.testing' : ['*.txt'] |
|
145 | 135 | } |
|
146 | 136 | return package_data |
|
147 | 137 | |
|
148 | 138 | |
|
149 | 139 | #--------------------------------------------------------------------------- |
|
150 | 140 | # Find data files |
|
151 | 141 | #--------------------------------------------------------------------------- |
|
152 | 142 | |
|
153 | 143 | def make_dir_struct(tag,base,out_base): |
|
154 | 144 | """Make the directory structure of all files below a starting dir. |
|
155 | 145 | |
|
156 | 146 | This is just a convenience routine to help build a nested directory |
|
157 | 147 | hierarchy because distutils is too stupid to do this by itself. |
|
158 | 148 | |
|
159 | 149 | XXX - this needs a proper docstring! |
|
160 | 150 | """ |
|
161 | 151 | |
|
162 | 152 | # we'll use these a lot below |
|
163 | 153 | lbase = len(base) |
|
164 | 154 | pathsep = os.path.sep |
|
165 | 155 | lpathsep = len(pathsep) |
|
166 | 156 | |
|
167 | 157 | out = [] |
|
168 | 158 | for (dirpath,dirnames,filenames) in os.walk(base): |
|
169 | 159 | # we need to strip out the dirpath from the base to map it to the |
|
170 | 160 | # output (installation) path. This requires possibly stripping the |
|
171 | 161 | # path separator, because otherwise pjoin will not work correctly |
|
172 | 162 | # (pjoin('foo/','/bar') returns '/bar'). |
|
173 | 163 | |
|
174 | 164 | dp_eff = dirpath[lbase:] |
|
175 | 165 | if dp_eff.startswith(pathsep): |
|
176 | 166 | dp_eff = dp_eff[lpathsep:] |
|
177 | 167 | # The output path must be anchored at the out_base marker |
|
178 | 168 | out_path = pjoin(out_base,dp_eff) |
|
179 | 169 | # Now we can generate the final filenames. Since os.walk only produces |
|
180 | 170 | # filenames, we must join back with the dirpath to get full valid file |
|
181 | 171 | # paths: |
|
182 | 172 | pfiles = [pjoin(dirpath,f) for f in filenames] |
|
183 | 173 | # Finally, generate the entry we need, which is a triple of (tag,output |
|
184 | 174 | # path, files) for use as a data_files parameter in install_data. |
|
185 | 175 | out.append((tag,out_path,pfiles)) |
|
186 | 176 | |
|
187 | 177 | return out |
|
188 | 178 | |
|
189 | 179 | |
|
190 | 180 | def find_data_files(): |
|
191 | 181 | """ |
|
192 | 182 | Find IPython's data_files. |
|
193 | 183 | |
|
194 | 184 | Most of these are docs. |
|
195 | 185 | """ |
|
196 | 186 | |
|
197 | 187 | docdirbase = pjoin('share', 'doc', 'ipython') |
|
198 | 188 | manpagebase = pjoin('share', 'man', 'man1') |
|
199 | 189 | |
|
200 | 190 | # Simple file lists can be made by hand |
|
201 | 191 | manpages = filter(isfile, glob(pjoin('docs','man','*.1.gz'))) |
|
202 | 192 | igridhelpfiles = filter(isfile, glob(pjoin('IPython','extensions','igrid_help.*'))) |
|
203 | 193 | |
|
204 | 194 | # For nested structures, use the utility above |
|
205 | 195 | example_files = make_dir_struct( |
|
206 | 196 | 'data', |
|
207 | 197 | pjoin('docs','examples'), |
|
208 | 198 | pjoin(docdirbase,'examples') |
|
209 | 199 | ) |
|
210 | 200 | manual_files = make_dir_struct( |
|
211 | 201 | 'data', |
|
212 | 202 | pjoin('docs','dist'), |
|
213 | 203 | pjoin(docdirbase,'manual') |
|
214 | 204 | ) |
|
215 | 205 | |
|
216 | 206 | # And assemble the entire output list |
|
217 | 207 | data_files = [ ('data',manpagebase, manpages), |
|
218 | 208 | ('data',pjoin(docdirbase,'extensions'),igridhelpfiles), |
|
219 | 209 | ] + manual_files + example_files |
|
220 | 210 | |
|
221 | 211 | ## import pprint # dbg |
|
222 | 212 | ## print '*'*80 |
|
223 | 213 | ## print 'data files' |
|
224 | 214 | ## pprint.pprint(data_files) |
|
225 | 215 | ## print '*'*80 |
|
226 | 216 | |
|
227 | 217 | return data_files |
|
228 | 218 | |
|
229 | 219 | |
|
230 | 220 | def make_man_update_target(manpage): |
|
231 | 221 | """Return a target_update-compliant tuple for the given manpage. |
|
232 | 222 | |
|
233 | 223 | Parameters |
|
234 | 224 | ---------- |
|
235 | 225 | manpage : string |
|
236 | 226 | Name of the manpage, must include the section number (trailing number). |
|
237 | 227 | |
|
238 | 228 | Example |
|
239 | 229 | ------- |
|
240 | 230 | |
|
241 | 231 | >>> make_man_update_target('ipython.1') #doctest: +NORMALIZE_WHITESPACE |
|
242 | 232 | ('docs/man/ipython.1.gz', |
|
243 | 233 | ['docs/man/ipython.1'], |
|
244 | 234 | 'cd docs/man && gzip -9c ipython.1 > ipython.1.gz') |
|
245 | 235 | """ |
|
246 | 236 | man_dir = pjoin('docs', 'man') |
|
247 | 237 | manpage_gz = manpage + '.gz' |
|
248 | 238 | manpath = pjoin(man_dir, manpage) |
|
249 | 239 | manpath_gz = pjoin(man_dir, manpage_gz) |
|
250 | 240 | gz_cmd = ( "cd %(man_dir)s && gzip -9c %(manpage)s > %(manpage_gz)s" % |
|
251 | 241 | locals() ) |
|
252 | 242 | return (manpath_gz, [manpath], gz_cmd) |
|
253 | 243 | |
|
254 | 244 | #--------------------------------------------------------------------------- |
|
255 | 245 | # Find scripts |
|
256 | 246 | #--------------------------------------------------------------------------- |
|
257 | 247 | |
|
258 | 248 | def find_scripts(): |
|
259 | 249 | """ |
|
260 | 250 | Find IPython's scripts. |
|
261 | 251 | """ |
|
262 | 252 | kernel_scripts = pjoin('IPython','kernel','scripts') |
|
263 | 253 | main_scripts = pjoin('IPython','scripts') |
|
264 | 254 | scripts = [pjoin(kernel_scripts, 'ipengine'), |
|
265 | 255 | pjoin(kernel_scripts, 'ipcontroller'), |
|
266 | 256 | pjoin(kernel_scripts, 'ipcluster'), |
|
267 | 257 | pjoin(main_scripts, 'ipython'), |
|
268 | 258 | pjoin(main_scripts, 'ipythonx'), |
|
269 | 259 | pjoin(main_scripts, 'ipython-wx'), |
|
270 | 260 | pjoin(main_scripts, 'pycolor'), |
|
271 | 261 | pjoin(main_scripts, 'irunner'), |
|
272 | 262 | pjoin(main_scripts, 'iptest') |
|
273 | 263 | ] |
|
274 | 264 | |
|
275 | 265 | # Script to be run by the windows binary installer after the default setup |
|
276 | 266 | # routine, to add shortcuts and similar windows-only things. Windows |
|
277 | 267 | # post-install scripts MUST reside in the scripts/ dir, otherwise distutils |
|
278 | 268 | # doesn't find them. |
|
279 | 269 | if 'bdist_wininst' in sys.argv: |
|
280 | 270 | if len(sys.argv) > 2 and ('sdist' in sys.argv or 'bdist_rpm' in sys.argv): |
|
281 | 271 | print >> sys.stderr,"ERROR: bdist_wininst must be run alone. Exiting." |
|
282 | 272 | sys.exit(1) |
|
283 | 273 | scripts.append(pjoin('scripts','ipython_win_post_install.py')) |
|
284 | 274 | |
|
285 | 275 | return scripts |
|
286 | 276 | |
|
287 | 277 | #--------------------------------------------------------------------------- |
|
288 | 278 | # Verify all dependencies |
|
289 | 279 | #--------------------------------------------------------------------------- |
|
290 | 280 | |
|
291 | 281 | def check_for_dependencies(): |
|
292 | 282 | """Check for IPython's dependencies. |
|
293 | 283 | |
|
294 | 284 | This function should NOT be called if running under setuptools! |
|
295 | 285 | """ |
|
296 | 286 | from setupext.setupext import ( |
|
297 | 287 | print_line, print_raw, print_status, print_message, |
|
298 | 288 | check_for_zopeinterface, check_for_twisted, |
|
299 | 289 | check_for_foolscap, check_for_pyopenssl, |
|
300 | 290 | check_for_sphinx, check_for_pygments, |
|
301 | 291 | check_for_nose, check_for_pexpect |
|
302 | 292 | ) |
|
303 | 293 | print_line() |
|
304 | 294 | print_raw("BUILDING IPYTHON") |
|
305 | 295 | print_status('python', sys.version) |
|
306 | 296 | print_status('platform', sys.platform) |
|
307 | 297 | if sys.platform == 'win32': |
|
308 | 298 | print_status('Windows version', sys.getwindowsversion()) |
|
309 | 299 | |
|
310 | 300 | print_raw("") |
|
311 | 301 | print_raw("OPTIONAL DEPENDENCIES") |
|
312 | 302 | |
|
313 | 303 | check_for_zopeinterface() |
|
314 | 304 | check_for_twisted() |
|
315 | 305 | check_for_foolscap() |
|
316 | 306 | check_for_pyopenssl() |
|
317 | 307 | check_for_sphinx() |
|
318 | 308 | check_for_pygments() |
|
319 | 309 | check_for_nose() |
|
320 | 310 | check_for_pexpect() |
General Comments 0
You need to be logged in to leave comments.
Login now