From bd402ee230f152fcb6ddfcf0d3f8bc24bde326d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Tue, 23 Sep 2025 12:36:02 +0200 Subject: [PATCH] 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 --- .../scripts/src/opm_wheels/click_helpers.py | 5 +++-- .../test_wheels/scripts/src/opm_wheels/helpers.py | 11 +++++++++-- .../docker/test_wheels/scripts/src/opm_wheels/main.py | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/python/docker/test_wheels/scripts/src/opm_wheels/click_helpers.py b/python/docker/test_wheels/scripts/src/opm_wheels/click_helpers.py index 99d36221fe..b810684a47 100644 --- a/python/docker/test_wheels/scripts/src/opm_wheels/click_helpers.py +++ b/python/docker/test_wheels/scripts/src/opm_wheels/click_helpers.py @@ -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()] diff --git a/python/docker/test_wheels/scripts/src/opm_wheels/helpers.py b/python/docker/test_wheels/scripts/src/opm_wheels/helpers.py index 9e1791a2d4..c9fc3c5042 100644 --- a/python/docker/test_wheels/scripts/src/opm_wheels/helpers.py +++ b/python/docker/test_wheels/scripts/src/opm_wheels/helpers.py @@ -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 diff --git a/python/docker/test_wheels/scripts/src/opm_wheels/main.py b/python/docker/test_wheels/scripts/src/opm_wheels/main.py index 182a6eeb9f..b0de395238 100644 --- a/python/docker/test_wheels/scripts/src/opm_wheels/main.py +++ b/python/docker/test_wheels/scripts/src/opm_wheels/main.py @@ -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,