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

Metadata computing methods loader #36

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ dynamic = ["version"]
[project.scripts]
scicat_ingestor = "scicat_ingestor:main"

[project.entry-points."scicat_ingestor.metadata_extractor"]
max = "numpy:max"
min = "numpy:min"
mean = "numpy:mean"

[tool.setuptools_scm]

[tool.pytest.ini_options]
Expand Down
12 changes: 12 additions & 0 deletions src/scicat_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 ScicatProject contributors (https://github.com/ScicatProject)
from importlib.metadata import entry_points
from typing import Callable


def load_metadata_extractors(extractor_name: str) -> Callable:
"""Load metadata extractors from the entry points."""

return entry_points(group="scicat_ingestor.metadata_extractor")[
extractor_name
].load()
12 changes: 12 additions & 0 deletions tests/test_metadata_extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from scicat_metadata import load_metadata_extractors


@pytest.mark.parametrize(
["extractor_name", "expected_result"], [("max", 5), ("min", 1), ("mean", 3)]
)
def test_metadata_extractor(extractor_name: str, expected_result: int):
"""Test if the metadata extractor can be loaded."""
test_data = [1, 2, 3, 4, 5]
assert load_metadata_extractors(extractor_name)(test_data) == expected_result