in terranova/resources.py [0:0]
def from_file(path: Path) -> "ResourcesManifest":
"""
Read a resources manifest
Args:
path: path to manifest.
Raises:
MissingManifestError: if the manifest is missing.
UnreadableManifestError: if the manifest can't be read.
VersionManifestError: if the version manifest isn't supported.
InvalidManifestError: if the manifest isn't invalid.
"""
if not path.exists() or not path.is_file():
raise MissingManifestError(path)
if not os.access(path.as_posix(), os.R_OK):
raise UnreadableManifestError(path)
with path.open(
Constants.FILE_MODE_READ, encoding=Constants.ENCODING_UTF_8
) as file_descriptor:
try:
data = yaml.safe_load(file_descriptor)
except yaml.YAMLError as err:
raise InvalidManifestError(path) from err
# Check version
version = data.get("version", "1.0")
# Get configuration schema
try:
schema = pkgutil.get_data(
__name__, f"schemas/manifest_schema_v{version}.json"
)
if not schema:
raise FileNotFoundError(
f"The schema `schemas/manifest_schema_v{version}.json` can't be found"
)
except FileNotFoundError as err:
raise VersionManifestError(version) from err
schema = json.loads(schema)
# Validate manifest
try:
validate(instance=data, schema=schema)
except ValidationError as err:
raise InvalidManifestError(path) from err
# noinspection PyUnresolvedReferences
return ResourcesManifest.from_dict(data) # type: ignore[attr-defined]