chore: import upstream snapshot with attribution
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
Docker image release / Build base image (push) Has been cancelled
Sync docs with Docusaurus / sync (push) Has been cancelled
Tests / Check if changed (push) Has been cancelled
Tests / format (push) Has been cancelled
Tests / check-imports (push) Has been cancelled
Tests / Unit / macos-latest (push) Has been cancelled
Tests / Unit / ubuntu-latest (push) Has been cancelled
Tests / Unit / windows-latest (push) Has been cancelled
Tests / mypy (push) Has been cancelled
Tests / Integration / ubuntu-latest (push) Has been cancelled
Tests / Integration / macos-latest (push) Has been cancelled
Tests / Integration / windows-latest (push) Has been cancelled
Tests / notify-slack-on-failure (push) Has been cancelled
Tests / Mark tests as completed (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
Docker image release / Build base image (push) Has been cancelled
Sync docs with Docusaurus / sync (push) Has been cancelled
Tests / Check if changed (push) Has been cancelled
Tests / format (push) Has been cancelled
Tests / check-imports (push) Has been cancelled
Tests / Unit / macos-latest (push) Has been cancelled
Tests / Unit / ubuntu-latest (push) Has been cancelled
Tests / Unit / windows-latest (push) Has been cancelled
Tests / mypy (push) Has been cancelled
Tests / Integration / ubuntu-latest (push) Has been cancelled
Tests / Integration / macos-latest (push) Has been cancelled
Tests / Integration / windows-latest (push) Has been cancelled
Tests / notify-slack-on-failure (push) Has been cancelled
Tests / Mark tests as completed (push) Has been cancelled
This commit is contained in:
@@ -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