@@ -59,7 +59,7 @@ def __exit__(
59
59
self .foutput .close ()
60
60
61
61
@contextlib .contextmanager
62
- def set_env (self , * env_varss : dict [ str , str ] | None ) -> Iterator [None ]:
62
+ def set_env (self , * env_varss : Env_VarsType ) -> Iterator [None ]:
63
63
"""Set environment variables.
64
64
65
65
All the arguments are dicts of name:value, or None. All are applied
@@ -116,12 +116,13 @@ def run_command(self, cmd: str) -> str:
116
116
return output .strip ()
117
117
118
118
119
- def rmrf (path : Path ) -> None :
119
+ def remake (path : Path ) -> None :
120
120
"""
121
- Remove a directory tree. It's OK if it doesn't exist.
121
+ Remove a directory tree and recreate it . It's OK if it doesn't exist.
122
122
"""
123
123
if path .exists ():
124
124
shutil .rmtree (path )
125
+ path .mkdir (parents = True )
125
126
126
127
127
128
@contextlib .contextmanager
@@ -204,8 +205,9 @@ def shell(self) -> ShellSession:
204
205
205
206
def make_dir (self ) -> None :
206
207
self .dir = Path (f"work_{ self .slug } " )
207
- if self .dir .exists ():
208
- rmrf (self .dir )
208
+ remake (self .dir )
209
+ self .tmpdir = Path (f"tmp_{ self .slug } " ).resolve ()
210
+ remake (self .tmpdir )
209
211
210
212
def get_source (self , shell : ShellSession , retries : int = 5 ) -> None :
211
213
"""Get the source of the project."""
@@ -277,11 +279,18 @@ def run_with_coverage(self, env: Env, cov_ver: Coverage) -> float:
277
279
class ToxProject (ProjectToTest ):
278
280
"""A project using tox to run the test suite."""
279
281
282
+ ALLOWABLE_ENV_VARS = [
283
+ "COVERAGE_DEBUG" ,
284
+ "COVERAGE_CORE" ,
285
+ "COVERAGE_FORCE_CONFIG" ,
286
+ "PATH" ,
287
+ "TMPDIR" ,
288
+ ]
289
+
280
290
env_vars : Env_VarsType = {
281
291
** (ProjectToTest .env_vars or {}),
282
292
# Allow some environment variables into the tox execution.
283
- "TOX_OVERRIDE" : "testenv.pass_env+=COVERAGE_DEBUG,COVERAGE_CORE,COVERAGE_FORCE_CONFIG" ,
284
- "COVERAGE_DEBUG" : "config,sys" ,
293
+ "TOX_OVERRIDE" : "testenv.pass_env+=" + "," .join (ALLOWABLE_ENV_VARS ),
285
294
}
286
295
287
296
def prep_environment (self , env : Env ) -> None :
@@ -423,22 +432,19 @@ def __init__(self, more_pytest_args: str = ""):
423
432
424
433
def prep_environment (self , env : Env ) -> None :
425
434
env .shell .run_command (f"{ env .python } -m pip install tox" )
426
- Path ("/tmp/operator_tmp" ).mkdir (exist_ok = True )
427
435
env .shell .run_command (f"{ env .python } -m tox -e unit --notest" )
428
436
env .shell .run_command (f"{ env .python } -m tox -e unitnocov --notest" )
429
437
430
438
def run_no_coverage (self , env : Env ) -> float :
431
439
env .shell .run_command (
432
- f"TMPDIR=/tmp/operator_tmp { env .python } -m tox -e unitnocov --skip-pkg-install"
433
- + f" -- { self .more_pytest_args } "
440
+ f"{ env .python } -m tox -e unitnocov --skip-pkg-install -- { self .more_pytest_args } "
434
441
)
435
442
return env .shell .last_duration
436
443
437
444
def run_with_coverage (self , env : Env , cov_ver : Coverage ) -> float :
438
445
env .shell .run_command (f"{ env .python } -m pip install { cov_ver .pip_args } " )
439
446
env .shell .run_command (
440
- f"TMPDIR=/tmp/operator_tmp { env .python } -m tox -e unit --skip-pkg-install"
441
- + f" -- { self .more_pytest_args } "
447
+ f"{ env .python } -m tox -e unit --skip-pkg-install -- { self .more_pytest_args } "
442
448
)
443
449
duration = env .shell .last_duration
444
450
report = env .shell .run_command (f"{ env .python } -m coverage report --precision=6" )
@@ -848,18 +854,17 @@ def __init__(
848
854
py_versions : list [PyVersion ],
849
855
cov_versions : list [Coverage ],
850
856
projects : list [ProjectToTest ],
851
- results_file : str = "results.json" ,
857
+ results_file : Path = Path ( "results.json" ) ,
852
858
load : bool = False ,
853
- cwd : str = "" ,
854
859
):
855
860
self .py_versions = py_versions
856
861
self .cov_versions = cov_versions
857
862
self .projects = projects
858
- self .results_file = Path (cwd ) / Path (results_file )
859
- self .result_data : dict [ResultKey , list [float ]] = (
860
- self .load_results () if load else {}
861
- )
863
+ self .results_file = results_file
864
+ self .result_data : dict [ResultKey , list [float ]] = {}
862
865
self .summary_data : dict [ResultKey , float ] = {}
866
+ if load :
867
+ self .result_data = self .load_results ()
863
868
864
869
def save_results (self ) -> None :
865
870
"""Save current results to the JSON file."""
@@ -933,8 +938,13 @@ def run(self, num_runs: int = 3) -> None:
933
938
)
934
939
print (banner )
935
940
env .shell .print_banner (banner )
941
+ env_vars = [
942
+ proj .env_vars ,
943
+ cov_ver .env_vars ,
944
+ {"TMPDIR" : str (proj .tmpdir )},
945
+ ]
936
946
with change_dir (proj .dir ):
937
- with env .shell .set_env (proj . env_vars , cov_ver . env_vars ):
947
+ with env .shell .set_env (* env_vars ):
938
948
try :
939
949
if cov_ver .pip_args is None :
940
950
dur = proj .run_no_coverage (env )
@@ -1056,16 +1066,16 @@ def run_experiment(
1056
1066
)
1057
1067
1058
1068
print (f"Removing and re-making { PERF_DIR } " )
1059
- rmrf (PERF_DIR )
1069
+ remake (PERF_DIR )
1060
1070
1061
- cwd = str ( Path . cwd () )
1071
+ results_file = Path ( "results.json" ). resolve ( )
1062
1072
with change_dir (PERF_DIR ):
1063
1073
exp = Experiment (
1064
1074
py_versions = py_versions ,
1065
1075
cov_versions = cov_versions ,
1066
1076
projects = projects ,
1077
+ results_file = results_file ,
1067
1078
load = load ,
1068
- cwd = cwd ,
1069
1079
)
1070
1080
exp .run (num_runs = int (num_runs ))
1071
1081
exp .show_results (rows = rows , column = column , ratios = ratios )
0 commit comments