chore: import upstream snapshot with attribution
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import sys
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from lazy_imports import LazyImporter
|
||||
|
||||
_import_structure = {"protocol": ["Marshaller"], "yaml": ["YamlMarshaller"]}
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .protocol import Marshaller as Marshaller
|
||||
from .yaml import YamlMarshaller as YamlMarshaller
|
||||
else:
|
||||
sys.modules[__name__] = LazyImporter(name=__name__, module_file=__file__, import_structure=_import_structure)
|
||||
@@ -0,0 +1,15 @@
|
||||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from typing import Any, Protocol
|
||||
|
||||
|
||||
class Marshaller(Protocol):
|
||||
def marshal(self, dict_: dict[str, Any]) -> str:
|
||||
"Convert a dictionary to its string representation"
|
||||
...
|
||||
|
||||
def unmarshal(self, data_: str | bytes | bytearray) -> dict[str, Any]:
|
||||
"""Convert a marshalled object to its dictionary representation"""
|
||||
...
|
||||
@@ -0,0 +1,45 @@
|
||||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
# Custom YAML safe loader that supports loading Python tuples
|
||||
class YamlLoader(yaml.SafeLoader):
|
||||
def construct_python_tuple(self, node: yaml.SequenceNode) -> tuple:
|
||||
"""Construct a Python tuple from the sequence."""
|
||||
return tuple(self.construct_sequence(node))
|
||||
|
||||
|
||||
class YamlDumper(yaml.SafeDumper):
|
||||
def represent_tuple(self, data: tuple) -> yaml.SequenceNode:
|
||||
"""Represent a Python tuple."""
|
||||
return self.represent_sequence("tag:yaml.org,2002:python/tuple", data)
|
||||
|
||||
|
||||
YamlDumper.add_representer(tuple, YamlDumper.represent_tuple)
|
||||
YamlLoader.add_constructor("tag:yaml.org,2002:python/tuple", YamlLoader.construct_python_tuple)
|
||||
|
||||
|
||||
class YamlMarshaller:
|
||||
def marshal(self, dict_: dict[str, Any]) -> str:
|
||||
"""Return a YAML representation of the given dictionary."""
|
||||
try:
|
||||
return yaml.dump(dict_, Dumper=YamlDumper)
|
||||
except yaml.representer.RepresenterError as e:
|
||||
raise TypeError(
|
||||
"Error dumping pipeline to YAML - Ensure that all pipeline components only serialize basic Python types"
|
||||
) from e
|
||||
|
||||
def unmarshal(self, data_: str | bytes | bytearray) -> dict[str, Any]:
|
||||
"""Return a dictionary from the given YAML data."""
|
||||
try:
|
||||
return yaml.load(data_, Loader=YamlLoader)
|
||||
except yaml.constructor.ConstructorError as e:
|
||||
raise TypeError(
|
||||
"Error loading pipeline from YAML - Ensure that all pipeline "
|
||||
"components only serialize basic Python types"
|
||||
) from e
|
||||
Reference in New Issue
Block a user