tardis.io.configuration.config_validator module¶
Configuration validation module for TARDIS.
This module provides functionality to validate TARDIS configuration files against JSON schemas with support for cross-schema references and custom type checking for Astropy Quantity objects.
- tardis.io.configuration.config_validator.extend_with_default(validator_class: type[Draft7Validator]) type[Draft7Validator] [source]¶
Extend a jsonschema validator to automatically set default values on properties.
By default, jsonschema ignores default values defined in schemas. This function creates an extended validator that will set default values during validation.
- Parameters:
- validator_classtype[Draft7Validator]
The jsonschema validator class to extend (e.g., Draft7Validator)
- Returns:
- type[Draft7Validator]
Extended validator class that sets default values during validation
Notes
The extended validator also properly handles default values in schemas that use the oneOf keyword and validates that default values are of correct types.
- tardis.io.configuration.config_validator.is_quantity(checker: Any, instance: Any) bool [source]¶
Check if the provided instance is of type astropy.units.quantity.Quantity.
This function is used as a custom type checker for jsonschema validation to properly handle Astropy Quantity objects in configuration validation.
- Parameters:
- checkerAny
Object of
TypeChecker
. Passed by jsonschema internally.- instanceAny
The instance to be checked for Quantity type.
- Returns:
- bool
True if the instance is of type astropy.units.quantity.Quantity, False otherwise.
- tardis.io.configuration.config_validator.validate_dict(config_dict: dict[str, Any], schemapath: Path = PosixPath('/home/runner/work/tardis/tardis/tardis/io/configuration/schemas/base.yml'), validator: type[Draft7Validator] = <class 'jsonschema.validators.create.<locals>.Validator'>) dict[str, Any] [source]¶
Validate a configuration dictionary against a JSON schema.
This function validates a configuration dictionary using a JSON schema, with support for cross-file schema references and custom type checking for Astropy Quantity objects. Default values are automatically set according to the schema definition.
- Parameters:
- config_dictdict[str, Any]
The configuration dictionary to validate.
- schemapathPath, optional
Path to the main schema file. Defaults to CONFIG_SCHEMA_FNAME.
- validatortype[Draft7Validator], optional
The validator class to use. Defaults to DefaultDraft7Validator.
- Returns:
- dict[str, Any]
A validated and potentially modified copy of the input dictionary with default values set according to the schema.
- Raises:
- jsonschema.ValidationError
If the configuration dictionary does not conform to the schema.
- jsonschema.SchemaError
If the schema itself is invalid.
Notes
This function creates a deep copy of the input dictionary before validation to avoid modifying the original data.
- tardis.io.configuration.config_validator.validate_yaml(configpath: Path, schemapath: Path = PosixPath('/home/runner/work/tardis/tardis/tardis/io/configuration/schemas/base.yml'), validator: type[Draft7Validator] = <class 'jsonschema.validators.create.<locals>.Validator'>) dict[str, Any] [source]¶
Validate a YAML configuration file against a JSON schema.
This function loads a YAML configuration file and validates it using the validate_dict function. It provides a convenient interface for validating configuration files directly from disk.
- Parameters:
- configpathPath
Path to the YAML configuration file to validate.
- schemapathPath, optional
Path to the main schema file. Defaults to CONFIG_SCHEMA_FNAME.
- validatortype[Draft7Validator], optional
The validator class to use. Defaults to DefaultDraft7Validator.
- Returns:
- dict[str, Any]
A validated configuration dictionary with default values set according to the schema.
- Raises:
- FileNotFoundError
If the configuration file cannot be found.
- yaml.YAMLError
If the YAML file cannot be parsed.
- jsonschema.ValidationError
If the configuration does not conform to the schema.
- jsonschema.SchemaError
If the schema itself is invalid.
Notes
The YAML file is loaded using the custom YAMLLoader which may have specific behavior for handling certain YAML constructs.