Skip to content

Commit

Permalink
Simplify submit script
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Nov 27, 2024
1 parent 186a508 commit 559db0a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 32 deletions.
13 changes: 2 additions & 11 deletions src/ert/config/queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,10 @@


def activate_script() -> str:
shell = os.environ.get("SHELL")
venv = os.environ.get("VIRTUAL_ENV")
if not venv or not shell:
if not venv:
return ""
script = [f"#!{shell}"]
match shell:
case x if "bash" in x or "zsh" in x:
script.append(f"source {venv}/bin/activate")
case x if "csh" in x or "tcsh" in x:
script.append(f"source {venv}/bin/activate.csh")
case x if "fish" in x:
script.append(f"source {venv}/bin/activate.fish")
return "\n".join(script)
return f"source {venv}/bin/activate"


@pydantic.dataclasses.dataclass(config={"extra": "forbid", "validate_assignment": True})
Expand Down
12 changes: 1 addition & 11 deletions src/ert/scheduler/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import shlex
from abc import ABC, abstractmethod
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import Dict, Iterable, List, Optional, Tuple

from .event import Event
Expand All @@ -17,19 +16,10 @@
def create_submit_script(
runpath: Path, executable: str, args: tuple[str, ...], activate_script: str
) -> str:
with NamedTemporaryFile(
dir=runpath,
prefix=".compute_activate",
suffix=".sh",
mode="w",
encoding="utf-8",
delete=False,
) as script_handle:
script_handle.write(activate_script)
return (
"#!/usr/bin/env bash\n"
f"cd {shlex.quote(str(runpath))}\n"
f"source {script_handle.name}\n"
f"{activate_script}\n"
f"exec -a {shlex.quote(executable)} {executable} {shlex.join(args)}\n"
)

Expand Down
13 changes: 3 additions & 10 deletions tests/ert/unit_tests/config/test_queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,20 +512,13 @@ def test_driver_initialization_from_defaults(queue_system):
SlurmDriver(**SlurmQueueOptions().driver_options)


@pytest.mark.parametrize("venv", ["my_env", None])
@pytest.mark.parametrize(
"shell, expected",
[
["csh", "#!csh\nsource my_env/bin/activate.csh"],
["bash", "#!bash\nsource my_env/bin/activate"],
],
"venv, expected", [("my_env", "source my_env/bin/activate"), (None, "")]
)
def test_default_activate_script_generation(shell, expected, monkeypatch, venv):
monkeypatch.setenv("SHELL", shell)
def test_default_activate_script_generation(expected, monkeypatch, venv):
if venv:
monkeypatch.setenv("VIRTUAL_ENV", "my_env")
monkeypatch.setenv("VIRTUAL_ENV", venv)
else:
monkeypatch.delenv("VIRTUAL_ENV", raising=False)
expected = ""
options = QueueOptions(name="local")
assert options.activate_script == expected

0 comments on commit 559db0a

Please sign in to comment.