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 to the new plugins system in core #20

Merged
merged 4 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Furthermore, the repository will contain **dummy/demo** strategies for each of t
- Mapping (`mappingType`)
- Parse (`mediaType`)
- Resource (`accessService`)
- Transformation (`transformation_type`)
- Transformation (`transformationType`)

These should be **updated** to **your specific needs** according to the strategy or strategies you intend to implement.
The ones that are not used should be deleted.
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.project_slug }}/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
oteapi-core==0.0.4
oteapi-core==0.0.5
24 changes: 12 additions & 12 deletions {{ cookiecutter.project_slug }}/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[options.entry_points]
oteapi.download_strategy =
{{ cookiecutter.package_name }}.demo = {{ cookiecutter.package_name }}.strategies.download
oteapi.filter_strategy =
{{ cookiecutter.package_name }}.demo = {{ cookiecutter.package_name }}.strategies.filter
oteapi.mapping_strategy =
{{ cookiecutter.package_name }}.demo = {{ cookiecutter.package_name }}.strategies.mapping
oteapi.resource_strategy =
{{ cookiecutter.package_name }}.demo = {{ cookiecutter.package_name }}.strategies.resource
oteapi.transformation_strategy =
{{ cookiecutter.package_name }}.demo = {{ cookiecutter.package_name }}.strategies.transformation
oteapi.parse_strategy =
{{ cookiecutter.package_name }}.demo = {{ cookiecutter.package_name }}.strategies.parse
oteapi.download =
{{ cookiecutter.package_name }}.fileDEMO = {{ cookiecutter.package_name }}.strategies.download:DemoFileStrategy
oteapi.filter =
{{ cookiecutter.package_name }}.filter/DEMO = {{ cookiecutter.package_name }}.strategies.filter:DemoFilter
oteapi.mapping =
{{ cookiecutter.package_name }}.mapping/DEMO = {{ cookiecutter.package_name }}.strategies.mapping:DemoMappingStrategy
oteapi.parse =
{{ cookiecutter.package_name }}.text/jsonDEMO = {{ cookiecutter.package_name }}.strategies.parse:DemoJSONDataParseStrategy
oteapi.resource =
{{ cookiecutter.package_name }}.DEMO-access-service = {{ cookiecutter.package_name }}.strategies.resource:DemoResourceStrategy
oteapi.transformation =
{{ cookiecutter.package_name }}.script/DEMO = {{ cookiecutter.package_name }}.strategies.transformation:DummyTransformationStrategy
6 changes: 3 additions & 3 deletions {{ cookiecutter.project_slug }}/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@pytest.fixture(scope="session", autouse=True)
def load_plugins() -> None:
"""Load plugins."""
from oteapi.plugins.plugins import load_plugins
"""Load pip installed plugin strategies."""
from oteapi.plugins.factories import load_strategies

load_plugins()
load_strategies()
2 changes: 1 addition & 1 deletion {{ cookiecutter.project_slug }}/tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def test_json():
mediaType="text/jsonDEMO",
)
parser = DemoJSONDataParseStrategy(config)
json = parser.parse()
json = parser.get()

assert json == data
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Optional

from oteapi.datacache.datacache import DataCache
from oteapi.plugins.factories import StrategyFactory
from oteapi.datacache import DataCache
from pydantic import BaseModel, Extra, Field

if TYPE_CHECKING:
Expand Down Expand Up @@ -33,11 +32,10 @@ class FileConfig(BaseModel):


@dataclass
@StrategyFactory.register(("scheme", "fileDEMO"))
class DemoFileStrategy:
"""Strategy for retrieving data via local file."""

resource_config: "ResourceConfig"
download_config: "ResourceConfig"

def initialize(
self, session: "Optional[Dict[str, Any]]" = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, List

from oteapi.plugins.factories import StrategyFactory
from pydantic import BaseModel, Field

if TYPE_CHECKING:
Expand All @@ -19,7 +18,6 @@ class DemoDataModel(BaseModel):


@dataclass
@StrategyFactory.register(("filterType", "filter/DEMO"))
class DemoFilter:
"""Filter Strategy."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING

from oteapi.plugins.factories import StrategyFactory

if TYPE_CHECKING:
from typing import Any, Dict, Optional

from oteapi.models.mappingconfig import MappingConfig


@dataclass
@StrategyFactory.register(("mappingType", "mapping/DEMO"))
class DemoMappingStrategy:
"""Mapping Strategy."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING

from oteapi.datacache.datacache import DataCache
from oteapi.plugins.factories import StrategyFactory, create_download_strategy
from oteapi.datacache import DataCache
from oteapi.plugins import create_strategy

if TYPE_CHECKING:
from typing import Any, Dict, Optional
Expand All @@ -14,11 +14,10 @@


@dataclass
@StrategyFactory.register(("mediaType", "text/jsonDEMO"))
class DemoJSONDataParseStrategy:
"""Parse Strategy."""

resource_config: "ResourceConfig"
parse_config: "ResourceConfig"

def initialize(
self, session: "Optional[Dict[str, Any]]" = None
Expand All @@ -38,7 +37,7 @@ def initialize(
"""
return {}

def parse(self, session: "Optional[Dict[str, Any]]" = None) -> "Dict[str, Any]":
def get(self, session: "Optional[Dict[str, Any]]" = None) -> "Dict[str, Any]":
"""Execute the strategy.

This method will be called through the strategy-specific endpoint of the
Expand All @@ -52,7 +51,7 @@ def parse(self, session: "Optional[Dict[str, Any]]" = None) -> "Dict[str, Any]":
dictionary context.

"""
downloader = create_download_strategy(self.resource_config)
downloader = create_strategy("download", self.resource_config)
CasperWA marked this conversation as resolved.
Show resolved Hide resolved
output = downloader.get()
cache = DataCache(self.resource_config.configuration)
CasperWA marked this conversation as resolved.
Show resolved Hide resolved
content = cache.get(output["key"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING

from oteapi.plugins.factories import StrategyFactory, create_download_strategy
from oteapi.plugins import create_strategy

if TYPE_CHECKING:
from typing import Any, Dict, Optional
Expand All @@ -12,7 +12,6 @@


@dataclass
@StrategyFactory.register(("accessService", "DEMO-access-service"))
class DemoResourceStrategy:
"""Resource Strategy."""

Expand Down Expand Up @@ -51,6 +50,6 @@ def get(self, session: "Optional[Dict[str, Any]]" = None) -> "Dict[str, Any]":

"""
# Example of the plugin using the download strategy to fetch the data
download_strategy = create_download_strategy(self.resource_config)
download_strategy = create_strategy("download", self.resource_config)
read_output = download_strategy.get(session)
return {"output": read_output}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from datetime import datetime
from typing import TYPE_CHECKING

from oteapi.models.transformationconfig import TransformationStatus
from oteapi.plugins.factories import StrategyFactory
from oteapi.models import TransformationStatus

if TYPE_CHECKING:
from typing import Any, Dict, Optional
Expand All @@ -14,7 +13,6 @@


@dataclass
@StrategyFactory.register(("transformation_type", "script/DEMO"))
class DummyTransformationStrategy:
"""Transformation Strategy."""

Expand Down