|
8 | 8 |
|
9 | 9 |
|
10 | 10 | def _resolve_example(args: list[str]) -> tuple[str, list[str]]: |
11 | | - """Return (example, remaining_args) picking the first non-flag arg or EXAMPLE env.""" |
12 | | - remaining = list(args) |
13 | | - if remaining and not remaining[0].startswith("-"): |
14 | | - example = remaining.pop(0) |
15 | | - else: |
16 | | - example = os.environ.get("EXAMPLE", "hello_world") |
17 | | - while remaining and remaining[0] == "--": |
18 | | - remaining.pop(0) |
19 | | - return example, remaining |
| 11 | + """Return (example, remaining_args) picking the first non-flag arg or EXAMPLE env.""" |
| 12 | + remaining = list(args) |
| 13 | + if remaining and not remaining[0].startswith("-"): |
| 14 | + example = remaining.pop(0) |
| 15 | + else: |
| 16 | + example = os.environ.get("EXAMPLE", "hello_world") |
| 17 | + while remaining and remaining[0] == "--": |
| 18 | + remaining.pop(0) |
| 19 | + return example, remaining |
20 | 20 |
|
21 | 21 |
|
22 | 22 | def main(argv: list[str]) -> int: |
23 | | - repo_root = Path(__file__).resolve().parent.parent |
24 | | - example, remaining = _resolve_example(argv) |
25 | | - |
26 | | - script = repo_root / "python" / "examples" / example / "main.py" |
27 | | - if not script.exists(): |
28 | | - sys.stderr.write(f"Python example not found: {script}\n") |
29 | | - return 1 |
30 | | - |
31 | | - build_type = os.environ.get("BUILD_TYPE", "Release") |
32 | | - env_name = os.environ.get("PIXI_ENVIRONMENT_NAME", "default") |
33 | | - py_path = repo_root / "build" / env_name / "cpp" / build_type / "python" |
34 | | - |
35 | | - env = os.environ.copy() |
36 | | - existing = env.get("PYTHONPATH", "") |
37 | | - env["PYTHONPATH"] = f"{py_path}:{existing}" if existing else str(py_path) |
38 | | - # Ensure conda libs (glfw, imgui, OpenGL) are ahead of system paths. |
39 | | - conda_prefix = env.get("CONDA_PREFIX") |
40 | | - if conda_prefix: |
41 | | - ld_paths = env.get("LD_LIBRARY_PATH", "") |
42 | | - env["LD_LIBRARY_PATH"] = f"{conda_prefix}/lib:{ld_paths}" if ld_paths else f"{conda_prefix}/lib" |
43 | | - preload = env.get("LD_PRELOAD", "") |
44 | | - glfw_lib = f"{conda_prefix}/lib/libglfw.so" |
45 | | - env["LD_PRELOAD"] = f"{glfw_lib}:{preload}" if preload else glfw_lib |
46 | | - |
47 | | - cmd = [sys.executable, str(script), *remaining] |
48 | | - return subprocess.call(cmd, env=env, cwd=repo_root) |
| 23 | + repo_root = Path(__file__).resolve().parent.parent |
| 24 | + example, remaining = _resolve_example(argv) |
| 25 | + |
| 26 | + script = repo_root / "python" / "examples" / example / "main.py" |
| 27 | + if not script.exists(): |
| 28 | + sys.stderr.write(f"Python example not found: {script}\n") |
| 29 | + return 1 |
| 30 | + |
| 31 | + build_type = os.environ.get("BUILD_TYPE", "Release") |
| 32 | + env_name = os.environ.get("PIXI_ENVIRONMENT_NAME", "default") |
| 33 | + py_path = repo_root / "build" / env_name / "cpp" / build_type / "python" |
| 34 | + |
| 35 | + env = os.environ.copy() |
| 36 | + existing = env.get("PYTHONPATH", "") |
| 37 | + env["PYTHONPATH"] = f"{py_path}:{existing}" if existing else str(py_path) |
| 38 | + # Ensure conda libs (glfw, imgui, OpenGL) are ahead of system paths. |
| 39 | + conda_prefix = env.get("CONDA_PREFIX") |
| 40 | + if conda_prefix: |
| 41 | + ld_paths = env.get("LD_LIBRARY_PATH", "") |
| 42 | + env["LD_LIBRARY_PATH"] = ( |
| 43 | + f"{conda_prefix}/lib:{ld_paths}" if ld_paths else f"{conda_prefix}/lib" |
| 44 | + ) |
| 45 | + preload = env.get("LD_PRELOAD", "") |
| 46 | + glfw_lib = f"{conda_prefix}/lib/libglfw.so" |
| 47 | + env["LD_PRELOAD"] = f"{glfw_lib}:{preload}" if preload else glfw_lib |
| 48 | + |
| 49 | + cmd = [sys.executable, str(script), *remaining] |
| 50 | + return subprocess.call(cmd, env=env, cwd=repo_root) |
49 | 51 |
|
50 | 52 |
|
51 | 53 | if __name__ == "__main__": |
52 | | - raise SystemExit(main(sys.argv[1:])) |
| 54 | + raise SystemExit(main(sys.argv[1:])) |
0 commit comments