Skip to content

Commit

Permalink
Move AutowrapConfigYaml loading to common location
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald committed Sep 30, 2023
1 parent ba5d8b2 commit dcf121b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 11 additions & 0 deletions robotpy_build/config/autowrap_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pydantic import validator
from .util import Model, _generating_documentation
import yaml


class ParamData(Model):
Expand Down Expand Up @@ -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)
13 changes: 2 additions & 11 deletions robotpy_build/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dcf121b

Please sign in to comment.