Skip to content

load_validate

trestle.common.load_validate ¤

Function to load and validate files while avoiding circular imports.

Attributes¤

logger = logging.getLogger(__name__) module-attribute ¤

Classes¤

Functions¤

load_validate_model_name(trestle_root, model_name, model_class, file_content_type=None) ¤

Load a model by its name and type and validate it.

Source code in trestle/common/load_validate.py
42
43
44
45
46
47
48
49
50
51
def load_validate_model_name(
    trestle_root: Path,
    model_name: str,
    model_class: TG,
    file_content_type: Optional[FileContentType] = None
) -> Tuple[TG, Path]:
    """Load a model by its name and type and validate it."""
    model_path = ModelUtils.get_model_path_for_name_and_class(trestle_root, model_name, model_class, file_content_type)
    model = load_validate_model_path(trestle_root, model_path)
    return model, model_path

load_validate_model_path(trestle_root, model_path) ¤

Load a model by its path and validate it.

Source code in trestle/common/load_validate.py
32
33
34
35
36
37
38
39
def load_validate_model_path(trestle_root: Path, model_path: Path) -> TopLevelOscalModel:
    """Load a model by its path and validate it."""
    _, _, model = ModelUtils.load_distributed(model_path, trestle_root)
    args = argparse.Namespace(mode=const.VAL_MODE_ALL, quiet=True)
    validator: Validator = validator_factory.get(args)
    if not validator.model_is_valid(model, True, trestle_root):
        logger.warning(f'Model loaded at {model_path} fails validation, but is being loaded anyway.')
    return model

handler: python