diff --git a/robotpy_build/config/autowrap_yml.py b/robotpy_build/config/autowrap_yml.py index d26b4a95..d0063176 100644 --- a/robotpy_build/config/autowrap_yml.py +++ b/robotpy_build/config/autowrap_yml.py @@ -8,6 +8,7 @@ from pydantic import validator from .util import Model, _generating_documentation +import yaml class ParamData(Model): @@ -577,3 +578,13 @@ def validate_functions(cls, value): if v is None: value[k] = FunctionData() return value + + @classmethod + def from_file(cls, fname) -> "AutowrapConfigYaml": + with open(fname) as fp: + data = yaml.safe_load(fp) + + if data is None: + data = {} + + return cls(**data) diff --git a/robotpy_build/wrapper.py b/robotpy_build/wrapper.py index 7caa736f..87c0490c 100644 --- a/robotpy_build/wrapper.py +++ b/robotpy_build/wrapper.py @@ -586,15 +586,6 @@ def get_type_casters(casters): self._add_addl_data_file(fname) - def _load_generation_data(self, datafile): - with open(datafile) as fp: - data = yaml.safe_load(fp) - - if data is None: - data = {} - - return AutowrapConfigYaml(**data) - def on_build_gen( self, cxx_gen_dir, missing_reporter: Optional[MissingReporter] = None ): @@ -637,7 +628,7 @@ def on_build_gen( datapath = join(self.setup_root, normpath(self.cfg.generation_data)) per_header = isdir(datapath) if not per_header: - data = self._load_generation_data(datapath) + data = AutowrapConfigYaml.from_file(datapath) else: data = AutowrapConfigYaml() @@ -694,7 +685,7 @@ def on_build_gen( print("WARNING: could not find", data_fname) data = AutowrapConfigYaml() else: - data = self._load_generation_data(data_fname) + data = AutowrapConfigYaml.from_file(data_fname) # split instantiation of each template to separate cpp files to reduce # compiler memory for really obscene objects