EOX GitLab Instance

Commit 1be1be8a authored by Fabian Schindler's avatar Fabian Schindler
Browse files

Allowing to declare postprocessor by python path

parent 0e73be9b
Pipeline #19535 passed with stage
in 43 seconds
from abc import ABC, abstractmethod
from typing import Dict, Type
from .utils import import_by_path
class Postprocessor(ABC):
def __init__(self, **kwargs):
......@@ -17,5 +19,9 @@ POSTPROCESSORS: Dict[str, Type[Postprocessor]] = {
def get_postprocessor(config: dict) -> Postprocessor:
cls = POSTPROCESSORS[config.pop("type")]
type_ = config.pop("type")
except KeyError:
cls = import_by_path(type_)
return cls(**config)
from typing import Iterator
import importlib
from typing import Any, Iterator
from pygeofilter.backends.native.evaluate import NativeEvaluator
from pygeofilter.parsers.cql_json import parse as json_parse
......@@ -13,3 +14,14 @@ def cql_filter(_filter: dict, data: Iterator[dict]) -> Iterator[dict]:
nat_eval = NativeEvaluator(attribute_map=attr_map, use_getattr=False)
evaluator = nat_eval.evaluate(_filter)
yield from filter(evaluator, data)
def import_by_path(path: str) -> Any:
"""Imports the object from the referenced module.
path (str): the dotted Python path, where the last element is the
object in the referenced module.
module_path, _, object_name = path.rpartition(".")
return getattr(importlib.import_module(module_path), object_name)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment