@@ -277,27 +277,31 @@ def infer_python_version_and_executable(options: Options,
277
277
This function mutates options based on special_opts to infer the correct Python version and
278
278
executable to use.
279
279
"""
280
+ # Check Options in case python_version is set in a config file, but prefer command
281
+ # line arguments.
282
+ python_version = special_opts .python_version or options .python_version
283
+
280
284
# Infer Python version and/or executable if one is not given
281
285
282
286
# TODO: (ethanhs) Look at folding these checks and the site packages subprocess calls into
283
287
# one subprocess call for speed.
284
- if special_opts .python_executable is not None and special_opts . python_version is not None :
288
+ if special_opts .python_executable is not None and python_version is not None :
285
289
py_exe_ver = _python_version_from_executable (special_opts .python_executable )
286
- if py_exe_ver != special_opts . python_version :
290
+ if py_exe_ver != python_version :
287
291
raise PythonExecutableInferenceError (
288
292
'Python version {} did not match executable {}, got version {}.' .format (
289
- special_opts . python_version , special_opts .python_executable , py_exe_ver
293
+ python_version , special_opts .python_executable , py_exe_ver
290
294
))
291
295
else :
292
- options .python_version = special_opts . python_version
296
+ options .python_version = python_version
293
297
options .python_executable = special_opts .python_executable
294
- elif special_opts .python_executable is None and special_opts . python_version is not None :
295
- options .python_version = special_opts . python_version
298
+ elif special_opts .python_executable is None and python_version is not None :
299
+ options .python_version = python_version
296
300
py_exe = None
297
301
if not special_opts .no_executable :
298
- py_exe = _python_executable_from_version (special_opts . python_version )
302
+ py_exe = _python_executable_from_version (python_version )
299
303
options .python_executable = py_exe
300
- elif special_opts . python_version is None and special_opts .python_executable is not None :
304
+ elif python_version is None and special_opts .python_executable is not None :
301
305
options .python_version = _python_version_from_executable (
302
306
special_opts .python_executable )
303
307
options .python_executable = special_opts .python_executable
@@ -454,7 +458,7 @@ def add_invertible_flag(flag: str,
454
458
help = 'Type check code assuming it will be running on Python x.y' ,
455
459
dest = 'special-opts:python_version' )
456
460
platform_group .add_argument (
457
- '-2' , '--py2' , dest = 'python_version' , action = 'store_const' ,
461
+ '-2' , '--py2' , dest = 'special-opts: python_version' , action = 'store_const' ,
458
462
const = defaults .PYTHON2_VERSION ,
459
463
help = "Use Python 2 mode (same as --python-version 2.7)" )
460
464
platform_group .add_argument (
0 commit comments