Skip to content

Commit

Permalink
fixup! Make activate script that runs on compute node
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Nov 21, 2024
1 parent 4c82853 commit 9e7f130
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/ert/plugins/hook_specifications/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .activate_script import activate_script
from .ecl_config import (
ecl100_config_path,
ecl300_config_path,
Expand All @@ -18,9 +19,9 @@
add_span_processor,
)
from .site_config import site_config_lines
from .activate_script import activate_script

__all__ = [
"activate_script",
"add_log_handle_to_root",
"add_span_processor",
"ecl100_config_path",
Expand Down
2 changes: 1 addition & 1 deletion src/ert/plugins/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _site_config_lines(self) -> List[str]:

def activate_script(self) -> str:
def activate_script():

Check failure on line 160 in src/ert/plugins/plugin_manager.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Function is missing a return type annotation
shell = os.environ['SHELL']
shell = os.environ["SHELL"]
venv = os.environ.get("VIRTUAL_ENV")
if not venv:
return ""
Expand Down
15 changes: 7 additions & 8 deletions src/ert/scheduler/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import asyncio
import logging
import os
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
from ..plugins import ErtPluginManager
from .event import Event

SIGNAL_OFFSET = 128
"""Bash and other shells add an offset of 128 to the signal value when a process exited due to a signal"""
Expand All @@ -19,12 +18,12 @@
def create_submit_script(runpath: Path, executable: str, args: tuple[str, ...]) -> str:
activate_script = ErtPluginManager().activate_script()
with NamedTemporaryFile(
dir=runpath,
prefix=".compute_activate",
suffix=".sh",
mode="w",
encoding="utf-8",
delete=False,
dir=runpath,
prefix=".compute_activate",
suffix=".sh",
mode="w",
encoding="utf-8",
delete=False,
) as script_handle:
script_handle.write(activate_script)
return (
Expand Down
10 changes: 8 additions & 2 deletions tests/ert/unit_tests/plugins/test_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ def test_that_forward_model_step_is_registered(tmpdir):


@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"]])
@pytest.mark.parametrize(
"shell, expected",
[
["csh", "#!csh\nsource my_env/bin/activate.csh"],
["bash", "#!bash\nsource my_env/bin/activate"],
],
)
def test_activate_script_generation(shell, expected, monkeypatch, venv):
monkeypatch.setenv("SHELL", shell)
pm = ErtPluginManager(plugins=[])
Expand All @@ -151,4 +157,4 @@ def test_activate_script_generation(shell, expected, monkeypatch, venv):
assert pm.activate_script() == expected
else:
monkeypatch.delenv("VIRTUAL_ENV")
assert pm.activate_script() == ""
assert not pm.activate_script()

0 comments on commit 9e7f130

Please sign in to comment.