Skip to content

Commit

Permalink
Merge branch 'smartsim-refactor' into v1.0-merge-core
Browse files Browse the repository at this point in the history
  • Loading branch information
ankona committed Oct 21, 2024
2 parents bfc36e3 + a39246e commit 30c7d36
Show file tree
Hide file tree
Showing 21 changed files with 1,102 additions and 564 deletions.
56 changes: 56 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import typing as t
import uuid
import warnings
from glob import glob
from os import path as osp
from collections import defaultdict
from dataclasses import dataclass
from subprocess import run
Expand All @@ -53,6 +55,8 @@
from smartsim._core.config.config import Config
from smartsim._core.launcher.dragon.dragon_connector import DragonConnector
from smartsim._core.launcher.dragon.dragon_launcher import DragonLauncher
from smartsim._core.generation.operations.operations import ConfigureOperation, CopyOperation, SymlinkOperation
from smartsim._core.generation.generator import Generator
from smartsim._core.utils.telemetry.telemetry import JobEntity
from smartsim.database import FeatureStore
from smartsim.entity import Application
Expand Down Expand Up @@ -469,6 +473,58 @@ def check_output_dir() -> None:
def fsutils() -> t.Type[FSUtils]:
return FSUtils

@pytest.fixture
def files(fileutils):
path_to_files = fileutils.get_test_conf_path(
osp.join("generator_files", "easy", "correct/")
)
list_of_files_strs = glob(path_to_files + "/*")
yield [pathlib.Path(str_path) for str_path in list_of_files_strs]


@pytest.fixture
def directory(fileutils):
directory = fileutils.get_test_conf_path(
osp.join("generator_files", "easy", "correct/")
)
yield [pathlib.Path(directory)]


@pytest.fixture(params=["files", "directory"])
def source(request):
yield request.getfixturevalue(request.param)


@pytest.fixture
def mock_src(test_dir: str):
"""Fixture to create a mock source path."""
return pathlib.Path(test_dir) / pathlib.Path("mock_src")


@pytest.fixture
def mock_dest():
"""Fixture to create a mock destination path."""
return pathlib.Path("mock_dest")


@pytest.fixture
def copy_operation(mock_src: pathlib.Path, mock_dest: pathlib.Path):
"""Fixture to create a CopyOperation object."""
return CopyOperation(src=mock_src, dest=mock_dest)


@pytest.fixture
def symlink_operation(mock_src: pathlib.Path, mock_dest: pathlib.Path):
"""Fixture to create a CopyOperation object."""
return SymlinkOperation(src=mock_src, dest=mock_dest)


@pytest.fixture
def configure_operation(mock_src: pathlib.Path, mock_dest: pathlib.Path):
"""Fixture to create a Configure object."""
return ConfigureOperation(
src=mock_src, dest=mock_dest, file_parameters={"FOO": "BAR"}
)

class FSUtils:
@staticmethod
Expand Down
10 changes: 6 additions & 4 deletions smartsim/_core/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class Command(MutableSequence[str]):
"""Basic container for command information"""

def __init__(self, command: t.List[str]) -> None:
if not command:
raise TypeError("Command list cannot be empty")
if not all(isinstance(item, str) for item in command):
raise TypeError("All items in the command list must be strings")
"""Command constructor"""
self._command = command

Expand Down Expand Up @@ -66,17 +70,15 @@ def __setitem__(
"""Set the command at the specified index."""
if isinstance(idx, int):
if not isinstance(value, str):
raise ValueError(
raise TypeError(
"Value must be of type `str` when assigning to an index"
)
self._command[idx] = deepcopy(value)
return
if not isinstance(value, list) or not all(
isinstance(item, str) for item in value
):
raise ValueError(
"Value must be a list of strings when assigning to a slice"
)
raise TypeError("Value must be a list of strings when assigning to a slice")
self._command[idx] = (deepcopy(val) for val in value)

def __delitem__(self, idx: t.Union[int, slice]) -> None:
Expand Down
6 changes: 3 additions & 3 deletions smartsim/_core/commands/command_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ def __setitem__(
"""Set the Commands at the specified index."""
if isinstance(idx, int):
if not isinstance(value, Command):
raise ValueError(
raise TypeError(
"Value must be of type `Command` when assigning to an index"
)
self._commands[idx] = deepcopy(value)
return
if not isinstance(value, list):
raise ValueError(
raise TypeError(
"Value must be a list of Commands when assigning to a slice"
)
for sublist in value:
if not isinstance(sublist.command, list) or not all(
isinstance(item, str) for item in sublist.command
):
raise ValueError(
raise TypeError(
"Value sublists must be a list of Commands when assigning to a slice"
)
self._commands[idx] = (deepcopy(val) for val in value)
Expand Down
5 changes: 2 additions & 3 deletions smartsim/_core/entrypoints/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def copy(parsed_args: argparse.Namespace) -> None:
/absolute/file/dest/path: Path to destination directory or path to
destination file
--dirs_exist_ok: if the flag is included, the copying operation will
continue if the destination directory and files alrady exist,
continue if the destination directory and files already exist,
and will be overwritten by corresponding files. If the flag is
not includedm and the destination file already exists, a
not included and the destination file already exists, a
FileExistsError will be raised
"""
if os.path.isdir(parsed_args.source):
Expand Down Expand Up @@ -226,7 +226,6 @@ def configure(parsed_args: argparse.Namespace) -> None:
for file_name in filenames:
src_file = os.path.join(dirpath, file_name)
dst_file = os.path.join(new_dir_dest, file_name)
print(type(substitutions))
_process_file(substitutions, src_file, dst_file)
else:
dst_file = parsed_args.dest / os.path.basename(parsed_args.source)
Expand Down
Loading

0 comments on commit 30c7d36

Please sign in to comment.