File size: 526 Bytes
877add7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""Package/local artifact loading."""

from __future__ import annotations

import json
from pathlib import Path
from typing import Any

import yaml


def load_artifact(path: Path) -> Any:
    if path.suffix.lower() in {".json"}:
        return json.loads(path.read_text(encoding="utf-8"))
    if path.suffix.lower() in {".yaml", ".yml"}:
        return yaml.safe_load(path.read_text(encoding="utf-8"))
    if path.suffix.lower() in {".txt", ".md"}:
        return path.read_text(encoding="utf-8")
    return path.read_bytes()