Skip to content

Commit

Permalink
Incorporated PR feedback: use {sys.executable} -m for run invocat…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
erictraut committed Dec 26, 2023
1 parent 448fffe commit 4b9ec56
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions conformance/src/type_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path
import re
from subprocess import PIPE, run
import sys
from typing import Sequence


Expand Down Expand Up @@ -48,18 +49,20 @@ 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.
version = version.split(" (")[0]
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")

Expand All @@ -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"]
Expand Down Expand Up @@ -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 = (
Expand All @@ -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.
Expand All @@ -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")

Expand All @@ -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:
Expand All @@ -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()

Expand All @@ -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()

Expand Down

0 comments on commit 4b9ec56

Please sign in to comment.