-
Notifications
You must be signed in to change notification settings - Fork 0
feature/SOF 7878 #142
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
Merged
Merged
feature/SOF 7878 #142
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1757cf9
update: add generic convergence
VsevolodX 7a52ce4
update: add test
VsevolodX a0940f2
update: multi unit
VsevolodX ba005c2
update: input item
VsevolodX 23406e1
update: use input item
VsevolodX 0e8d86f
update: adjust convergence mixin
VsevolodX c75cbe0
chore: lint
VsevolodX 859d81b
update: add test for inputs
VsevolodX 6bafefc
chore: renanme param -> parameter
VsevolodX e03be6e
chore: use existing approach
VsevolodX 73dc01c
chore: simplify
VsevolodX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,65 @@ | ||
| from typing import Any, Dict, List, Literal | ||
|
|
||
| from mat3ra.ade import Application, Executable, Flavor | ||
| from mat3ra.ade import Application, Executable, Flavor, Template | ||
| from mat3ra.code.entity import InMemoryEntitySnakeCase | ||
| from mat3ra.esse.models.workflow.unit.execution import ExecutionUnitSchemaBase | ||
| from mat3ra.utils import ( | ||
| calculate_hash_from_object, | ||
| remove_comments_from_source_code, | ||
| remove_empty_lines_from_string, | ||
| remove_timestampable_keys, | ||
| ) | ||
| from pydantic import Field | ||
| from pydantic import Field, model_serializer, model_validator | ||
|
|
||
| from .unit import Unit | ||
|
|
||
| _ITEM_KEYS = {"rendered", "isManuallyChanged"} | ||
|
|
||
|
|
||
| # TODO: use from ESSE when epic/SOF-7756 merged | ||
| class ExecutionUnitInputItem(InMemoryEntitySnakeCase): | ||
|
Member
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. Remove |
||
| template: Template = Field(default_factory=Template) | ||
| rendered: str = "" | ||
| isManuallyChanged: bool = False | ||
|
|
||
| @model_validator(mode="before") | ||
| @classmethod | ||
| def from_flat(cls, data: Any) -> Any: | ||
| if isinstance(data, dict) and "template" not in data: | ||
| return { | ||
| "template": {k: v for k, v in data.items() if k not in _ITEM_KEYS}, | ||
| "rendered": data.get("rendered", ""), | ||
| "isManuallyChanged": data.get("isManuallyChanged", False), | ||
| } | ||
| return data | ||
|
|
||
| @model_serializer(mode="plain") | ||
| def to_flat(self) -> Dict[str, Any]: | ||
| return {**self.template.to_dict(), "rendered": self.rendered, "isManuallyChanged": self.isManuallyChanged} | ||
|
|
||
|
|
||
| class ExecutionUnit(Unit, ExecutionUnitSchemaBase): | ||
| type: Literal["execution"] = "execution" | ||
| executable: Executable = None | ||
| flavor: Flavor = None | ||
| application: Application = None | ||
| input: List = Field(default_factory=list) | ||
| input: List[ExecutionUnitInputItem] = Field(default_factory=List[ExecutionUnitInputItem]) | ||
|
|
||
| def replace_in_input_content(self, pattern: str, replacement: str) -> None: | ||
| for input_item in self.input: | ||
| input_item.template.replace_in_content(pattern, replacement) | ||
|
|
||
| def replace_variable_value_in_inputs(self, variable_name: str, new_value: str) -> None: | ||
| for input_item in self.input: | ||
| input_item.template.replace_variable_value(variable_name, new_value) | ||
|
|
||
| def get_hash_object(self) -> Dict[str, Any]: | ||
| app = self.application.to_dict() if self.application else {} | ||
| exe = self.executable.to_dict() if self.executable else {} | ||
| flv = self.flavor.to_dict() if self.flavor else {} | ||
| input_items = self.input if isinstance(self.input, list) else [] | ||
| input_hash = calculate_hash_from_object( | ||
| [ | ||
| remove_empty_lines_from_string(remove_comments_from_source_code(i.get("content", ""))) | ||
| for i in input_items | ||
| if isinstance(i, dict) | ||
| ] | ||
| [remove_empty_lines_from_string(remove_comments_from_source_code(i.template.content)) for i in input_items] | ||
| ) | ||
| return { | ||
| **super().get_hash_object(), | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remove