8000 Add --python-executable and --no-infer-executable flags by emmatyping · Pull Request #4692 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Add --python-executable and --no-infer-executable flags #4692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Split inference out of process_options
  • Loading branch information
emmatyping committed Mar 7, 2018
commit 53ff42c936fa47dd6db6cd200ce4a0eea022df8e
49 changes: 28 additions & 21 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,33 @@ def _python_executable_from_version(python_version: Tuple[int, int]) -> str:
' perhaps try --python-executable, or --no-site-packages?'.format(python_version))


def infer_python_version_and_executable(options: Options,
special_opts: argparse.Namespace
) -> Options:
# Infer Python version and/or executable if one is not given
if special_opts.python_executable is not None and special_opts.python_version is not None:
py_exe_ver = _python_version_from_executable(special_opts.python_executable)
if py_exe_ver != special_opts.python_version:
raise PythonExecutableInferenceError(
'Python version {} did not match executable {}, got version {}.'.format(
special_opts.python_version, special_opts.python_executable, py_exe_ver
))
else:
options.python_version = special_opts.python_version
options.python_executable = special_opts.python_executable
elif special_opts.python_executable is None and special_opts.python_version is not None:
options.python_version = special_opts.python_version
py_exe = None
if not special_opts.no_site_packages:
py_exe = _python_executable_from_version(special_opts.python_version)
options.python_executable = py_exe
elif special_opts.python_version is None and special_opts.python_executable is not None:
options.python_version = _python_version_from_executable(
special_opts.python_executable)
options.python_executable = special_opts.python_executable
return options


def process_options(args: List[str],
require_targets: bool = True,
server_options: bool = False,
Expand Down Expand Up @@ -530,27 +557,7 @@ def add_invertible_flag(flag: str,
"is now mypy's default and only parser.")

try:
7900 # Infer Python version and/or executable if one is not given
if special_opts.python_executable is not None and special_opts.python_version is not None:
py_exe_ver = _python_version_from_executable(special_opts.python_executable)
if py_exe_ver != special_opts.python_version:
parser.error(
'Python version {} did not match executable {}, got version {}.'.format(
special_opts.python_version, special_opts.python_executable, py_exe_ver
))
else:
options.python_version = special_opts.python_version
options.python_executable = special_opts.python_executable
elif special_opts.python_executable is None and special_opts.python_version is not None:
options.python_version = special_opts.python_version
py_exe = None
if not special_opts.no_site_packages:
py_exe = _python_executable_from_version(special_opts.python_version)
options.python_executable = py_exe
elif special_opts.python_version is None and special_opts.python_executable is not None:
options.python_version = _python_version_from_executable(
special_opts.python_executable)
options.python_executable = special_opts.python_executable
options = infer_python_version_and_executable(options, special_opts)
except PythonExecutableInferenceError as e:
parser.error(str(e))

Expand Down
0