33import logging
44import shlex
55import subprocess
6- import typing
76from pathlib import Path
7+ from typing import Mapping , NamedTuple
88
99
10- class Command (typing . NamedTuple ):
10+ class Command (NamedTuple ):
1111 name : str
1212 """The name of the command to benchmark."""
1313
@@ -18,7 +18,7 @@ class Command(typing.NamedTuple):
1818 """The command to run before each benchmark run."""
1919
2020
21- class Hyperfine (typing . NamedTuple ):
21+ class Hyperfine (NamedTuple ):
2222 name : str
2323 """The benchmark to run."""
2424
@@ -37,13 +37,16 @@ class Hyperfine(typing.NamedTuple):
3737 json : bool
3838 """Whether to export results to JSON."""
3939
40- def run (self , * , cwd : Path | None = None ) -> None :
40+ def run (self , * , cwd : Path | None = None , env : Mapping [ str , str ] = dict () ) -> None :
4141 """Run the benchmark using `hyperfine`."""
4242 args = [
4343 "hyperfine" ,
44- # Most repositories have some typing errors.
45- # This is annoying because it prevents us from capturing "real" errors.
46- "-i" ,
44+ # Ignore any warning/error diagnostics but fail if there are any fatal errors, incorrect configuration, etc.
45+ # mypy exit codes: https://github.com/python/mypy/issues/14615#issuecomment-1420163253
46+ # pyright exit codes: https://docs.basedpyright.com/v1.31.6/configuration/command-line/#pyright-exit-codes
47+ # pyrefly exit codes: Not documented
48+ # ty: https://docs.astral.sh/ty/reference/exit-codes/
49+ "-i=1" ,
4750 ]
4851
4952 # Export to JSON.
@@ -70,7 +73,4 @@ def run(self, *, cwd: Path | None = None) -> None:
7073
7174 logging .info (f"Running { args } " )
7275
73- subprocess .run (
74- args ,
75- cwd = cwd ,
76- )
76+ subprocess .run (args , cwd = cwd , env = env )
0 commit comments