Skip to content

Commit

Permalink
Make it possible to pass another sources dict to DataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
e-belfer committed Jan 7, 2025
1 parent 60e55d0 commit e04ffb7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/pudl/metadata/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,20 +1035,22 @@ def to_rst(
sys.stdout.write(rendered)

@classmethod
def from_field_namespace(cls, x: str) -> list["DataSource"]:
def from_field_namespace(
cls, x: str, sources: dict[str, Any] = SOURCES
) -> list["DataSource"]:
"""Return list of DataSource objects by field namespace."""
return [
cls(**cls.dict_from_id(name))
for name, val in SOURCES.items()
for name, val in sources.items()
if val.get("field_namespace") == x
]

@staticmethod
def dict_from_id(x: str) -> dict:
def dict_from_id(x: str, sources: dict[str, Any] = SOURCES) -> dict:
"""Look up the source by source name in the metadata."""
# If ID ends with _xbrl strip end to find data source
lookup_id = x.replace("_xbrl", "")
return {"name": x, **copy.deepcopy(SOURCES[lookup_id])}
return {"name": x, **copy.deepcopy(sources[lookup_id])}

@classmethod
def from_id(cls, x: str) -> "DataSource":
Expand Down Expand Up @@ -1285,6 +1287,7 @@ class Resource(PudlMeta):
"pudl",
"nrelatb",
"vcerare",
"phmsagas",
]
| None
) = None
Expand Down Expand Up @@ -1313,6 +1316,7 @@ class Resource(PudlMeta):
"service_territories",
"nrelatb",
"vcerare",
"phmsagas",
]
| None
) = None
Expand Down

0 comments on commit e04ffb7

Please sign in to comment.