diff options
author | cookedm <cookedm@localhost> | 2007-12-26 07:08:16 +0000 |
---|---|---|
committer | cookedm <cookedm@localhost> | 2007-12-26 07:08:16 +0000 |
commit | 87f61abda82e21fc77facd3931e0182dd564c3a0 (patch) | |
tree | 2e21b844c860a76a98cf4badd0e2761051bb10f0 /numpy/distutils/exec_command.py | |
parent | 2a726d25c8404aa21bb9ab5a6f9af82b3ccf4a47 (diff) | |
download | numpy-87f61abda82e21fc77facd3931e0182dd564c3a0.tar.gz |
Replace numpy.distutils.exec_command.splitcmdline with shlex.split instead.
It has the same problems as our old numpy.distutils.ccompiler.split_quoted.
splitcmdline still exists, but uses shlex.split, and issues a DeprecationWarning
This has the positive side effect of not having numpy.distutils pulled in
when numpy is imported -- there was a use of splitcmdline in numpy.testing.
Diffstat (limited to 'numpy/distutils/exec_command.py')
-rw-r--r-- | numpy/distutils/exec_command.py | 61 |
1 files changed, 6 insertions, 55 deletions
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py index 5863f5d6e..ba2f8842b 100644 --- a/numpy/distutils/exec_command.py +++ b/numpy/distutils/exec_command.py @@ -11,7 +11,6 @@ takes keyword arguments for (re-)defining environment variables. Provides functions: exec_command --- execute command in a specified directory and in the modified environment. - splitcmdline --- inverse of ' '.join(argv) find_executable --- locate a command using info from environment variable PATH. Equivalent to posix `which` command. @@ -50,6 +49,7 @@ __all__ = ['exec_command','find_executable'] import os import sys +import shlex from numpy.distutils.misc_util import is_sequence, make_temp_file from numpy.distutils import log @@ -59,8 +59,6 @@ def temp_file_name(): fo.close() return name -############################################################ - def get_pythonexe(): pythonexe = sys.executable if os.name in ['nt','dos']: @@ -70,57 +68,11 @@ def get_pythonexe(): assert os.path.isfile(pythonexe), '%r is not a file' % (pythonexe,) return pythonexe -############################################################ - def splitcmdline(line): - """ Inverse of ' '.join(sys.argv). - """ - log.debug('splitcmdline(%r)' % (line)) - lst = [] - flag = 0 - s,pc,cc = '','','' - for nc in line+' ': - if flag==0: - flag = (pc != '\\' and \ - ((cc=='"' and 1) or (cc=="'" and 2) or \ - (cc==' ' and pc!=' ' and -2))) or flag - elif flag==1: - flag = (cc=='"' and pc!='\\' and nc==' ' and -1) or flag - elif flag==2: - flag = (cc=="'" and pc!='\\' and nc==' ' and -1) or flag - if flag!=-2: - s += cc - if flag<0: - flag = 0 - s = s.strip() - if s: - lst.append(s) - s = '' - pc,cc = cc,nc - else: - s = s.strip() - if s: - lst.append(s) - log.debug('splitcmdline -> %r' % (lst)) - return lst - -def test_splitcmdline(): - l = splitcmdline('a b cc') - assert l==['a','b','cc'], repr(l) - l = splitcmdline('a') - assert l==['a'], repr(l) - l = splitcmdline('a " b cc"') - assert l==['a','" b cc"'], repr(l) - l = splitcmdline('"a bcc" -h') - assert l==['"a bcc"','-h'], repr(l) - l = splitcmdline(r'"\"a \" bcc" -h') - assert l==[r'"\"a \" bcc"','-h'], repr(l) - l = splitcmdline(" 'a bcc' -h") - assert l==["'a bcc'",'-h'], repr(l) - l = splitcmdline(r"'\'a \' bcc' -h") - assert l==[r"'\'a \' bcc'",'-h'], repr(l) - -############################################################ + import warnings + warnings.warn('splitcmdline is deprecated; use shlex.split', + DeprecationWarning) + return shlex.split(line) def find_executable(exe, path=None, _cache={}): """Return full path of a executable or None. @@ -379,7 +331,7 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ): if is_sequence(command): argv = command[:] else: - argv = splitcmdline(command) + argv = shlex.split(command) if hasattr(os,'spawnvpe'): spawn_command = os.spawnvpe @@ -632,7 +584,6 @@ else: if __name__ == "__main__": - test_splitcmdline() test(use_tee=0) test(use_tee=1) test_execute_in(use_tee=0) |