From be6c5b25843d90290db8adc3cba3c5663d21689c Mon Sep 17 00:00:00 2001 From: Carlos Marques Date: Tue, 3 Dec 2024 14:24:11 -0300 Subject: [PATCH 1/2] Add conda support to activation script --- src/ert/config/queue_config.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ert/config/queue_config.py b/src/ert/config/queue_config.py index 576e0f8934b..5dad891d017 100644 --- a/src/ert/config/queue_config.py +++ b/src/ert/config/queue_config.py @@ -29,9 +29,12 @@ def activate_script() -> str: venv = os.environ.get("VIRTUAL_ENV") - if not venv: - return "" - return f"source {venv}/bin/activate" + if venv: + return f"source {venv}/bin/activate" + conda_env = os.environ.get("CONDA_ENV") + if conda_env: + return f'eval "$(conda shell.bash hook)" && conda activate {conda_env}' + return "" @pydantic.dataclasses.dataclass(config={"extra": "forbid", "validate_assignment": True}) From fd4093991cc36bce8e7684f5cf071c30c809e607 Mon Sep 17 00:00:00 2001 From: Carlos Marques Date: Tue, 3 Dec 2024 14:28:00 -0300 Subject: [PATCH 2/2] Add unit tests for conda activation script --- .../unit_tests/config/test_queue_config.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/ert/unit_tests/config/test_queue_config.py b/tests/ert/unit_tests/config/test_queue_config.py index bfa26641652..72f3103f2e3 100644 --- a/tests/ert/unit_tests/config/test_queue_config.py +++ b/tests/ert/unit_tests/config/test_queue_config.py @@ -522,3 +522,26 @@ def test_default_activate_script_generation(expected, monkeypatch, venv): monkeypatch.delenv("VIRTUAL_ENV", raising=False) options = QueueOptions(name="local") assert options.activate_script == expected + + +@pytest.mark.parametrize( + "env, expected", + [ + ("my_env", 'eval "$(conda shell.bash hook)" && conda activate my_env'), + ], +) +def test_conda_activate_script_generation(expected, monkeypatch, env): + monkeypatch.setenv("CONDA_ENV", env) + options = QueueOptions(name="local") + assert options.activate_script == expected + + +@pytest.mark.parametrize( + "env, expected", + [("my_env", "source my_env/bin/activate")], +) +def test_multiple_activate_script_generation(expected, monkeypatch, env): + monkeypatch.setenv("VIRTUAL_ENV", env) + monkeypatch.setenv("CONDA_ENV", env) + options = QueueOptions(name="local") + assert options.activate_script == expected