Skip to content

Commit

Permalink
Use entry point to expose methods alias.
Browse files Browse the repository at this point in the history
  • Loading branch information
YooSunYoung committed Jun 12, 2024
1 parent 4e881be commit faa28b8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
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

0 comments on commit faa28b8

Please sign in to comment.