EOX GitLab Instance
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
View Server 2
harvester
Commits
1be1be8a
Commit
1be1be8a
authored
Dec 10, 2021
by
Fabian Schindler
Browse files
Allowing to declare postprocessor by python path
parent
0e73be9b
Pipeline
#19535
passed with stage
in 43 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
harvester/postprocess.py
View file @
1be1be8a
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"
)
try
:
cls
=
POSTPROCESSORS
[
type_
]
except
KeyError
:
cls
=
import_by_path
(
type_
)
return
cls
(
**
config
)
harvester/utils.py
View file @
1be1be8a
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.
Args:
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment