Skip to content

Commit 70617c7

Browse files
authored
Refactor yaml validation schemas (#141)
In the future, we want to include separate validation schemas for each PEtab version in this package
1 parent 5d8f7ff commit 70617c7

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

MANIFEST.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include petab/petab_schema.yaml
2-
recursive-include petab/visualize/templates
1+
recursive-include petab/schemas *.yaml
2+
recursive-include petab/visualize/templates *

petab/yaml.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111

1212
from .C import * # noqa: F403
1313

14-
SCHEMA = os.path.join(os.path.abspath(os.path.dirname(__file__)),
15-
"petab_schema.yaml")
14+
# directory with PEtab yaml schema files
15+
SCHEMA_DIR = Path(__file__).parent / "schemas"
16+
# map of version number to validation schema
17+
SCHEMAS = {
18+
'1': SCHEMA_DIR / "petab_schema.v1.0.0.yaml",
19+
'1.0.0': SCHEMA_DIR / "petab_schema.v1.0.0.yaml",
20+
}
21+
1622
__all__ = ['validate', 'validate_yaml_syntax', 'validate_yaml_semantics',
1723
'load_yaml', 'is_composite_problem',
1824
'assert_single_condition_and_sbml_file', 'write_yaml',
@@ -52,13 +58,17 @@ def validate_yaml_syntax(
5258
Raises:
5359
see jsonschema.validate
5460
"""
61+
yaml_config = load_yaml(yaml_config)
5562

5663
if schema is None:
57-
schema = SCHEMA
64+
# try get PEtab version from yaml file
65+
# if this is not the available, the file is not valid anyways,
66+
# but let's still use the latest PEtab schema for full validation
67+
version = yaml_config.get(FORMAT_VERSION, None) \
68+
or list(SCHEMAS.values())[-1]
69+
schema = SCHEMAS[str(version)]
5870

5971
schema = load_yaml(schema)
60-
yaml_config = load_yaml(yaml_config)
61-
6272
jsonschema.validate(instance=yaml_config, schema=schema)
6373

6474

0 commit comments

Comments
 (0)