Skip to content

Commit

Permalink
hmm
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Oct 11, 2024
1 parent 17dd6bc commit 71c0b74
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion mypy_primer/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def parse_options(argv: list[str]) -> _Args:
primer_group.add_argument(
"-j",
"--concurrency",
default=multiprocessing.cpu_count(),
default=multiprocessing.cpu_count() - 8,
type=int,
help="number of subprocesses to use at a time",
)
Expand Down
25 changes: 16 additions & 9 deletions mypy_primer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,27 @@ async def measure_project_runtimes() -> None:
async def inner(project: Project) -> tuple[float, Project]:
await project.setup()
result = await project.run_typechecker(type_checker_exe, typeshed_dir=None)
if not result.success:
print(str(result))
return (result.runtime, project)

projects = select_projects()
results = []
for fut in asyncio.as_completed([inner(project) for project in projects]):
time_taken, project = await fut
results.append((time_taken, project))
print(f"[{len(results)}/{len(projects)}] {time_taken:6.2f}s {project.location}")
import collections, statistics, random

results.sort(reverse=True)
projects = select_projects()
results = collections.defaultdict(list)
for _ in range(5):
random.shuffle(projects)
for i, fut in enumerate(asyncio.as_completed([inner(project) for project in projects])):
time_taken, project = await fut
results[project.location].append(time_taken)
print(f"[{i}/{len(projects)}] {time_taken:6.2f}s {project.location}")

results = [(statistics.mean(times), location) for location, times in results.items()]
results.sort(key=lambda x: x[0], reverse=True)
print("\n" * 5)
print("Results:")
for time_taken, project in results:
print(f"{time_taken:6.2f}s {project.location}")
for time_taken, location in results:
print(f"{time_taken:6.2f}s {location}")


# ==============================
Expand Down
20 changes: 11 additions & 9 deletions mypy_primer/type_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ async def pip_install(*targets: str) -> None:
repo_dir = await ensure_repo_at_revision(repo, mypy_dir, revision_like)
if mypyc_compile_level is not None:
env = os.environ.copy()
env["MYPYC_OPT_LEVEL"] = str(mypyc_compile_level)
await pip_install("typing_extensions", "mypy_extensions")
env["MYPY_USE_MYPYC"] = "1"
env["MYPYC_OPT_LEVEL"] = str(mypyc_compile_level) # can be zero
await pip_install("typing_extensions", "mypy_extensions", "tomli", "types-psutil", "types-setuptools")
await run(
[str(venv.python), "setup.py", "--use-mypyc", "build_ext", "--inplace"],
[str(venv.python), "-m", "pip", "install", ".", "--no-build-isolation"],
cwd=repo_dir,
env=env,
)
targets = []
if editable:
targets.append("--editable")
targets.append(str(repo_dir))
targets.append("tomli")
await pip_install(*targets)
else:
targets = []
if editable:
targets.append("--editable")
targets.append(str(repo_dir))
targets.append("tomli")
await pip_install(*targets)

with open(venv.site_packages / "primer_plugin.pth", "w") as f:
# pth file that lets us let mypy import plugins from another venv
Expand Down
2 changes: 2 additions & 0 deletions mypy_primer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ async def run(
stderr = stderr_b.decode("utf-8") if stderr_b is not None else None
assert proc.returncode is not None
if check and proc.returncode:
print(f"stdout:\n{stdout}")
print(f"stderr:\n{stderr}")
raise subprocess.CalledProcessError(proc.returncode, cmd, output=stdout, stderr=stderr)
return subprocess.CompletedProcess(cmd, proc.returncode, stdout, stderr), end_t - start_t

Expand Down

0 comments on commit 71c0b74

Please sign in to comment.