From 4b9ec56dcbe454b5f7e09191afaac3c9dfc6f1db Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 26 Dec 2023 14:36:27 -0700 Subject: [PATCH] Incorporated PR feedback: use `{sys.executable} -m` for `run` invocations. --- conformance/src/type_checker.py | 43 ++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/conformance/src/type_checker.py b/conformance/src/type_checker.py index 43280e3e9..a6d1e76b0 100644 --- a/conformance/src/type_checker.py +++ b/conformance/src/type_checker.py @@ -7,6 +7,7 @@ from pathlib import Path import re from subprocess import PIPE, run +import sys from typing import Sequence @@ -48,10 +49,12 @@ def name(self) -> str: return "mypy" def install(self) -> None: - run("pip install mypy --upgrade", shell=True) + run(f"{sys.executable} -m pip install mypy --upgrade", shell=True) def get_version(self) -> str: - proc = run("mypy --version", stdout=PIPE, text=True, shell=True) + proc = run( + f"{sys.executable} -m mypy --version", stdout=PIPE, text=True, shell=True + ) version = proc.stdout.strip() # Remove the " (compiled)" if it's present. @@ -59,7 +62,7 @@ def get_version(self) -> str: return version def run_tests(self, test_files: Sequence[str]) -> dict[str, str]: - command = "mypy . --disable-error-code empty-body" + command = f"{sys.executable} -m mypy . --disable-error-code empty-body" proc = run(command, stdout=PIPE, text=True, shell=True) lines = proc.stdout.split("\n") @@ -79,18 +82,20 @@ def name(self) -> str: def install(self) -> None: # Install the Python wrapper if it's not installed. - run("pip install pyright --upgrade", shell=True) + run(f"{sys.executable} -m pip install pyright --upgrade", shell=True) # Force the Python wrapper to install node if needed # and download the latest version of pyright. self.get_version() def get_version(self) -> str: - proc = run("pyright --version", stdout=PIPE, text=True, shell=True) + proc = run( + f"{sys.executable} -m pyright --version", stdout=PIPE, text=True, shell=True + ) return proc.stdout.strip() def run_tests(self, test_files: Sequence[str]) -> dict[str, str]: - command = "pyright . --outputjson" + command = f"{sys.executable} -m pyright . --outputjson" proc = run(command, stdout=PIPE, text=True, shell=True) output_json = json.loads(proc.stdout) diagnostics = output_json["generalDiagnostics"] @@ -118,7 +123,7 @@ def name(self) -> str: return "pyre" def install(self) -> None: - run("pip install pyre-check --upgrade", shell=True) + run(f"{sys.executable} -m pip install pyre-check --upgrade", shell=True) # Generate a default config file. pyre_config = ( @@ -134,8 +139,7 @@ def get_version(self) -> str: return version def run_tests(self, test_files: Sequence[str]) -> dict[str, str]: - command = "pyre check" - proc = run(command, stdout=PIPE, text=True, shell=True) + proc = run("pyre check", stdout=PIPE, text=True, shell=True) lines = proc.stdout.split("\n") # Add results to a dictionary keyed by the file name. @@ -153,15 +157,20 @@ def name(self) -> str: return "pytype" def install(self) -> None: - run("pip install pytype --upgrade", shell=True) + run(f"{sys.executable} -m pip install pytype --upgrade", shell=True) def get_version(self) -> str: - proc = run("pytype --version", stdout=PIPE, text=True, shell=True) + proc = run( + f"{sys.executable} -m pytype --version", stdout=PIPE, text=True, shell=True + ) version = proc.stdout.strip() - return f'pytype {version}' + return f"pytype {version}" def run_tests(self, test_files: Sequence[str]) -> dict[str, str]: - command = "pytype -V 3.11 -k *.py" + # Specify 3.11 for now to work around the fact that pytype + # currently doesn't support 3.12 and emits an error when + # running on 3.12. + command = f"{sys.executable} -m pytype -V 3.11 -k *.py" proc = run(command, stdout=PIPE, text=True, shell=True) lines = proc.stdout.split("\n") @@ -173,7 +182,7 @@ def run_tests(self, test_files: Sequence[str]) -> dict[str, str]: def log_accumulated(): if file_name is not None: results_dict[file_name] = ( - results_dict.get(file_name, "") + ''.join(accumulated_lines) + '\n' + results_dict.get(file_name, "") + "".join(accumulated_lines) + "\n" ) for line in lines: @@ -183,12 +192,12 @@ def log_accumulated(): # An empty line precedes the summary for the file. Ignore # everything after that line until we see diagnostics for # the next file. - if line.strip() == '': + if line.strip() == "": log_accumulated() file_name = None accumulated_lines = [] elif file_name is not None: - accumulated_lines.append('\n' + line) + accumulated_lines.append("\n" + line) else: log_accumulated() @@ -198,7 +207,7 @@ def log_accumulated(): # Replace the full file path with the file name. line = f'File "{file_name}",{line[match.end():]}' accumulated_lines = [line] - + # Log the final accumulated lines. log_accumulated()