diff --git a/IPython/testing/decorators.py b/IPython/testing/decorators.py index 2014c07..6a74483 100644 --- a/IPython/testing/decorators.py +++ b/IPython/testing/decorators.py @@ -26,32 +26,16 @@ IPython.external.decorators, we import either numpy.testing.decorators if numpy available, OR use equivalent code in IPython.external._decorators, which we've copied verbatim from numpy. -Authors -------- - -- Fernando Perez """ -#----------------------------------------------------------------------------- -# Copyright (C) 2009-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -# Stdlib imports import sys import os import tempfile import unittest -# Third-party imports - -# This is Michele Simionato's decorator module, kept verbatim. from decorator import decorator # Expose the unittest-driven decorators @@ -63,8 +47,7 @@ from .ipunittest import ipdoctest, ipdocstring from IPython.external.decorators import * # For onlyif_cmd_exists decorator -from IPython.utils.process import is_cmd_found -from IPython.utils.py3compat import string_types +from IPython.utils.py3compat import string_types, which #----------------------------------------------------------------------------- # Classes and functions @@ -370,16 +353,9 @@ def onlyif_cmds_exist(*commands): Decorator to skip test when at least one of `commands` is not found. """ for cmd in commands: - try: - if not is_cmd_found(cmd): - return skip("This test runs only if command '{0}' " - "is installed".format(cmd)) - except ImportError as e: - # is_cmd_found uses pywin32 on windows, which might not be available - if sys.platform == 'win32' and 'pywin32' in str(e): - return skip("This test runs only if pywin32 and command '{0}' " - "is installed".format(cmd)) - raise e + if not which(cmd): + return skip("This test runs only if command '{0}' " + "is installed".format(cmd)) return null_deco def onlyif_any_cmd_exists(*commands): @@ -387,14 +363,7 @@ def onlyif_any_cmd_exists(*commands): Decorator to skip test unless at least one of `commands` is found. """ for cmd in commands: - try: - if is_cmd_found(cmd): - return null_deco - except ImportError as e: - # is_cmd_found uses pywin32 on windows, which might not be available - if sys.platform == 'win32' and 'pywin32' in str(e): - return skip("This test runs only if pywin32 and commands '{0}' " - "are installed".format(commands)) - raise e + if which(cmd): + return null_deco return skip("This test runs only if one of the commands {0} " "is installed".format(commands)) diff --git a/IPython/utils/process.py b/IPython/utils/process.py index 64b7254..a274f43 100644 --- a/IPython/utils/process.py +++ b/IPython/utils/process.py @@ -3,37 +3,24 @@ Utilities for working with external processes. """ -#----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + from __future__ import print_function -# Stdlib import os import sys -# Our own if sys.platform == 'win32': - from ._process_win32 import _find_cmd, system, getoutput, arg_split, check_pid + from ._process_win32 import system, getoutput, arg_split, check_pid elif sys.platform == 'cli': - from ._process_cli import _find_cmd, system, getoutput, arg_split, check_pid + from ._process_cli import system, getoutput, arg_split, check_pid else: - from ._process_posix import _find_cmd, system, getoutput, arg_split, check_pid + from ._process_posix import system, getoutput, arg_split, check_pid from ._process_common import getoutputerror, get_output_error_code, process_handler from . import py3compat -#----------------------------------------------------------------------------- -# Code -#----------------------------------------------------------------------------- - class FindCmdError(Exception): pass @@ -59,14 +46,10 @@ def find_cmd(cmd): cmd : str The command line program to look for. """ - try: - path = _find_cmd(cmd).rstrip() - except OSError: - raise FindCmdError('command could not be found: %s' % cmd) - # which returns empty if not found - if path == '': + path = py3compat.which(cmd) + if path is None: raise FindCmdError('command could not be found: %s' % cmd) - return os.path.abspath(path) + return path def is_cmd_found(cmd): diff --git a/jupyter_nbconvert/exporters/pdf.py b/jupyter_nbconvert/exporters/pdf.py index 9f3e85b..4e5095c 100644 --- a/jupyter_nbconvert/exporters/pdf.py +++ b/jupyter_nbconvert/exporters/pdf.py @@ -7,7 +7,7 @@ import subprocess import os import sys -from IPython.utils.process import find_cmd +from IPython.utils.py3compat import which from IPython.utils.traitlets import Integer, List, Bool, Instance from IPython.utils.tempdir import TemporaryWorkingDirectory from .latex import LatexExporter @@ -65,10 +65,12 @@ class PDFExporter(LatexExporter): #We must use cp1252 encoding for calling subprocess.Popen #Note that sys.stdin.encoding and encoding.DEFAULT_ENCODING # could be different (cp437 in case of dos console) - command = [c.encode('cp1252') for c in command] + command = [c.encode('cp1252') for c in command] # This will throw a clearer error if the command is not found - find_cmd(command_list[0]) + cmd = which(command_list[0]) + if cmd is None: + raise OSError("%s not found on PATH" % command_list[0]) times = 'time' if count == 1 else 'times' self.log.info("Running %s %i %s: %s", command_list[0], count, times, command)