Source code for base

"""
Base class of any column map.
"""

from dataclasses import dataclass
from pathlib import Path
import yaml


@dataclass
[docs] class ColumnMap:
[docs] name: str = "Name of column map"
[docs] purpose: str = "Purpose of map"
def __init__(self, name: str, purpose: str): self.name = name self.purpose = purpose
[docs] def mapper_from_glossary(class_name: str, purpose: str, glossary_yaml: Path) -> ColumnMap: """ Given a class name and purpose, creates a class of that name as a specialization of ColumnMap whose attributes are read-only properties informed by the elements of the glossary that specify a variable and an id. """ with open(glossary_yaml) as f_in: glossary = yaml.safe_load(f_in) clazz_attrs = {"__init__": lambda self: ColumnMap.__init__(self, class_name, purpose)} clazz_attrs.update( { x["variable"]: property(fget=lambda s, value=x["column_id"]: value, doc=x["description"]) for x in glossary if "variable" in x } ) clazz = type(class_name, (ColumnMap,), clazz_attrs) return clazz()