11from os import PathLike
2- from pathlib import Path
32from typing import TextIO , Union
43from harp .model import Model , Registers
54from pydantic_yaml import parse_yaml_raw_as
5+ from importlib import resources
66
7- _common_yaml_path = Path (__file__ ).absolute ().parent .joinpath ("common.yml" )
87
9-
10- def _read_common_registers (file : Union [str , PathLike , TextIO ]) -> Registers :
11- if isinstance (file , TextIO ):
12- return parse_yaml_raw_as (Registers , file .read ())
13- else :
14- with open (file ) as fileIO :
15- return _read_common_registers (fileIO )
8+ def _read_common_registers () -> Registers :
9+ file = resources .files (__package__ ) / "common.yml"
10+ with file .open ("rt" ) as fileIO :
11+ return parse_yaml_raw_as (Registers , fileIO .read ())
1612
1713
1814def read_schema (
@@ -21,7 +17,7 @@ def read_schema(
2117 if isinstance (file , TextIO ):
2218 schema = parse_yaml_raw_as (Model , file .read ())
2319 if not "WhoAmI" in schema .registers and include_common_registers :
24- common = _read_common_registers (_common_yaml_path )
20+ common = _read_common_registers ()
2521 schema .registers = dict (common .registers , ** schema .registers )
2622 if schema .bitMasks is not None and common .bitMasks is not None :
2723 schema .bitMasks = dict (common .bitMasks , ** schema .bitMasks )
0 commit comments