From 559db0af4388f0a3282694136c8679e3d4837bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Eide?= Date: Wed, 27 Nov 2024 12:20:22 +0100 Subject: [PATCH] Simplify submit script --- src/ert/config/queue_config.py | 13 ++----------- src/ert/scheduler/driver.py | 12 +----------- tests/ert/unit_tests/config/test_queue_config.py | 13 +++---------- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/src/ert/config/queue_config.py b/src/ert/config/queue_config.py index f9c82f59e74..576e0f8934b 100644 --- a/src/ert/config/queue_config.py +++ b/src/ert/config/queue_config.py @@ -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}) diff --git a/src/ert/scheduler/driver.py b/src/ert/scheduler/driver.py index 8a0b0a277a4..a5736dc597f 100644 --- a/src/ert/scheduler/driver.py +++ b/src/ert/scheduler/driver.py @@ -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 @@ -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" ) diff --git a/tests/ert/unit_tests/config/test_queue_config.py b/tests/ert/unit_tests/config/test_queue_config.py index 00b03a79ff6..bfa26641652 100644 --- a/tests/ert/unit_tests/config/test_queue_config.py +++ b/tests/ert/unit_tests/config/test_queue_config.py @@ -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