Fix auto-detection by not setting PYTHON_VERSIONS when not specified

The auto-detection wasn't working because the
CLI was always setting PYTHON_VERSIONS environment variable to all supported
versions when --python-versions was not provided.

Changes:
- click_helpers.py: Return None instead of all versions when option not provided
- helpers.py: Only set PYTHON_VERSIONS env var when explicitly specified
- main.py: Update type hints to allow None for python_versions parameter

Now the flow works correctly:
1. No --python-versions CLI option -> python_versions = None
2. None passed to Docker -> no PYTHON_VERSIONS env var set
3. Container auto-detects installed versions using pyenv
4. Tests run only on detected versions
This commit is contained in:
Håkon Hægland committed 2025-09-23 12:42:48 +02:00
1 parent 85344a3998
commit bd402ee230
3 files changed
+13 -5

No files matched your search

@@ -6,9 +6,10 @@ from opm_wheels import helpers
def validate_python_versions(
ctx: click.Context, param: Union[click.Option, click.Parameter], value: str
) -> list[PythonVersion]:
) -> list[PythonVersion] | None:
if value is None:
value = ",".join(PythonVersion.valid_versions())
# Return None to allow runtime auto-detection of installed versions
return None
versions = value.split(",")
versions = [PythonVersion.from_str(str(v)) for v in versions]
valid_versions = [PythonVersion.from_str(v) for v in PythonVersion.values()]
@@ -129,7 +129,7 @@ def run_docker_build(
def run_docker_run(
docker_tag: str,
wheel_dir: Path,
python_versions: list[PythonVersion],
python_versions: list[PythonVersion] | None,
host_tests_dir: Path = None,
test_cases_common: str = None,
test_cases_simulators: str = None,
@@ -140,9 +140,16 @@ def run_docker_run(
"docker", "run",
"--rm",
"-v", str(wheel_dir) + ":/test/wheels/",
"-e", "PYTHON_VERSIONS=" + ",".join([str(v) for v in python_versions])
]
# Only set PYTHON_VERSIONS environment variable if explicitly specified
# If not specified (None), let the container auto-detect installed versions
if python_versions is not None:
docker_cmd.extend(["-e", "PYTHON_VERSIONS=" + ",".join([str(v) for v in python_versions])])
logging.info(f"Using specified Python versions: {','.join([str(v) for v in python_versions])}")
else:
logging.info("Using auto-detected Python versions from container")
# Add host test directory mounts if specified
if host_tests_dir:
# Validate that the expected directories exist
@@ -170,7 +170,7 @@ def build_docker_image(
def run_docker_image(
docker_os: str,
wheel_dir: str,
python_versions: list[PythonVersion],
python_versions: list[PythonVersion] | None,
host_tests_dir: Path = None,
test_cases_common: str = None,
test_cases_simulators: str = None,