move html and json io managers
This commit is contained in:
20
shared/src/shared/io_manager/html.py
Normal file
20
shared/src/shared/io_manager/html.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from shared.io_manager.base import BaseIOManager
|
||||
from upath import UPath
|
||||
|
||||
import dagster as dg
|
||||
|
||||
|
||||
class HtmlIOManager(BaseIOManager):
|
||||
extension: str = ".html" # 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:
|
||||
fp.write(obj)
|
||||
|
||||
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 fp.read()
|
||||
22
shared/src/shared/io_manager/json.py
Normal file
22
shared/src/shared/io_manager/json.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import json
|
||||
|
||||
from shared.io_manager.base import BaseIOManager
|
||||
from upath import UPath
|
||||
|
||||
import dagster as dg
|
||||
|
||||
|
||||
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