Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update deps + template & enable entities output #2

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: v6.0.1
_commit: v6.1.0
_src_path: gh:eccenca/cmem-plugin-template
author_mail: [email protected]
author_name: eccenca GmbH
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ tasks:
desc: Complain about everything else
<<: *preparation
cmds:
- poetry run ruff check --show-source tests {{.PACKAGE}}
- poetry run ruff check --exit-zero tests {{.PACKAGE}} {{.XML_PARAMS}}
- poetry run ruff check --show-source tests {{.PACKAGE}}
- poetry run ruff format --check tests {{.PACKAGE}}
vars:
JUNIT_FILE: ./{{.DIST_DIR}}/junit-ruff.xml
Expand Down
21 changes: 14 additions & 7 deletions cmem_plugin_yaml/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
from cmem_plugin_base.dataintegration.ports import (
FixedNumberOfInputs,
FixedSchemaPort,
FlexibleSchemaPort,
UnknownSchemaPort,
)
from cmem_plugin_base.dataintegration.utils import setup_cmempy_user_access
from cmem_plugin_base.dataintegration.utils.entity_builder import build_entities_from_data

SOURCE = SimpleNamespace()
SOURCE.entities = "entities"
Expand All @@ -40,7 +41,7 @@
SOURCE.options = OrderedDict(
{
SOURCE.entities: f"{SOURCE.entities}: "
"Content is parsed from of the input port in a workflow (default).",
"Content is parsed from of the input port in a workflow.",
SOURCE.code: f"{SOURCE.code}: " "Content is parsed from the YAML code field below.",
SOURCE.file: f"{SOURCE.file}: "
"Content is parsed from an uploaded project file resource (see advanced options).",
Expand All @@ -54,12 +55,11 @@
TARGET.options = OrderedDict(
{
TARGET.json_entities: f"{TARGET.json_entities}: "
"Parsed structure will be sent as JSON entities to the output port (current default).",
"Parsed structure will be sent as JSON entities to the output port.",
TARGET.json_dataset: f"{TARGET.json_dataset}: "
"Parsed structure will be is saved in a JSON dataset (see advanced options).",
TARGET.entities: f"{TARGET.entities}: "
"Parsed structure will be send as entities to the output port "
"(not implemented yet, later default).",
"Parsed structure will be send as entities to the output port.",
}
)

Expand All @@ -78,13 +78,14 @@
label="Source / Input Mode",
description="",
param_type=ChoiceParameterType(SOURCE.options),
default_value=SOURCE.code,
),
PluginParameter(
name="target_mode",
label="Target / Output Mode",
description="",
param_type=ChoiceParameterType(TARGET.options),
default_value=TARGET.json_entities,
default_value=TARGET.entities,
),
PluginParameter(
name="source_code",
Expand Down Expand Up @@ -199,7 +200,7 @@ def _set_ports(self) -> None:
match self.target_mode:
case TARGET.entities:
# output port with flexible schema
self.output_port = FlexibleSchemaPort()
self.output_port = UnknownSchemaPort()
case TARGET.json_entities:
# output port with fixed schema
self.output_port = FixedSchemaPort(
Expand Down Expand Up @@ -310,6 +311,12 @@ def _provide_output_json_dataset(self, file_json: Path) -> None:
)
)

@staticmethod
def _provide_output_entities(file_json: Path) -> Entities | None:
"""Output as entities"""
data = json.loads(Path.open(file_json, encoding="utf-8").read())
return build_entities_from_data(data=data)

def _provide_output(self, file_json: Path) -> Entities | None:
"""Depending on configuration, provides the parsed content for different outputs"""
try:
Expand Down
Loading
Loading