Skip to content

Commit

Permalink
Merge pull request #251 from IFCA-Advanced-Computing/upstream_fix/con…
Browse files Browse the repository at this point in the history
…fig_terms

Fix: import ConfigTerms from api/evaluator
  • Loading branch information
ferag authored Sep 17, 2024
2 parents 22cb374 + 189a4ed commit 670375b
Showing 1 changed file with 1 addition and 47 deletions.
48 changes: 1 addition & 47 deletions plugins/digital_csic/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,60 +16,14 @@
from bs4 import BeautifulSoup

import api.utils as ut
from api.evaluator import Evaluator
from api.evaluator import ConfigTerms, Evaluator

logging.basicConfig(
stream=sys.stdout, level=logging.DEBUG, format="'%(name)s:%(lineno)s' | %(message)s"
)
logger = logging.getLogger("api.plugin")


class ConfigTerms(property):
def __init__(self, term_id):
self.term_id = term_id

def __call__(self, wrapped_func):
@wraps(wrapped_func)
def wrapper(plugin, **kwargs):
metadata = plugin.metadata
has_metadata = True

term_list = ast.literal_eval(plugin.config[plugin.name][self.term_id])
# Get values in config for the given term
if not term_list:
msg = (
"Cannot find any value for term <%s> in configuration"
% self.term_id
)
has_metadata = False
else:
# Get metadata associated with the term ID
term_metadata = pd.DataFrame(
term_list, columns=["element", "qualifier"]
)
term_metadata = ut.check_metadata_terms_with_values(
metadata, term_metadata
)
if term_metadata.empty:
msg = (
"No access information can be found in the metadata for: %s. Please double-check the value/s provided for '%s' configuration parameter"
% (term_list, self.term_id)
)
has_metadata = False

if not has_metadata:
logger.warning(msg)
return (0, [{"message": msg, "points": 0}])

# Update kwargs with collected metadata for the required terms
kwargs.update(
{self.term_id: {"list": term_list, "metadata": term_metadata}}
)
return wrapped_func(plugin, **kwargs)

return wrapper


class Plugin(Evaluator):
"""A class used to define FAIR indicators tests. It is tailored towards the
DigitalCSIC repository.
Expand Down

0 comments on commit 670375b

Please sign in to comment.