Skip to content

Commit

Permalink
styling
Browse files Browse the repository at this point in the history
  • Loading branch information
amandarichardsonn committed Aug 27, 2024
1 parent 20844d0 commit e905874
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
4 changes: 3 additions & 1 deletion smartsim/_core/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def __getitem__(self, idx: t.Union[int, slice]) -> t.Union[str, Self]:
def __setitem__(self, idx: int, value: str) -> None: ...
@t.overload
def __setitem__(self, idx: slice, value: t.Iterable[str]) -> None: ...
def __setitem__(self, idx: t.Union[int, slice], value: t.Union[str, t.Iterable[str]]) -> None:
def __setitem__(
self, idx: t.Union[int, slice], value: t.Union[str, t.Iterable[str]]
) -> None:
"""Set the command at the specified index."""
if isinstance(idx, int):
if not isinstance(value, str):
Expand Down
4 changes: 3 additions & 1 deletion smartsim/_core/commands/commandList.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def commands(self) -> t.List[Command]:
def __getitem__(self, idx: int) -> Command: ...
@t.overload
def __getitem__(self, idx: slice) -> t.List[Command]: ...
def __getitem__(self, idx: t.Union[slice, int]) -> t.Union[Command, t.List[Command]]:
def __getitem__(
self, idx: t.Union[slice, int]
) -> t.Union[Command, t.List[Command]]:
"""Get the Command at the specified index."""
return self._commands[idx]

Expand Down
1 change: 0 additions & 1 deletion smartsim/_core/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import dataclasses
import os
import pathlib

import typing as t

from typing_extensions import Self, TypeAlias, TypeVarTuple, Unpack
Expand Down
11 changes: 8 additions & 3 deletions smartsim/_core/shell/shellLauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@

from __future__ import annotations

import subprocess as sp
import typing as t
import io
import pathlib
import subprocess as sp
import typing as t

import psutil

from smartsim._core.dispatch import _EnvironMappingType, _FormatterType, _WorkingDirectory
from smartsim._core.arguments.shell import ShellLaunchArguments
from smartsim._core.dispatch import (
_EnvironMappingType,
_FormatterType,
_WorkingDirectory,
)
from smartsim._core.utils import helpers
from smartsim._core.utils.launcher import ExecutableProtocol, create_job_id
from smartsim.error import errors
Expand All @@ -52,13 +55,15 @@

logger = get_logger(__name__)


class ShellLauncherCommand(t.NamedTuple):
env: _EnvironMappingType
path: pathlib.Path
stdout: io.TextIOWrapper | int
stderr: io.TextIOWrapper | int
command_tuple: tuple[str, tuple[str, ...]] | t.Sequence[str]


def make_shell_format_fn(
run_command: str | None,
) -> _FormatterType[ShellLaunchArguments, ShellLauncherCommand]:
Expand Down
7 changes: 2 additions & 5 deletions smartsim/settings/arguments/launch/lsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
import subprocess
import typing as t

from smartsim._core.dispatch import (
_EnvironMappingType,
dispatch,
)
from smartsim._core.arguments.shell import ShellLaunchArguments
from smartsim._core.dispatch import _EnvironMappingType, dispatch
from smartsim._core.shell.shellLauncher import ShellLauncher, ShellLauncherCommand
from smartsim._core.utils.launcher import ExecutableProtocol
from smartsim._core.arguments.shell import ShellLaunchArguments
from smartsim.log import get_logger

from ...common import set_check_input
Expand Down
9 changes: 2 additions & 7 deletions smartsim/settings/arguments/launch/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,10 @@
import subprocess
import typing as t

from smartsim._core.dispatch import (
_EnvironMappingType,
dispatch,
)
from smartsim._core.arguments.shell import ShellLaunchArguments
from smartsim._core.dispatch import _EnvironMappingType, dispatch
from smartsim._core.shell.shellLauncher import ShellLauncher, ShellLauncherCommand
from smartsim._core.utils.launcher import ExecutableProtocol
from smartsim._core.arguments.shell import ShellLaunchArguments
from smartsim._core.dispatch import dispatch

from smartsim.log import get_logger

from ...common import set_check_input
Expand Down
8 changes: 6 additions & 2 deletions tests/test_shell_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def test_shell_launcher_start_calls_popen(
shell_launcher, shell_cmd: ShellLauncherCommand
):
"""Test that the process leading up to the shell launcher popen call was correct"""
with unittest.mock.patch("smartsim._core.shell.shellLauncher.sp.Popen") as mock_open:
with unittest.mock.patch(
"smartsim._core.shell.shellLauncher.sp.Popen"
) as mock_open:
_ = shell_launcher.start(shell_cmd)
mock_open.assert_called_once()

Expand All @@ -134,7 +136,9 @@ def test_shell_launcher_start_calls_popen_with_value(
shell_launcher, shell_cmd: ShellLauncherCommand
):
"""Test that popen was called with correct values"""
with unittest.mock.patch("smartsim._core.shell.shellLauncher.sp.Popen") as mock_open:
with unittest.mock.patch(
"smartsim._core.shell.shellLauncher.sp.Popen"
) as mock_open:
_ = shell_launcher.start(shell_cmd)
mock_open.assert_called_once_with(
shell_cmd.command_tuple,
Expand Down

0 comments on commit e905874

Please sign in to comment.