forked from ax3l/pydantic-mad
-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] Add test to validate examples in the main PALS repository #55
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
Open
EZoni
wants to merge
6
commits into
pals-project:main
Choose a base branch
from
EZoni:run_examples_from_pals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+78
−13
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
085fc2c
Add test to validate examples in the main PALS repository
EZoni 4e722cc
Merge branch 'main' into run_examples_from_pals
EZoni 22c0f45
Use BeamLine.from_file to read from file
EZoni 82a2486
Start draft of new Lattice class
EZoni 89a5e53
Reexport, rebuild new Lattice class
EZoni d45ba9d
Replace `line` with `branches`, list of `BeamLine`s only
EZoni 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import argparse | ||
|
|
||
| from pals import Lattice | ||
|
|
||
|
|
||
| def main(): | ||
| # Parse command-line arguments | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| "--path", | ||
| required=True, | ||
| help="Path to the example file", | ||
| ) | ||
| args = parser.parse_args() | ||
| example_file = args.path | ||
| # Parse and validate YAML data from file | ||
| Lattice.from_file(example_file) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from pydantic import model_validator | ||
| from typing import List, Literal | ||
|
|
||
| from .all_elements import get_all_elements_as_annotation | ||
| from .mixin import BaseElement | ||
| from ..functions import load_file_to_dict, store_dict_to_file | ||
|
|
||
|
|
||
| class Lattice(BaseElement): | ||
| """A line of elements and/or other lines""" | ||
|
|
||
| kind: Literal["Lattice"] = "Lattice" | ||
|
|
||
| branches: List[Annotated[Union[BeamLine], Field(discriminator="kind")]] | ||
|
|
||
| @model_validator(mode="before") | ||
| @classmethod | ||
| def unpack_json_structure(cls, data): | ||
| """Deserialize the JSON/YAML/...-like dict for Lattice elements""" | ||
| from pals.kinds.mixin.all_element_mixin import unpack_element_list_structure | ||
|
|
||
| return unpack_element_list_structure(data, "line", "line") | ||
|
|
||
| def model_dump(self, *args, **kwargs): | ||
| """Custom model dump for Lattice to handle element list formatting""" | ||
| from pals.kinds.mixin.all_element_mixin import dump_element_list | ||
|
|
||
| return dump_element_list(self, "line", *args, **kwargs) | ||
|
|
||
| @staticmethod | ||
| def from_file(filename: str) -> "Lattice": | ||
| """Load a Lattice from a text file""" | ||
| pals_dict = load_file_to_dict(filename) | ||
| return Lattice(**pals_dict) | ||
|
|
||
| def to_file(self, filename: str): | ||
| """Save a Lattice to a text file""" | ||
| pals_dict = self.model_dump() | ||
| store_dict_to_file(filename, pals_dict) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
For stability (avoid triggering limits), we want to use the GH action
checkoutfor all checkouts.It supports sub-options for creating the clone in a specific folder. It also supports sparse checkouts and shallow fetch depths.
https://github.com/actions/checkout?tab=readme-ov-file#checkout-v6