Skip to content

Commit 6600630

Browse files
committed
Fix Windows again
1 parent 37c68b6 commit 6600630

3 files changed

Lines changed: 54 additions & 40 deletions

File tree

bench_runner/scripts/workflow.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,26 @@ def get_windows_build_dir(force_32bit: bool) -> Path:
3333

3434

3535
def get_exe_path(cpython: Path, flags: list[str], force_32bit: bool) -> Path:
36-
if sys.platform.startswith("linux"):
37-
return cpython / "python"
38-
elif sys.platform == "darwin":
39-
return cpython / "python.exe"
40-
elif sys.platform.startswith("win32"):
41-
build_dir = cpython / get_windows_build_dir(force_32bit)
42-
if "NOGIL" in flags:
43-
print(list(build_dir.glob("*.exe")))
44-
exe = next(build_dir.glob("python3.*.exe"))
45-
else:
46-
exe = "python.exe"
47-
return cpython / get_windows_build_dir(force_32bit) / exe
48-
else:
49-
raise RuntimeError(f"Unsupported platform: {sys.platform}")
36+
match util.get_simple_platform():
37+
case "linux":
38+
return cpython / "python"
39+
case "macos":
40+
return cpython / "python.exe"
41+
case "windows":
42+
build_dir = cpython / get_windows_build_dir(force_32bit)
43+
if "NOGIL" in flags:
44+
exe = next(build_dir.glob("python3.*.exe"))
45+
else:
46+
exe = build_dir / "python.exe"
47+
return exe
5048

5149

5250
def run_in_venv(
5351
venv: PathLike, module: str, cmd: list[str], sudo: bool = False
5452
) -> None:
5553
venv = Path(venv)
5654

57-
if sys.platform == "win32":
55+
if util.get_simple_platform() == "windows":
5856
exe = Path("Scripts") / "python.exe"
5957
else:
6058
exe = Path("bin") / "python"
@@ -138,18 +136,19 @@ def compile_unix(cpython: PathLike, flags: list[str], pgo: bool, pystats: bool)
138136

139137
env = os.environ.copy()
140138
if "CLANG" in flags:
141-
if sys.platform.startswith("linux"):
142-
env["CC"] = util.safe_which("clang-19")
143-
env["LLVM_AR"] = util.safe_which("llvm-ar-19")
144-
env["LLVM_PROFDATA"] = util.safe_which("llvm-profdata-19")
145-
elif sys.platform == "darwin":
146-
llvm_prefix = util.get_brew_prefix("llvm")
147-
env["PATH"] = f"{llvm_prefix}/bin:{env['PATH']}"
148-
env["CC"] = f"{llvm_prefix}/bin/clang"
149-
env["LDFLAGS"] = f"-L{llvm_prefix}/lib"
150-
env["CFLAGS"] = f"-I{llvm_prefix}/include"
151-
152-
if sys.platform == "darwin":
139+
match util.get_simple_platform():
140+
case "linux":
141+
env["CC"] = util.safe_which("clang-19")
142+
env["LLVM_AR"] = util.safe_which("llvm-ar-19")
143+
env["LLVM_PROFDATA"] = util.safe_which("llvm-profdata-19")
144+
case "macos":
145+
llvm_prefix = util.get_brew_prefix("llvm")
146+
env["PATH"] = f"{llvm_prefix}/bin:{env['PATH']}"
147+
env["CC"] = f"{llvm_prefix}/bin/clang"
148+
env["LDFLAGS"] = f"-L{llvm_prefix}/lib"
149+
env["CFLAGS"] = f"-I{llvm_prefix}/include"
150+
151+
if util.get_simple_platform() == "macos":
153152
openssl_prefix = util.get_brew_prefix("openssl@1.1")
154153
env["PKG_CONFIG_PATH"] = f"{openssl_prefix}/lib/pkgconfig"
155154

@@ -226,7 +225,7 @@ def install_pyperformance(venv: PathLike) -> None:
226225

227226
def tune_system(venv: PathLike, perf: bool) -> None:
228227
# System tuning is Linux only
229-
if not sys.platform.startswith("linux"):
228+
if util.get_simple_platform() != "linux":
230229
return
231230

232231
args = ["system", perf and "reset" or "tune"]
@@ -248,7 +247,7 @@ def tune_system(venv: PathLike, perf: bool) -> None:
248247

249248
def reset_system(venv: PathLike) -> None:
250249
# System tuning is Linux only
251-
if not sys.platform.startswith("linux"):
250+
if util.get_simple_platform() != "linux":
252251
return
253252

254253
run_in_venv(
@@ -274,12 +273,13 @@ def _main(
274273
):
275274
venv = Path("venv")
276275
cpython = Path("cpython")
276+
platform = util.get_simple_platform()
277277

278-
if force_32bit and sys.platform != "win32":
278+
if force_32bit and platform != "windows":
279279
raise RuntimeError("32-bit builds are only supported on Windows")
280-
if perf and not sys.platform.startswith("linux"):
280+
if perf and platform != "linux":
281281
raise RuntimeError("perf profiling is only supported on Linux")
282-
if pystats and not sys.platform.startswith("linux"):
282+
if pystats and platform != "linux":
283283
raise RuntimeError("Pystats is only supported on Linux")
284284

285285
checkout_cpython(fork, ref, cpython)
@@ -290,12 +290,11 @@ def _main(
290290

291291
checkout_benchmarks()
292292

293-
if sys.platform.startswith("linux") or sys.platform == "darwin":
294-
compile_unix(cpython, flags, pgo, pystats)
295-
elif sys.platform == "win32":
296-
compile_windows(cpython, flags, pgo, force_32bit)
297-
else:
298-
raise RuntimeError(f"Unsupported platform: {sys.platform}")
293+
match platform:
294+
case "linux" | "macos":
295+
compile_unix(cpython, flags, pgo, pystats)
296+
case "windows":
297+
compile_windows(cpython, flags, pgo, force_32bit)
299298

300299
# Print out the version of Python we built just so we can confirm it's the
301300
# right thing in the logs

bench_runner/templates/workflow_bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run_in_venv(
3131
) -> None:
3232
venv = Path(venv)
3333

34-
if sys.platform == "win32":
34+
if sys.platform.startswith("win"):
3535
exe = Path("Scripts") / "python.exe"
3636
else:
3737
exe = Path("bin") / "python"

bench_runner/util.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from pathlib import Path
55
import shutil
66
import subprocess
7-
from typing import TypeAlias, Union
7+
import sys
8+
from typing import Literal, TypeAlias, Union
89

910

1011
from . import config
@@ -70,3 +71,17 @@ def get_brew_prefix(command: str) -> str:
7071
except subprocess.CalledProcessError:
7172
raise RuntimeError(f"Unable to find brew installation prefix for {command}")
7273
return prefix.decode("utf-8").strip()
74+
75+
76+
@functools.cache
77+
def get_simple_platform() -> Literal["linux", "macos", "windows"]:
78+
"""
79+
Return a basic platform name: linux, macos or windows.
80+
"""
81+
if sys.platform.startswith("linux"):
82+
return "linux"
83+
elif sys.platform == "darwin":
84+
return "macos"
85+
elif sys.platform.startswith("win"):
86+
return "windows"
87+
raise RuntimeError(f"Unsupported platform {sys.platform}.")

0 commit comments

Comments
 (0)