Skip to content

Commit

Permalink
Merge pull request #2 from eccenca/feature/update
Browse files Browse the repository at this point in the history
update deps + template & enable entities output
  • Loading branch information
seebi authored Feb 16, 2024
2 parents 42b059d + e8cc971 commit ef68e2f
Show file tree
Hide file tree
Showing 7 changed files with 452 additions and 299 deletions.
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: cmempy-developer@eccenca.com
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

0 comments on commit ef68e2f

Please sign in to comment.