1
1
#!/usr/bin/env python3
2
2
import subprocess
3
3
from subprocess import Popen
4
- from os import system
5
- from sys import argv , exit , platform , executable , version_info
6
-
7
-
8
- # Use the Python provided to execute the script, or fall back to a sane default
9
- if version_info >= (3 , 5 , 0 ):
10
- python_name = executable
11
- else :
12
- if platform == 'win32' :
13
- python_name = 'py -3'
14
- else :
15
- python_name = 'python3'
4
+ from sys import argv , exit , executable
16
5
17
6
# Slow test suites
18
7
CMDLINE = 'PythonCmdline'
55
44
# time to run.
56
45
cmds = {
57
46
# Self type check
58
- 'self' : python_name + ' -m mypy --config-file mypy_self_check.ini -p mypy' ,
47
+ 'self' : [ executable , '-m' , ' mypy' , ' --config-file' , ' mypy_self_check.ini' , '-p' , ' mypy'] ,
59
48
# Lint
60
- 'lint' : 'flake8 -j0' ,
49
+ 'lint' : [ 'flake8' , ' -j0'] ,
61
50
# Fast test cases only (this is the bulk of the test suite)
62
- 'pytest-fast' : 'pytest -q -k " not (%s)" ' % ' or ' .join (ALL_NON_FAST ),
51
+ 'pytest-fast' : [ 'pytest' , '-q' , '-k' , ' not (%s)' % ' or ' .join (ALL_NON_FAST )] ,
63
52
# Test cases that invoke mypy (with small inputs)
64
- 'pytest-cmdline' : 'pytest -q -k "%s"' % ' or ' .join ([CMDLINE ,
65
- EVALUATION ,
66
- STUBGEN_CMD ,
67
- STUBGEN_PY ]),
53
+ 'pytest-cmdline' : [ 'pytest' , '-q' , '-k' , ' or ' .join ([CMDLINE ,
54
+ EVALUATION ,
55
+ STUBGEN_CMD ,
56
+ STUBGEN_PY ])] ,
68
57
# Test cases that may take seconds to run each
69
- 'pytest-slow' : 'pytest -q -k "%s"' % ' or ' .join (
58
+ 'pytest-slow' : [ 'pytest' , '-q' , '-k' , ' or ' .join (
70
59
[SAMPLES ,
71
60
TYPESHED ,
72
61
PEP561 ,
73
62
DAEMON ,
74
63
MYPYC_EXTERNAL ,
75
64
MYPYC_COMMAND_LINE ,
76
- ERROR_STREAM ]),
65
+ ERROR_STREAM ])] ,
77
66
# Test cases to run in typeshed CI
78
- 'typeshed-ci' : 'pytest -q -k "%s"' % ' or ' .join ([CMDLINE , EVALUATION , SAMPLES , TYPESHED ]),
67
+ 'typeshed-ci' : ['pytest' , '-q' , '-k' , ' or ' .join ([CMDLINE ,
68
+ EVALUATION ,
69
+ SAMPLES ,
70
+ TYPESHED ])],
79
71
# Mypyc tests that aren't run by default, since they are slow and rarely
80
72
# fail for commits that don't touch mypyc
81
- 'mypyc-extra' : 'pytest -q -k "%s"' % ' or ' .join (MYPYC_OPT_IN ),
73
+ 'mypyc-extra' : [ 'pytest' , '-q' , '-k' , ' or ' .join (MYPYC_OPT_IN )] ,
82
74
}
83
75
84
76
# Stop run immediately if these commands fail
@@ -93,10 +85,10 @@ def run_cmd(name: str) -> int:
93
85
status = 0
94
86
cmd = cmds [name ]
95
87
print ('run %s: %s' % (name , cmd ))
96
- res = ( system ( cmd ) & 0x7F00 ) >> 8
97
- if res :
88
+ proc = subprocess . run ( cmd , stderr = subprocess . STDOUT )
89
+ if proc . returncode :
98
90
print ('\n FAILED: %s' % name )
99
- status = res
91
+ status = proc . returncode
100
92
if name in FAST_FAIL :
101
93
exit (status )
102
94
return status
@@ -105,7 +97,6 @@ def run_cmd(name: str) -> int:
105
97
def start_background_cmd (name : str ) -> Popen :
106
98
cmd = cmds [name ]
107
99
proc = subprocess .Popen (cmd ,
108
- shell = True ,
109
100
stderr = subprocess .STDOUT ,
110
101
stdout = subprocess .PIPE )
111
102
return proc
0 commit comments