Skip to content

load_validate

trestle.common.load_validate ¤

Function to load and validate files while avoiding circular imports.

logger ¤

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
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.path_for_top_level_model(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
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):
        logger.warning(f'Model loaded at {model_path} fails validation, but is being loaded anyway.')
    return model

handler: python