Skip to content

Commit c4edd17

Browse files
committed
Merge branch 'fixed-python' into pre-kickstart-SR2026
2 parents b6f1c54 + a2ff683 commit c4edd17

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,4 @@ cython_debug/
167167
/simulator/controllers/competition_supervisor/runtime.ini
168168
/zone_*
169169
/dist
170+
/uv.lock

scripts/generate_release.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
script_dir = temp_dir / "scripts"
8686
script_dir.mkdir()
8787
shutil.copy(project_root / "scripts/run_comp_match.py", script_dir)
88+
shutil.copy(project_root / "scripts/setup_python_fix.py", script_dir)
8889

8990
logger.info("Copying example code to temp directory")
9091
shutil.copytree(project_root / "example_robots", temp_dir / "example_robots")

scripts/setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import sys
1717
from pathlib import Path
1818
from subprocess import SubprocessError, check_call
19-
from venv import create
2019

2120
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(levelname)s: %(message)s")
2221
logger = logging.getLogger(__name__)
@@ -84,7 +83,7 @@ def populate_python_config(runtime_ini: Path, venv_python: Path) -> None:
8483
(venv_dir / "setup_success").unlink(missing_ok=True)
8584

8685
logger.info(f"Creating virtual environment in {venv_dir.absolute()}")
87-
create(venv_dir, with_pip=True)
86+
check_call([sys.executable, "-m", "venv", venv_dir])
8887

8988
logger.info(f"Installing dependencies from {requirements.absolute()}")
9089
if platform.system() == "Windows":

scripts/setup_python_fix.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
"""
3+
A script to setup the environment for running the project in Webots.
4+
5+
It will:
6+
1. Create a setup virtual environment and install uv into it
7+
2. Use uv to run the standard setup using the desired Python version
8+
"""
9+
import logging
10+
import platform
11+
import sys
12+
from pathlib import Path
13+
from subprocess import SubprocessError, check_call
14+
15+
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(levelname)s: %(message)s")
16+
logger = logging.getLogger(__name__)
17+
18+
BOLD_RED = '\x1b[31;1m'
19+
GREEN = '\x1b[32;20m'
20+
RESET_COLOUR = '\x1b[0m'
21+
22+
PYTHON_VERSION = "3.11"
23+
24+
try:
25+
if (Path(__file__).parent / 'simulator/VERSION').exists():
26+
# This is running from a release
27+
print("Running in release mode")
28+
project_root = Path(__file__).parent
29+
else:
30+
# This is running from the repository
31+
print("Running in development mode")
32+
project_root = Path(__file__).parents[1]
33+
34+
print(f"Starting with python version: {sys.version} on {platform.platform()}")
35+
36+
venv_dir = project_root / "simulator/setup_venv"
37+
script_dir = Path(__file__).parent
38+
39+
check_call([sys.executable, "-m", "venv", venv_dir])
40+
41+
logger.info("Installing uv")
42+
if platform.system() == "Windows":
43+
venv_bin_dir = venv_dir / "Scripts"
44+
pip = venv_bin_dir / "pip.exe"
45+
uv_bin = venv_bin_dir / "uv.exe"
46+
else:
47+
venv_bin_dir = venv_dir / "bin"
48+
pip = venv_bin_dir / "pip"
49+
uv_bin = venv_bin_dir / "uv"
50+
51+
check_call(
52+
[pip, "install", "--only-binary=:all:", "--upgrade", "wheel", "uv"],
53+
cwd=venv_dir,
54+
)
55+
56+
logger.info(f"Running setup using Python {PYTHON_VERSION}")
57+
setup_script = script_dir.relative_to(project_root) / "setup.py"
58+
check_call([uv_bin, "run", "--python", PYTHON_VERSION, setup_script], cwd=project_root)
59+
except SubprocessError:
60+
print(BOLD_RED)
61+
logger.error("Setup failed due to an error.")
62+
input(f"An error occurred, press enter to close.{RESET_COLOUR}")
63+
except Exception:
64+
print(BOLD_RED)
65+
logger.exception("Setup failed due to an error.")
66+
input(f"An error occurred, press enter to close.{RESET_COLOUR}")

0 commit comments

Comments
 (0)