-
Notifications
You must be signed in to change notification settings - Fork 9
Fix PEtab v2 extension config model #506
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f87b31d
Fix PEtab v2 extension config model (#474)
dweindl 3cd3654
less verbose
dweindl 0429b0e
Apply suggestions from code review
dweindl 5857b79
Merge branch 'main' into fix/v2-extension-config
dweindl 9932e36
fixup
dweindl d826906
Fix CI regression and decouple extension parsing from core.py
dweindl 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,46 @@ | ||
| from pydantic import BaseModel, ConfigDict | ||
|
|
||
| __all__ = ["ExtensionConfig", "parse_extension_config"] | ||
|
|
||
|
|
||
| class ExtensionConfig(BaseModel): | ||
| """The configuration of a PEtab extension.""" | ||
|
|
||
| #: The extension's semantic version. | ||
| version: str | ||
| #: Whether the extension is required for the mathematical | ||
| #: interpretation of the problem. | ||
| required: bool | ||
|
|
||
| model_config = ConfigDict(extra="allow", validate_assignment=True) | ||
|
|
||
|
|
||
| def _extension_config_classes() -> dict[str, type[ExtensionConfig]]: | ||
| """Registry of extension ID to its specific :class:`ExtensionConfig` | ||
| subclass, if any. | ||
|
|
||
| Imported lazily (rather than built at module level) to avoid a | ||
| circular import: extension submodules (e.g. ``sciml``) import | ||
| :class:`ExtensionConfig` from this package. | ||
| """ | ||
| from .. import C | ||
| from .sciml import SciMLConfig | ||
|
|
||
| return {C.EXT_ID_SCIML: SciMLConfig} | ||
|
|
||
|
|
||
| def parse_extension_config( | ||
| ext_id: str, config: dict | ExtensionConfig | ||
| ) -> ExtensionConfig: | ||
| """Parse a single extension's configuration. | ||
|
|
||
| Converts ``config`` to the extension-specific :class:`ExtensionConfig` | ||
| subclass registered for ``ext_id``, or to the generic | ||
| :class:`ExtensionConfig` if no specific subclass is registered. | ||
|
|
||
| :param ext_id: The extension ID. | ||
| :param config: The extension's configuration, as a dict or an already | ||
| parsed :class:`ExtensionConfig` (sub)instance. | ||
| """ | ||
| cls = _extension_config_classes().get(ext_id, ExtensionConfig) | ||
| return config if isinstance(config, cls) else cls(**config) |
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 |
|---|---|---|
|
|
@@ -157,6 +157,26 @@ def test_lint(): | |
| assert problem.validate() == [] | ||
|
|
||
|
|
||
| def test_sciml_config_yaml_round_trip(tmp_path): | ||
| """The `sciml` extension config, once written to YAML via | ||
| `ProblemConfig.to_yaml()`, is schema-valid and can be read back. | ||
| """ | ||
| from petab.v1.yaml import load_yaml, validate_yaml_syntax | ||
|
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. Strange to see
Member
Author
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. I am fine with moving them to a common module, but not in this PR. |
||
|
|
||
| problem = _get_test_problem() | ||
| yaml_path = tmp_path / "problem.yaml" | ||
| problem.config.to_yaml(yaml_path) | ||
|
|
||
| yaml_config = load_yaml(yaml_path) | ||
| validate_yaml_syntax(yaml_config) | ||
| assert yaml_config["extensions"]["sciml"]["required"] is True | ||
|
|
||
| reloaded_config = ProblemConfig(**yaml_config, base_path=tmp_path) | ||
| sciml_config = reloaded_config.extensions["sciml"] | ||
| assert isinstance(sciml_config, SciMLConfig) | ||
| assert sciml_config.required is True | ||
|
|
||
|
|
||
| def test_lint_equinox_network_format(): | ||
| """Linter accepts non-YAML formats without reading the network file.""" | ||
| problem = _get_test_problem() | ||
|
|
||
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.