##// END OF EJS Templates
use py3compat.which in common locations
Min RK -
Show More
@@ -26,32 +26,16 b' IPython.external.decorators, we import either numpy.testing.decorators if numpy '
26 26 available, OR use equivalent code in IPython.external._decorators, which
27 27 we've copied verbatim from numpy.
28 28
29 Authors
30 -------
31
32 - Fernando Perez <Fernando.Perez@berkeley.edu>
33 29 """
34 30
35 #-----------------------------------------------------------------------------
36 # Copyright (C) 2009-2011 The IPython Development Team
37 #
38 # Distributed under the terms of the BSD License. The full license is in
39 # the file COPYING, distributed as part of this software.
40 #-----------------------------------------------------------------------------
31 # Copyright (c) IPython Development Team.
32 # Distributed under the terms of the Modified BSD License.
41 33
42 #-----------------------------------------------------------------------------
43 # Imports
44 #-----------------------------------------------------------------------------
45
46 # Stdlib imports
47 34 import sys
48 35 import os
49 36 import tempfile
50 37 import unittest
51 38
52 # Third-party imports
53
54 # This is Michele Simionato's decorator module, kept verbatim.
55 39 from decorator import decorator
56 40
57 41 # Expose the unittest-driven decorators
@@ -63,8 +47,7 b' from .ipunittest import ipdoctest, ipdocstring'
63 47 from IPython.external.decorators import *
64 48
65 49 # For onlyif_cmd_exists decorator
66 from IPython.utils.process import is_cmd_found
67 from IPython.utils.py3compat import string_types
50 from IPython.utils.py3compat import string_types, which
68 51
69 52 #-----------------------------------------------------------------------------
70 53 # Classes and functions
@@ -370,16 +353,9 b' def onlyif_cmds_exist(*commands):'
370 353 Decorator to skip test when at least one of `commands` is not found.
371 354 """
372 355 for cmd in commands:
373 try:
374 if not is_cmd_found(cmd):
375 return skip("This test runs only if command '{0}' "
376 "is installed".format(cmd))
377 except ImportError as e:
378 # is_cmd_found uses pywin32 on windows, which might not be available
379 if sys.platform == 'win32' and 'pywin32' in str(e):
380 return skip("This test runs only if pywin32 and command '{0}' "
381 "is installed".format(cmd))
382 raise e
356 if not which(cmd):
357 return skip("This test runs only if command '{0}' "
358 "is installed".format(cmd))
383 359 return null_deco
384 360
385 361 def onlyif_any_cmd_exists(*commands):
@@ -387,14 +363,7 b' def onlyif_any_cmd_exists(*commands):'
387 363 Decorator to skip test unless at least one of `commands` is found.
388 364 """
389 365 for cmd in commands:
390 try:
391 if is_cmd_found(cmd):
392 return null_deco
393 except ImportError as e:
394 # is_cmd_found uses pywin32 on windows, which might not be available
395 if sys.platform == 'win32' and 'pywin32' in str(e):
396 return skip("This test runs only if pywin32 and commands '{0}' "
397 "are installed".format(commands))
398 raise e
366 if which(cmd):
367 return null_deco
399 368 return skip("This test runs only if one of the commands {0} "
400 369 "is installed".format(commands))
@@ -3,37 +3,24 b''
3 3 Utilities for working with external processes.
4 4 """
5 5
6 #-----------------------------------------------------------------------------
7 # Copyright (C) 2008-2011 The IPython Development Team
8 #
9 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
8
16 9 from __future__ import print_function
17 10
18 # Stdlib
19 11 import os
20 12 import sys
21 13
22 # Our own
23 14 if sys.platform == 'win32':
24 from ._process_win32 import _find_cmd, system, getoutput, arg_split, check_pid
15 from ._process_win32 import system, getoutput, arg_split, check_pid
25 16 elif sys.platform == 'cli':
26 from ._process_cli import _find_cmd, system, getoutput, arg_split, check_pid
17 from ._process_cli import system, getoutput, arg_split, check_pid
27 18 else:
28 from ._process_posix import _find_cmd, system, getoutput, arg_split, check_pid
19 from ._process_posix import system, getoutput, arg_split, check_pid
29 20
30 21 from ._process_common import getoutputerror, get_output_error_code, process_handler
31 22 from . import py3compat
32 23
33 #-----------------------------------------------------------------------------
34 # Code
35 #-----------------------------------------------------------------------------
36
37 24
38 25 class FindCmdError(Exception):
39 26 pass
@@ -59,14 +46,10 b' def find_cmd(cmd):'
59 46 cmd : str
60 47 The command line program to look for.
61 48 """
62 try:
63 path = _find_cmd(cmd).rstrip()
64 except OSError:
65 raise FindCmdError('command could not be found: %s' % cmd)
66 # which returns empty if not found
67 if path == '':
49 path = py3compat.which(cmd)
50 if path is None:
68 51 raise FindCmdError('command could not be found: %s' % cmd)
69 return os.path.abspath(path)
52 return path
70 53
71 54
72 55 def is_cmd_found(cmd):
@@ -7,7 +7,7 b' import subprocess'
7 7 import os
8 8 import sys
9 9
10 from IPython.utils.process import find_cmd
10 from IPython.utils.py3compat import which
11 11 from IPython.utils.traitlets import Integer, List, Bool, Instance
12 12 from IPython.utils.tempdir import TemporaryWorkingDirectory
13 13 from .latex import LatexExporter
@@ -65,10 +65,12 b' class PDFExporter(LatexExporter):'
65 65 #We must use cp1252 encoding for calling subprocess.Popen
66 66 #Note that sys.stdin.encoding and encoding.DEFAULT_ENCODING
67 67 # could be different (cp437 in case of dos console)
68 command = [c.encode('cp1252') for c in command]
68 command = [c.encode('cp1252') for c in command]
69 69
70 70 # This will throw a clearer error if the command is not found
71 find_cmd(command_list[0])
71 cmd = which(command_list[0])
72 if cmd is None:
73 raise OSError("%s not found on PATH" % command_list[0])
72 74
73 75 times = 'time' if count == 1 else 'times'
74 76 self.log.info("Running %s %i %s: %s", command_list[0], count, times, command)
General Comments 0
You need to be logged in to leave comments. Login now