move html and json io managers
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from shared.resources import BaseIOManager
|
||||
from upath import UPath
|
||||
|
||||
import dagster as dg
|
||||
|
||||
|
||||
def _process_env_vars(config: dict[str, Any]) -> dict[str, Any]:
|
||||
out = {}
|
||||
for key, value in config.items():
|
||||
if (
|
||||
isinstance(value, dict)
|
||||
and len(value) == 1
|
||||
and next(iter(value.keys())) == "env"
|
||||
):
|
||||
out[key] = dg.EnvVar(next(iter(value.values()))).get_value()
|
||||
else:
|
||||
out[key] = value
|
||||
return out
|
||||
|
||||
|
||||
class JsonIOManager(BaseIOManager):
|
||||
extension: str = ".json" # Automatically adds a .json extension
|
||||
|
||||
def dump_to_path(
|
||||
self, context: dg.OutputContext, obj: object, path: "UPath"
|
||||
) -> None:
|
||||
"""This saves the output of an asset to a file path."""
|
||||
with path.open("w") as fp:
|
||||
json.dump(obj, fp, indent=4)
|
||||
|
||||
def load_from_path(self, context: dg.InputContext, path: "UPath") -> object:
|
||||
"""This loads an input for a downstream asset from a file path."""
|
||||
with path.open("r") as fp:
|
||||
return json.load(fp)
|
||||
Reference in New Issue
Block a user