-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensemble.files refactor #746
base: smartsim-refactor
Are you sure you want to change the base?
Changes from all commits
3cac1d1
b6b5022
6e88a40
c93c85d
3866bbd
b2c5421
e221b43
69f7866
143ff4b
cdd82a4
56eb31c
83e015a
70dd2a0
b9c0137
44a3b18
3a2012e
006a430
6c2d908
f87d7cd
5de9628
a7960f1
a6391cf
96c21bd
e937f0d
36e8801
1fe7719
b1dbbb3
f42e208
8c7a767
06f530d
8a9a577
e88f226
d60df2d
d632588
27aa710
2f9838f
7bc70f2
b71871e
87372e1
a8965bd
bd2ac50
6198a14
8ca13c3
c039680
f4e4cdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,165 @@ | ||||||
import pathlib | ||||||
import typing as t | ||||||
from dataclasses import dataclass, field | ||||||
|
||||||
from .operations import default_tag | ||||||
from .utils.helpers import check_src_and_dest_path | ||||||
|
||||||
|
||||||
class EnsembleGenerationProtocol(t.Protocol): | ||||||
"""Protocol for Ensemble Generation Operations.""" | ||||||
|
||||||
src: pathlib.Path | ||||||
"""Path to source""" | ||||||
dest: t.Optional[pathlib.Path] | ||||||
"""Path to destination""" | ||||||
|
||||||
|
||||||
class EnsembleCopyOperation(EnsembleGenerationProtocol): | ||||||
"""Ensemble Copy Operation""" | ||||||
|
||||||
def __init__( | ||||||
self, src: pathlib.Path, dest: t.Optional[pathlib.Path] = None | ||||||
) -> None: | ||||||
"""Initialize a EnsembleCopyOperation object | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the result if the destination path is not supplied. Should this behavior be specified in this docstring? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes I will specify |
||||||
|
||||||
:param src: Path to source | ||||||
:param dest: Path to destination | ||||||
""" | ||||||
check_src_and_dest_path(src, dest) | ||||||
self.src = src | ||||||
"""Path to source""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider being explicit |
||||||
self.dest = dest | ||||||
"""Path to destination""" | ||||||
|
||||||
|
||||||
class EnsembleSymlinkOperation(EnsembleGenerationProtocol): | ||||||
"""Ensemble Symlink Operation""" | ||||||
|
||||||
def __init__( | ||||||
self, src: pathlib.Path, dest: t.Optional[pathlib.Path] = None | ||||||
) -> None: | ||||||
"""Initialize a EnsembleSymlinkOperation object | ||||||
|
||||||
:param src: Path to source | ||||||
:param dest: Path to destination | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the result if the destination path is not supplied. Should this behavior be specified in this docstring? |
||||||
""" | ||||||
check_src_and_dest_path(src, dest) | ||||||
self.src = src | ||||||
"""Path to source""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider being explicit: |
||||||
self.dest = dest | ||||||
"""Path to destination""" | ||||||
|
||||||
|
||||||
class EnsembleConfigureOperation(EnsembleGenerationProtocol): | ||||||
"""Ensemble Configure Operation""" | ||||||
|
||||||
def __init__( | ||||||
self, | ||||||
src: pathlib.Path, | ||||||
file_parameters: t.Mapping[str, t.Sequence[str]], | ||||||
dest: t.Optional[pathlib.Path] = None, | ||||||
tag: t.Optional[str] = None, | ||||||
) -> None: | ||||||
"""Initialize a EnsembleConfigureOperation | ||||||
|
||||||
:param src: Path to source | ||||||
:param file_parameters: File parameters to find and replace | ||||||
:param dest: Path to destination | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the result if the destination path is not supplied. Should this behavior be specified in this docstring? |
||||||
:param tag: Tag to use for find and replacement | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the result if the tag is not supplied. Should this behavior be specified in this docstring? |
||||||
""" | ||||||
check_src_and_dest_path(src, dest) | ||||||
self.src = src | ||||||
"""Path to source""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider being explicit: |
||||||
self.dest = dest | ||||||
"""Path to destination""" | ||||||
self.file_parameters = file_parameters | ||||||
"""File parameters to find and replace""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider being explicit in what file parameters are.
|
||||||
self.tag = tag if tag else default_tag | ||||||
"""Tag to use for the file""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is a tag? |
||||||
|
||||||
|
||||||
EnsembleGenerationProtocolT = t.TypeVar( | ||||||
"EnsembleGenerationProtocolT", bound=EnsembleGenerationProtocol | ||||||
) | ||||||
|
||||||
|
||||||
@dataclass | ||||||
class EnsembleFileSysOperationSet: | ||||||
"""Dataclass to represent a set of Ensemble file system operation objects""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. omit
Suggested change
|
||||||
|
||||||
operations: list[EnsembleGenerationProtocol] = field(default_factory=list) | ||||||
"""Set of Ensemble file system objects that match the EnsembleGenerationProtocol""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. says set but it is a list. might be misleading. consider using list/collection instead |
||||||
|
||||||
def add_copy( | ||||||
self, src: pathlib.Path, dest: t.Optional[pathlib.Path] = None | ||||||
) -> None: | ||||||
"""Add a copy operation to the operations list | ||||||
|
||||||
:param src: Path to source | ||||||
:param dest: Path to destination | ||||||
""" | ||||||
self.operations.append(EnsembleCopyOperation(src, dest)) | ||||||
|
||||||
def add_symlink( | ||||||
self, src: pathlib.Path, dest: t.Optional[pathlib.Path] = None | ||||||
) -> None: | ||||||
"""Add a symlink operation to the operations list | ||||||
|
||||||
:param src: Path to source | ||||||
:param dest: Path to destination | ||||||
""" | ||||||
self.operations.append(EnsembleSymlinkOperation(src, dest)) | ||||||
|
||||||
def add_configuration( | ||||||
self, | ||||||
src: pathlib.Path, | ||||||
file_parameters: t.Mapping[str, t.Sequence[str]], | ||||||
dest: t.Optional[pathlib.Path] = None, | ||||||
tag: t.Optional[str] = None, | ||||||
) -> None: | ||||||
"""Add a configure operation to the operations list | ||||||
|
||||||
:param src: Path to source | ||||||
:param file_parameters: File parameters to find and replace | ||||||
:param dest: Path to destination | ||||||
:param tag: Tag to use for find and replacement | ||||||
""" | ||||||
self.operations.append( | ||||||
EnsembleConfigureOperation(src, file_parameters, dest, tag) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we change the order of these so that it matches the configure method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also I dont know if file_parameters is the best name for what is going in? This is a mapping of the items that need to be found and replaced right? |
||||||
) | ||||||
|
||||||
@property | ||||||
def copy_operations(self) -> list[EnsembleCopyOperation]: | ||||||
"""Property to get the list of copy files. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
:return: List of EnsembleCopyOperation objects | ||||||
""" | ||||||
return self._filter(EnsembleCopyOperation) | ||||||
|
||||||
@property | ||||||
def symlink_operations(self) -> list[EnsembleSymlinkOperation]: | ||||||
"""Property to get the list of symlink files. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
:return: List of EnsembleSymlinkOperation objects | ||||||
""" | ||||||
return self._filter(EnsembleSymlinkOperation) | ||||||
|
||||||
@property | ||||||
def configure_operations(self) -> list[EnsembleConfigureOperation]: | ||||||
"""Property to get the list of configure files. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
:return: List of EnsembleConfigureOperation objects | ||||||
""" | ||||||
return self._filter(EnsembleConfigureOperation) | ||||||
|
||||||
def _filter( | ||||||
self, type: t.Type[EnsembleGenerationProtocolT] | ||||||
) -> list[EnsembleGenerationProtocolT]: | ||||||
"""Filters the operations list to include only instances of the | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
specified type. | ||||||
|
||||||
:param type: The type of operations to filter | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
:return: A list of operations that are instances of the specified type | ||||||
""" | ||||||
return [x for x in self.operations if isinstance(x, type)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider describing the functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better description than my three words eep! will change