[Numpy-svn] r4645 - in trunk/numpy: distutils distutils/command doc testing
numpy-svn at scipy.org
numpy-svn at scipy.org
Wed Dec 26 02:08:20 EST 2007
Author: cookedm
Date: 2007-12-26 01:08:16 -0600 (Wed, 26 Dec 2007)
New Revision: 4645
Modified:
trunk/numpy/distutils/command/build_src.py
trunk/numpy/distutils/exec_command.py
trunk/numpy/distutils/interactive.py
trunk/numpy/doc/DISTUTILS.txt
trunk/numpy/testing/numpytest.py
Log:
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.
Modified: trunk/numpy/distutils/command/build_src.py
===================================================================
--- trunk/numpy/distutils/command/build_src.py 2007-12-26 07:04:24 UTC (rev 4644)
+++ trunk/numpy/distutils/command/build_src.py 2007-12-26 07:08:16 UTC (rev 4645)
@@ -4,6 +4,7 @@
import os
import re
import sys
+import shlex
from distutils.command import build_ext
from distutils.dep_util import newer_group, newer
@@ -24,7 +25,6 @@
appendpath, is_string, is_sequence
from numpy.distutils.from_template import process_file as process_f_file
from numpy.distutils.conv_template import process_file as process_c_file
-from numpy.distutils.exec_command import splitcmdline
class build_src(build_ext.build_ext):
@@ -94,7 +94,7 @@
if self.f2py_opts is None:
self.f2py_opts = []
else:
- self.f2py_opts = splitcmdline(self.f2py_opts)
+ self.f2py_opts = shlex.split(self.f2py_opts)
if self.swigflags:
if self.swig_opts:
@@ -106,7 +106,7 @@
if self.swig_opts is None:
self.swig_opts = []
else:
- self.swig_opts = splitcmdline(self.swig_opts)
+ self.swig_opts = shlex.split(self.swig_opts)
# use options from build_ext command
build_ext = self.get_finalized_command('build_ext')
Modified: trunk/numpy/distutils/exec_command.py
===================================================================
--- trunk/numpy/distutils/exec_command.py 2007-12-26 07:04:24 UTC (rev 4644)
+++ trunk/numpy/distutils/exec_command.py 2007-12-26 07:08:16 UTC (rev 4645)
@@ -11,7 +11,6 @@
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 @@
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 @@
fo.close()
return name
-############################################################
-
def get_pythonexe():
pythonexe = sys.executable
if os.name in ['nt','dos']:
@@ -70,58 +68,12 @@
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
+ import warnings
+ warnings.warn('splitcmdline is deprecated; use shlex.split',
+ DeprecationWarning)
+ return shlex.split(line)
-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)
-
-############################################################
-
def find_executable(exe, path=None, _cache={}):
"""Return full path of a executable or None.
@@ -379,7 +331,7 @@
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 @@
if __name__ == "__main__":
- test_splitcmdline()
test(use_tee=0)
test(use_tee=1)
test_execute_in(use_tee=0)
Modified: trunk/numpy/distutils/interactive.py
===================================================================
--- trunk/numpy/distutils/interactive.py 2007-12-26 07:04:24 UTC (rev 4644)
+++ trunk/numpy/distutils/interactive.py 2007-12-26 07:08:16 UTC (rev 4645)
@@ -50,7 +50,7 @@
""" % (ccompiler, fcompiler, argv)
-from exec_command import splitcmdline
+import shlex
def edit_argv(*args):
argv = args[0]
@@ -62,7 +62,7 @@
except EOFError:
return
if s:
- argv[1:] = splitcmdline(s)
+ argv[1:] = shlex.split(s)
return
def interactive_sys_argv(argv):
Modified: trunk/numpy/doc/DISTUTILS.txt
===================================================================
--- trunk/numpy/doc/DISTUTILS.txt 2007-12-26 07:04:24 UTC (rev 4644)
+++ trunk/numpy/doc/DISTUTILS.txt 2007-12-26 07:08:16 UTC (rev 4645)
@@ -399,7 +399,6 @@
---------------------------------------
+ ``get_pythonexe()``
-+ ``splitcmdline(line)``
+ ``find_executable(exe, path=None)``
+ ``exec_command( command, execute_in='', use_shell=None, use_tee=None, **env )``
Modified: trunk/numpy/testing/numpytest.py
===================================================================
--- trunk/numpy/testing/numpytest.py 2007-12-26 07:04:24 UTC (rev 4644)
+++ trunk/numpy/testing/numpytest.py 2007-12-26 07:08:16 UTC (rev 4645)
@@ -4,6 +4,7 @@
import imp
import glob
import types
+import shlex
import unittest
import traceback
import warnings
@@ -16,7 +17,6 @@
DEBUG=0
from numpy.testing.utils import jiffies
-from numpy.distutils.exec_command import splitcmdline
get_frame = sys._getframe
class IgnoreException(Exception):
@@ -649,7 +649,7 @@
type='string')
(options, args) = parser.parse_args()
return self.test(options.level,options.verbosity,
- sys_argv=splitcmdline(options.sys_argv or ''),
+ sys_argv=shlex.split(options.sys_argv or ''),
testcase_pattern=options.testcase_pattern)
def warn(self, message):
More information about the Numpy-svn
mailing list