Skip to content

Commit

Permalink
fix the version comparison for importlib usage
Browse files Browse the repository at this point in the history
This commit uses the python version 3.8 as
last version to use `importlib_metadata`.
The previous code tried to use
`importlib_metadata` on python 3.9, which
fails.

The commit also adapts the `entry_points()`
calls in  `get_extractor_class` to python 3.9,
where `entry_points` does not support
keyword-arguments
  • Loading branch information
christian-monch committed Jan 16, 2024
1 parent 398445c commit bea545f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
20 changes: 9 additions & 11 deletions datalad_metalad/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def get_extractor_class(extractor_name: str) -> Union[
Type[FileMetadataExtractor]]:

""" Get an extractor from its name """
if sys.version_info < (3, 10):
if sys.version_info < (3, 9):
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points
Expand All @@ -502,21 +502,19 @@ def get_extractor_class(extractor_name: str) -> Union[
# from datalad core.
entry_point_list = [
entry_point
for entry_point in entry_points(
group="datalad.metadata.extractors",
name=extractor_name,
)
if entry_point.dist.name != "datalad"
for entry_point in entry_points()
if entry_point.group == "datalad.metadata.extractors"
and entry_point.name == extractor_name
and entry_point.dist.name != "datalad"
]

if not entry_point_list:
entry_point_list = [
entry_point
for entry_point in entry_points(
group="datalad.metadata.extractors",
name=extractor_name,
)
if entry_point.dist.name == "datalad"
for entry_point in entry_points()
if entry_point.group == "datalad.metadata.extractors"
and entry_point.name == extractor_name
and entry_point.dist.name == "datalad"
]

if not entry_point_list:
Expand Down
2 changes: 1 addition & 1 deletion datalad_metalad/extractors/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys

import pytest
if sys.version_info < (3, 10):
if sys.version_info < (3, 9):
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points
Expand Down
2 changes: 1 addition & 1 deletion datalad_metalad/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def run_filter(filter_name: str,

def get_filter_class(filter_name: str) -> Type[MetadataFilterBase]:
""" Get a filter class from its name"""
if sys.version_info < (3, 10):
if sys.version_info < (3, 9):
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points
Expand Down
2 changes: 1 addition & 1 deletion datalad_metalad/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from typing import Dict, List, Union

if sys.version_info < (3, 10):
if sys.version_info < (3, 9):
from importlib_resources import files
else:
from importlib.resources import files
Expand Down
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
datalad>=0.18
sphinx>=1.7.8
sphinx-rtd-theme
datalad-metadata-model>=0.3.10
importlib-resources
pytest
pyyaml
datalad-metadata-model>=0.3.10
sphinx>=1.7.8
sphinx-rtd-theme

0 comments on commit bea545f

Please sign in to comment.