Skip to content

Commit 251bd11

Browse files
authored
Merge pull request #36 from SciCatProject/metadata-extractor
Metadata computing methods loader
2 parents 4e881be + faa28b8 commit 251bd11

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

pyproject.toml

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ dynamic = ["version"]
4646
[project.scripts]
4747
scicat_ingestor = "scicat_ingestor:main"
4848

49+
[project.entry-points."scicat_ingestor.metadata_extractor"]
50+
max = "numpy:max"
51+
min = "numpy:min"
52+
mean = "numpy:mean"
53+
4954
[tool.setuptools_scm]
5055

5156
[tool.pytest.ini_options]

src/scicat_metadata.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright (c) 2024 ScicatProject contributors (https://github.com/ScicatProject)
3+
from importlib.metadata import entry_points
4+
from typing import Callable
5+
6+
7+
def load_metadata_extractors(extractor_name: str) -> Callable:
8+
"""Load metadata extractors from the entry points."""
9+
10+
return entry_points(group="scicat_ingestor.metadata_extractor")[
11+
extractor_name
12+
].load()

tests/test_metadata_extractor.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pytest
2+
3+
from scicat_metadata import load_metadata_extractors
4+
5+
6+
@pytest.mark.parametrize(
7+
["extractor_name", "expected_result"], [("max", 5), ("min", 1), ("mean", 3)]
8+
)
9+
def test_metadata_extractor(extractor_name: str, expected_result: int):
10+
"""Test if the metadata extractor can be loaded."""
11+
test_data = [1, 2, 3, 4, 5]
12+
assert load_metadata_extractors(extractor_name)(test_data) == expected_result

0 commit comments

Comments
 (0)