-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add custom validation extension #108
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
khalsz
wants to merge
1
commit into
iterorganization:main
Choose a base branch
from
khalsz:feature/validation-extension
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.
+54
−30
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| import click | ||
| from pathlib import Path | ||
| from typing import Optional, List, Tuple, Any, Type | ||
| from typing import Any, List, Optional, Tuple, Type | ||
|
|
||
| import click | ||
|
|
||
| from . import pass_config, check_meta_args | ||
| from ...config.config import Config | ||
| from ...query import QueryType, parse_query_arg | ||
| from . import check_meta_args, pass_config | ||
| from .validators import validate_non_negative | ||
|
Contributor
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 could not get motivation of adding custom validation. Could you please share use case where you think ITER scenarios validation is more aggressive? |
||
|
|
||
|
|
||
| # def _validate_simulation_outputs(options: dict, simulation): | ||
| # file_validator_type = options.get("file_validator", None) | ||
| # file_validator_options = options.get("file_validator_options", {}) | ||
|
|
@@ -170,9 +170,10 @@ def simulation_info(config: Config, sim_id: str): | |
| def simulation_ingest(config: Config, manifest_file: str, alias: str): | ||
| """Ingest a MANIFEST_FILE.""" | ||
| import urllib.parse | ||
|
|
||
| from ...database import get_local_db | ||
| from ...database.models import Simulation | ||
| from ..manifest import Manifest, InvalidAlias | ||
| from ..manifest import InvalidAlias, Manifest | ||
|
|
||
| manifest = Manifest() | ||
| manifest.load(Path(manifest_file)) | ||
|
|
@@ -233,10 +234,11 @@ def simulation_push( | |
| add_watcher: bool, | ||
| ): | ||
| """Push the simulation with the given SIM_ID (UUID or alias) to the REMOTE.""" | ||
| import sys | ||
|
|
||
| from ...database import get_local_db | ||
| from ...validation import ValidationError, Validator | ||
| from ..remote_api import RemoteAPI | ||
| from ...validation import Validator, ValidationError | ||
| import sys | ||
|
|
||
| api = RemoteAPI(remote, username, password, config) | ||
| db = get_local_db(config) | ||
|
|
@@ -251,7 +253,7 @@ def simulation_push( | |
| schemas = api.get_validation_schemas() | ||
| try: | ||
| for schema in schemas: | ||
| Validator(schema).validate(simulation) | ||
| Validator(schema, config).validate(simulation) | ||
| except ValidationError as err: | ||
| raise click.ClickException(f"Simulation does not validate: {err}") | ||
|
|
||
|
|
@@ -279,10 +281,11 @@ def simulation_pull( | |
| password: Optional[str], | ||
| ): | ||
| """Pull the simulation with the given SIM_ID (UUID or alias) from the REMOTE.""" | ||
| from ...database import get_local_db, DatabaseError | ||
| from ..remote_api import RemoteAPI, RemoteError | ||
| import sys | ||
|
|
||
| from ...database import DatabaseError, get_local_db | ||
| from ..remote_api import RemoteAPI, RemoteError | ||
|
|
||
| api = RemoteAPI(remote, username, password, config) | ||
| db = get_local_db(config) | ||
|
|
||
|
|
@@ -323,7 +326,9 @@ def simulation_pull( | |
| help="Include UUID in the output.", | ||
| default=False, | ||
| ) | ||
| def simulation_query(config: Config, constraints: List[str], meta: List[str], show_uuid: bool): | ||
| def simulation_query( | ||
| config: Config, constraints: List[str], meta: List[str], show_uuid: bool | ||
| ): | ||
| """Perform a metadata query to find matching local simulations. | ||
|
|
||
| \b | ||
|
|
@@ -381,7 +386,9 @@ def simulation_query(config: Config, constraints: List[str], meta: List[str], sh | |
|
|
||
| db = get_local_db(config) | ||
| simulations = db.query_meta(parsed_constraints) | ||
| print_simulations(simulations, verbose=config.verbose, metadata_names=names, show_uuid=show_uuid) | ||
| print_simulations( | ||
| simulations, verbose=config.verbose, metadata_names=names, show_uuid=show_uuid | ||
| ) | ||
|
|
||
|
|
||
| @simulation.command("validate", cls=n_required_args_adaptor(1)) | ||
|
|
@@ -395,6 +402,7 @@ def simulation_validate( | |
| ): | ||
| """Validate the ingested simulation with given SIM_ID (UUID or alias) using validation schema from REMOTE.""" | ||
| from itertools import chain | ||
|
|
||
| from ...database import get_local_db | ||
| from ...validation import ValidationError, Validator | ||
| from ..remote_api import RemoteAPI | ||
|
|
@@ -410,7 +418,7 @@ def simulation_validate( | |
|
|
||
| click.echo("validating metadata ... ", nl=False) | ||
| for schema in schemas: | ||
| Validator(schema).validate(simulation) | ||
| Validator(schema, config).validate(simulation) | ||
|
|
||
| ids_list = [] | ||
| for file in chain(simulation.inputs, simulation.outputs): | ||
|
|
||
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
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.
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.
I think we can keep old code without formatting as this will be a patch? And we could better understand the real changes related to addition of custom validator.