summaryrefslogtreecommitdiff
path: root/numpy/distutils/exec_command.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/distutils/exec_command.py')
-rw-r--r--numpy/distutils/exec_command.py224
1 files changed, 112 insertions, 112 deletions
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py
index 0af60ec34..648a98efb 100644
--- a/numpy/distutils/exec_command.py
+++ b/numpy/distutils/exec_command.py
@@ -46,7 +46,7 @@ Known bugs:
"""
from __future__ import division, absolute_import, print_function
-__all__ = ['exec_command','find_executable']
+__all__ = ['exec_command', 'find_executable']
import os
import sys
@@ -65,10 +65,10 @@ def temp_file_name():
def get_pythonexe():
pythonexe = sys.executable
- if os.name in ['nt','dos']:
- fdir,fn = os.path.split(pythonexe)
- fn = fn.upper().replace('PYTHONW','PYTHON')
- pythonexe = os.path.join(fdir,fn)
+ if os.name in ['nt', 'dos']:
+ fdir, fn = os.path.split(pythonexe)
+ fn = fn.upper().replace('PYTHONW', 'PYTHON')
+ pythonexe = os.path.join(fdir, fn)
assert os.path.isfile(pythonexe), '%r is not a file' % (pythonexe,)
return pythonexe
@@ -92,7 +92,7 @@ def find_executable(exe, path=None, _cache={}):
orig_exe = exe
if path is None:
- path = os.environ.get('PATH',os.defpath)
+ path = os.environ.get('PATH', os.defpath)
if os.name=='posix':
realpath = os.path.realpath
else:
@@ -102,9 +102,9 @@ def find_executable(exe, path=None, _cache={}):
exe = exe[1:-1]
suffixes = ['']
- if os.name in ['nt','dos','os2']:
- fn,ext = os.path.splitext(exe)
- extra_suffixes = ['.exe','.com','.bat']
+ if os.name in ['nt', 'dos', 'os2']:
+ fn, ext = os.path.splitext(exe)
+ extra_suffixes = ['.exe', '.com', '.bat']
if ext.lower() not in extra_suffixes:
suffixes = extra_suffixes
@@ -138,7 +138,7 @@ def _preserve_environment( names ):
def _update_environment( **env ):
log.debug('_update_environment(...)')
- for name,value in env.items():
+ for name, value in env.items():
os.environ[name] = value or ''
def _supports_fileno(stream):
@@ -248,11 +248,11 @@ def _exec_command_posix( command,
if use_tee == 2:
filter = r'| tr -cd "\n" | tr "\n" "."; echo'
command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\
- % (command_str,stsfile,tmpfile,filter)
+ % (command_str, stsfile, tmpfile, filter)
else:
stsfile = temp_file_name()
command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\
- % (command_str,stsfile,tmpfile)
+ % (command_str, stsfile, tmpfile)
#command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)
log.debug('Running os.system(%r)' % (command_posix))
@@ -265,13 +265,13 @@ def _exec_command_posix( command,
return _exec_command(command, use_shell=use_shell, **env)
if stsfile is not None:
- f = open_latin1(stsfile,'r')
+ f = open_latin1(stsfile, 'r')
status_text = f.read()
status = int(status_text)
f.close()
os.remove(stsfile)
- f = open_latin1(tmpfile,'r')
+ f = open_latin1(tmpfile, 'r')
text = f.read()
f.close()
os.remove(tmpfile)
@@ -291,7 +291,7 @@ def _exec_command_python(command,
stsfile = temp_file_name()
outfile = temp_file_name()
- f = open(cmdfile,'w')
+ f = open(cmdfile, 'w')
f.write('import os\n')
f.write('import sys\n')
f.write('sys.path.insert(0,%r)\n' % (exec_command_dir))
@@ -310,12 +310,12 @@ def _exec_command_python(command,
raise RuntimeError("%r failed" % (cmd,))
os.remove(cmdfile)
- f = open_latin1(stsfile,'r')
+ f = open_latin1(stsfile, 'r')
status = int(f.read())
f.close()
os.remove(stsfile)
- f = open_latin1(outfile,'r')
+ f = open_latin1(outfile, 'r')
text = f.read()
f.close()
os.remove(outfile)
@@ -338,11 +338,11 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):
if use_shell:
# We use shell (unless use_shell==0) so that wildcards can be
# used.
- sh = os.environ.get('SHELL','/bin/sh')
+ sh = os.environ.get('SHELL', '/bin/sh')
if is_sequence(command):
- argv = [sh,'-c',' '.join(list(command))]
+ argv = [sh, '-c', ' '.join(list(command))]
else:
- argv = [sh,'-c',command]
+ argv = [sh, '-c', command]
else:
# On NT, DOS we avoid using command.com as it's exit status is
# not related to the exit status of a command.
@@ -351,16 +351,16 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):
else:
argv = shlex.split(command)
- if hasattr(os,'spawnvpe'):
+ if hasattr(os, 'spawnvpe'):
spawn_command = os.spawnvpe
else:
spawn_command = os.spawnve
argv[0] = find_executable(argv[0]) or argv[0]
if not os.path.isfile(argv[0]):
log.warn('Executable %s does not exist' % (argv[0]))
- if os.name in ['nt','dos']:
+ if os.name in ['nt', 'dos']:
# argv[0] might be internal command
- argv = [os.environ['COMSPEC'],'/C'] + argv
+ argv = [os.environ['COMSPEC'], '/C'] + argv
using_command = 1
_so_has_fileno = _supports_fileno(sys.stdout)
@@ -375,13 +375,13 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):
se_dup = os.dup(se_fileno)
outfile = temp_file_name()
- fout = open(outfile,'w')
+ fout = open(outfile, 'w')
if using_command:
errfile = temp_file_name()
- ferr = open(errfile,'w')
+ ferr = open(errfile, 'w')
log.debug('Running %s(%s,%r,%r,os.environ)' \
- % (spawn_command.__name__,os.P_WAIT,argv[0],argv))
+ % (spawn_command.__name__, os.P_WAIT, argv[0], argv))
argv0 = argv[0]
if not using_command:
@@ -390,38 +390,38 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):
so_flush()
se_flush()
if _so_has_fileno:
- os.dup2(fout.fileno(),so_fileno)
+ os.dup2(fout.fileno(), so_fileno)
if _se_has_fileno:
if using_command:
#XXX: disabled for now as it does not work from cmd under win32.
# Tests fail on msys
- os.dup2(ferr.fileno(),se_fileno)
+ os.dup2(ferr.fileno(), se_fileno)
else:
- os.dup2(fout.fileno(),se_fileno)
+ os.dup2(fout.fileno(), se_fileno)
try:
- status = spawn_command(os.P_WAIT,argv0,argv,os.environ)
+ status = spawn_command(os.P_WAIT, argv0, argv, os.environ)
except OSError:
errmess = str(get_exception())
status = 999
- sys.stderr.write('%s: %s'%(errmess,argv[0]))
+ sys.stderr.write('%s: %s'%(errmess, argv[0]))
so_flush()
se_flush()
if _so_has_fileno:
- os.dup2(so_dup,so_fileno)
+ os.dup2(so_dup, so_fileno)
if _se_has_fileno:
- os.dup2(se_dup,se_fileno)
+ os.dup2(se_dup, se_fileno)
fout.close()
- fout = open_latin1(outfile,'r')
+ fout = open_latin1(outfile, 'r')
text = fout.read()
fout.close()
os.remove(outfile)
if using_command:
ferr.close()
- ferr = open_latin1(errfile,'r')
+ ferr = open_latin1(errfile, 'r')
errmess = ferr.read()
ferr.close()
os.remove(errfile)
@@ -453,120 +453,120 @@ def test_nt(**kws):
if using_cygwin_echo:
log.warn('Using cygwin echo in win32 environment is not supported')
- s,o=exec_command(pythonexe\
+ s, o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'AAA\',\'\')"')
- assert s==0 and o=='',(s,o)
+ assert s==0 and o=='', (s, o)
- s,o=exec_command(pythonexe\
+ s, o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'AAA\')"',
AAA='Tere')
- assert s==0 and o=='Tere',(s,o)
+ assert s==0 and o=='Tere', (s, o)
os.environ['BBB'] = 'Hi'
- s,o=exec_command(pythonexe\
+ s, o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'BBB\',\'\')"')
- assert s==0 and o=='Hi',(s,o)
+ assert s==0 and o=='Hi', (s, o)
- s,o=exec_command(pythonexe\
+ s, o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'BBB\',\'\')"',
BBB='Hey')
- assert s==0 and o=='Hey',(s,o)
+ assert s==0 and o=='Hey', (s, o)
- s,o=exec_command(pythonexe\
+ s, o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'BBB\',\'\')"')
- assert s==0 and o=='Hi',(s,o)
+ assert s==0 and o=='Hi', (s, o)
elif 0:
- s,o=exec_command('echo Hello')
- assert s==0 and o=='Hello',(s,o)
+ s, o=exec_command('echo Hello')
+ assert s==0 and o=='Hello', (s, o)
- s,o=exec_command('echo a%AAA%')
- assert s==0 and o=='a',(s,o)
+ s, o=exec_command('echo a%AAA%')
+ assert s==0 and o=='a', (s, o)
- s,o=exec_command('echo a%AAA%',AAA='Tere')
- assert s==0 and o=='aTere',(s,o)
+ s, o=exec_command('echo a%AAA%', AAA='Tere')
+ assert s==0 and o=='aTere', (s, o)
os.environ['BBB'] = 'Hi'
- s,o=exec_command('echo a%BBB%')
- assert s==0 and o=='aHi',(s,o)
+ s, o=exec_command('echo a%BBB%')
+ assert s==0 and o=='aHi', (s, o)
- s,o=exec_command('echo a%BBB%',BBB='Hey')
- assert s==0 and o=='aHey', (s,o)
- s,o=exec_command('echo a%BBB%')
- assert s==0 and o=='aHi',(s,o)
+ s, o=exec_command('echo a%BBB%', BBB='Hey')
+ assert s==0 and o=='aHey', (s, o)
+ s, o=exec_command('echo a%BBB%')
+ assert s==0 and o=='aHi', (s, o)
- s,o=exec_command('this_is_not_a_command')
- assert s and o!='',(s,o)
+ s, o=exec_command('this_is_not_a_command')
+ assert s and o!='', (s, o)
- s,o=exec_command('type not_existing_file')
- assert s and o!='',(s,o)
+ s, o=exec_command('type not_existing_file')
+ assert s and o!='', (s, o)
- s,o=exec_command('echo path=%path%')
- assert s==0 and o!='',(s,o)
+ s, o=exec_command('echo path=%path%')
+ assert s==0 and o!='', (s, o)
- s,o=exec_command('%s -c "import sys;sys.stderr.write(sys.platform)"' \
+ s, o=exec_command('%s -c "import sys;sys.stderr.write(sys.platform)"' \
% pythonexe)
- assert s==0 and o=='win32',(s,o)
+ assert s==0 and o=='win32', (s, o)
- s,o=exec_command('%s -c "raise \'Ignore me.\'"' % pythonexe)
- assert s==1 and o,(s,o)
+ s, o=exec_command('%s -c "raise \'Ignore me.\'"' % pythonexe)
+ assert s==1 and o, (s, o)
- s,o=exec_command('%s -c "import sys;sys.stderr.write(\'0\');sys.stderr.write(\'1\');sys.stderr.write(\'2\')"'\
+ s, o=exec_command('%s -c "import sys;sys.stderr.write(\'0\');sys.stderr.write(\'1\');sys.stderr.write(\'2\')"'\
% pythonexe)
- assert s==0 and o=='012',(s,o)
+ assert s==0 and o=='012', (s, o)
- s,o=exec_command('%s -c "import sys;sys.exit(15)"' % pythonexe)
- assert s==15 and o=='',(s,o)
+ s, o=exec_command('%s -c "import sys;sys.exit(15)"' % pythonexe)
+ assert s==15 and o=='', (s, o)
- s,o=exec_command('%s -c "print \'Heipa\'"' % pythonexe)
- assert s==0 and o=='Heipa',(s,o)
+ s, o=exec_command('%s -c "print \'Heipa\'"' % pythonexe)
+ assert s==0 and o=='Heipa', (s, o)
print ('ok')
def test_posix(**kws):
- s,o=exec_command("echo Hello",**kws)
- assert s==0 and o=='Hello',(s,o)
+ s, o=exec_command("echo Hello",**kws)
+ assert s==0 and o=='Hello', (s, o)
- s,o=exec_command('echo $AAA',**kws)
- assert s==0 and o=='',(s,o)
+ s, o=exec_command('echo $AAA',**kws)
+ assert s==0 and o=='', (s, o)
- s,o=exec_command('echo "$AAA"',AAA='Tere',**kws)
- assert s==0 and o=='Tere',(s,o)
+ s, o=exec_command('echo "$AAA"',AAA='Tere',**kws)
+ assert s==0 and o=='Tere', (s, o)
- s,o=exec_command('echo "$AAA"',**kws)
- assert s==0 and o=='',(s,o)
+ s, o=exec_command('echo "$AAA"',**kws)
+ assert s==0 and o=='', (s, o)
os.environ['BBB'] = 'Hi'
- s,o=exec_command('echo "$BBB"',**kws)
- assert s==0 and o=='Hi',(s,o)
+ s, o=exec_command('echo "$BBB"',**kws)
+ assert s==0 and o=='Hi', (s, o)
- s,o=exec_command('echo "$BBB"',BBB='Hey',**kws)
- assert s==0 and o=='Hey',(s,o)
+ s, o=exec_command('echo "$BBB"',BBB='Hey',**kws)
+ assert s==0 and o=='Hey', (s, o)
- s,o=exec_command('echo "$BBB"',**kws)
- assert s==0 and o=='Hi',(s,o)
+ s, o=exec_command('echo "$BBB"',**kws)
+ assert s==0 and o=='Hi', (s, o)
- s,o=exec_command('this_is_not_a_command',**kws)
- assert s!=0 and o!='',(s,o)
+ s, o=exec_command('this_is_not_a_command',**kws)
+ assert s!=0 and o!='', (s, o)
- s,o=exec_command('echo path=$PATH',**kws)
- assert s==0 and o!='',(s,o)
+ s, o=exec_command('echo path=$PATH',**kws)
+ assert s==0 and o!='', (s, o)
- s,o=exec_command('python -c "import sys,os;sys.stderr.write(os.name)"',**kws)
- assert s==0 and o=='posix',(s,o)
+ s, o=exec_command('python -c "import sys,os;sys.stderr.write(os.name)"',**kws)
+ assert s==0 and o=='posix', (s, o)
- s,o=exec_command('python -c "raise \'Ignore me.\'"',**kws)
- assert s==1 and o,(s,o)
+ s, o=exec_command('python -c "raise \'Ignore me.\'"',**kws)
+ assert s==1 and o, (s, o)
- s,o=exec_command('python -c "import sys;sys.stderr.write(\'0\');sys.stderr.write(\'1\');sys.stderr.write(\'2\')"',**kws)
- assert s==0 and o=='012',(s,o)
+ s, o=exec_command('python -c "import sys;sys.stderr.write(\'0\');sys.stderr.write(\'1\');sys.stderr.write(\'2\')"',**kws)
+ assert s==0 and o=='012', (s, o)
- s,o=exec_command('python -c "import sys;sys.exit(15)"',**kws)
- assert s==15 and o=='',(s,o)
+ s, o=exec_command('python -c "import sys;sys.exit(15)"',**kws)
+ assert s==15 and o=='', (s, o)
- s,o=exec_command('python -c "print \'Heipa\'"',**kws)
- assert s==0 and o=='Heipa',(s,o)
+ s, o=exec_command('python -c "print \'Heipa\'"',**kws)
+ assert s==0 and o=='Heipa', (s, o)
print ('ok')
@@ -575,33 +575,33 @@ def test_execute_in(**kws):
tmpfile = temp_file_name()
fn = os.path.basename(tmpfile)
tmpdir = os.path.dirname(tmpfile)
- f = open(tmpfile,'w')
+ f = open(tmpfile, 'w')
f.write('Hello')
f.close()
- s,o = exec_command('%s -c "print \'Ignore the following IOError:\','\
- 'open(%r,\'r\')"' % (pythonexe,fn),**kws)
- assert s and o!='',(s,o)
- s,o = exec_command('%s -c "print open(%r,\'r\').read()"' % (pythonexe,fn),
+ s, o = exec_command('%s -c "print \'Ignore the following IOError:\','\
+ 'open(%r,\'r\')"' % (pythonexe, fn),**kws)
+ assert s and o!='', (s, o)
+ s, o = exec_command('%s -c "print open(%r,\'r\').read()"' % (pythonexe, fn),
execute_in = tmpdir,**kws)
- assert s==0 and o=='Hello',(s,o)
+ assert s==0 and o=='Hello', (s, o)
os.remove(tmpfile)
print ('ok')
def test_svn(**kws):
- s,o = exec_command(['svn','status'],**kws)
- assert s,(s,o)
+ s, o = exec_command(['svn', 'status'],**kws)
+ assert s, (s, o)
print ('svn ok')
def test_cl(**kws):
if os.name=='nt':
- s,o = exec_command(['cl','/V'],**kws)
- assert s,(s,o)
+ s, o = exec_command(['cl', '/V'],**kws)
+ assert s, (s, o)
print ('cl ok')
if os.name=='posix':
test = test_posix
-elif os.name in ['nt','dos']:
+elif os.name in ['nt', 'dos']:
test = test_nt
else:
raise NotImplementedError('exec_command tests for ', os.name)