Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conda support to activation script #9436

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ert/config/queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
23 changes: 23 additions & 0 deletions tests/ert/unit_tests/config/test_queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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