2222import argparse
2323import json
2424import os
25+ import shlex
2526import subprocess
2627import sys
2728import tempfile
@@ -244,36 +245,43 @@ def render_summary(projects: list[ProjectComparison]) -> str:
244245 return "\n " .join (lines )
245246
246247
247- def setup_project (* , name : str , dest : Path ) -> Path :
248+ def setup_project (* , name : str , dest : Path ) -> tuple [ Path , list [ str ]] :
248249 """Clone a project and install its mypy-primer dependencies."""
249250 project_path = dest / name
251+ setup_script = Path (__file__ ).with_name ("setup_primer_project.py" )
252+ setup_command = [
253+ "uv" ,
254+ "run" ,
255+ "--locked" ,
256+ "--python" ,
257+ sys .executable ,
258+ "--script" ,
259+ str (setup_script ),
260+ ]
261+
250262 if project_path .exists ():
251263 print (f"Project { name } already exists at { project_path } " , file = sys .stderr )
252- return project_path
264+ else :
265+ print (f"Setting up { name } and its dependencies..." , file = sys .stderr )
266+ subprocess .run (
267+ [* setup_command , name , str (project_path )],
268+ check = True ,
269+ stdout = sys .stderr ,
270+ )
253271
254- setup_script = Path (__file__ ).with_name ("setup_primer_project.py" )
255- print (f"Setting up { name } and its dependencies..." , file = sys .stderr )
256- subprocess .run (
257- [
258- "uv" ,
259- "run" ,
260- "--locked" ,
261- "--python" ,
262- sys .executable ,
263- "--script" ,
264- str (setup_script ),
265- name ,
266- str (project_path ),
267- ],
272+ ty_command = subprocess .run (
273+ [* setup_command , "--print-ty-command" , name , str (project_path )],
268274 check = True ,
269- stdout = sys .stderr ,
275+ capture_output = True ,
276+ text = True ,
270277 )
271- return project_path
278+ return project_path , shlex . split ( ty_command . stdout )
272279
273280
274281def run_ty_memory_check (
275282 * ,
276283 ty_path : str ,
284+ ty_command : list [str ],
277285 project_path : Path ,
278286 output_path : Path ,
279287) -> None :
@@ -283,8 +291,14 @@ def run_ty_memory_check(
283291 env ["TY_MAX_PARALLELISM" ] = "1" # For deterministic memory numbers
284292
285293 print (f"Running { ty_path } on { project_path .name } ..." , file = sys .stderr )
294+ command = [
295+ str (Path (ty_path ).resolve ()) if argument == "{ty}" else argument
296+ for argument in ty_command
297+ ]
286298 result = subprocess .run (
287- [ty_path , "check" , "--project" , str (project_path ), "--exit-zero" ],
299+ command ,
300+ cwd = project_path ,
301+ check = True ,
288302 capture_output = True ,
289303 text = True ,
290304 env = env ,
@@ -306,18 +320,24 @@ def run_memory_tests(
306320 new_reports_dir .mkdir (parents = True , exist_ok = True )
307321
308322 for project_name in KNOWN_PROJECTS :
309- project_path = setup_project (name = project_name , dest = projects_dir )
323+ project_path , ty_command = setup_project (name = project_name , dest = projects_dir )
310324
311325 # Run old ty
312326 old_report_path = old_reports_dir / f"{ project_name } .json"
313327 run_ty_memory_check (
314- ty_path = old_ty , project_path = project_path , output_path = old_report_path
328+ ty_path = old_ty ,
329+ ty_command = ty_command ,
330+ project_path = project_path ,
331+ output_path = old_report_path ,
315332 )
316333
317334 # Run new ty
318335 new_report_path = new_reports_dir / f"{ project_name } .json"
319336 run_ty_memory_check (
320- ty_path = new_ty , project_path = project_path , output_path = new_report_path
337+ ty_path = new_ty ,
338+ ty_command = ty_command ,
339+ project_path = project_path ,
340+ output_path = new_report_path ,
321341 )
322342
323343
0 commit comments