fix: Standardize package imports and configure explicit exports

This commit is contained in:
Alexander Minges 2025-07-10 15:07:42 +02:00
parent d96b07777e
commit d5bd11a8ed
Signed by: Athemis
SSH key fingerprint: SHA256:TUXshgulbwL+FRYvBNo54pCsI0auROsSEgSvueKbkZ4
8 changed files with 35 additions and 17 deletions

View file

@ -14,3 +14,20 @@ from .doi2dataset import (
sanitize_filename, sanitize_filename,
validate_email_address, validate_email_address,
) )
# Explicit exports for package API
__all__ = [
"AbstractProcessor",
"APIClient",
"CitationBuilder",
"Config",
"License",
"LicenseProcessor",
"MetadataProcessor",
"NameProcessor",
"Person",
"PIFinder",
"SubjectMapper",
"sanitize_filename",
"validate_email_address",
]

View file

@ -65,11 +65,12 @@ except ImportError:
# TODO: Remove once the warning is stripped from idutils # TODO: Remove once the warning is stripped from idutils
warnings.filterwarnings("ignore", category=DeprecationWarning) warnings.filterwarnings("ignore", category=DeprecationWarning)
from idutils.normalizers import normalize_doi, normalize_orcid, normalize_pmid from idutils.normalizers import ( # noqa: E402
from idutils.validators import is_doi normalize_doi,
normalize_orcid,
# Script version normalize_pmid,
VERSION = "1.0" )
from idutils.validators import is_doi # noqa: E402
# Icon definitions for console output # Icon definitions for console output
ICONS = { ICONS = {
@ -558,7 +559,7 @@ class APIClient:
Attributes: Attributes:
session (requests.Session): The underlying requests session. session (requests.Session): The underlying requests session.
""" """
def __init__(self, contact_mail: str | None = None, user_agent: str = f"UDE-Doi2Dataset/{VERSION}", token: str | None = None) -> None: def __init__(self, contact_mail: str | None = None, user_agent: str = f"UDE-Doi2Dataset/{__version__}", token: str | None = None) -> None:
""" """
Initialize the API client with optional contact mail, user agent, and token. Initialize the API client with optional contact mail, user agent, and token.

View file

@ -5,4 +5,4 @@ import sys
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
# Add the parent directory to sys.path # Add the parent directory to sys.path
sys.path.insert(0, parent_dir) sys.path.insert(0, parent_dir)

View file

@ -10,7 +10,7 @@ from doi2dataset import CitationBuilder, Person, PIFinder
def openalex_data(): def openalex_data():
"""Load the saved JSON response from the file 'srep45389.json'""" """Load the saved JSON response from the file 'srep45389.json'"""
json_path = os.path.join(os.path.dirname(__file__), "srep45389.json") json_path = os.path.join(os.path.dirname(__file__), "srep45389.json")
with open(json_path, "r", encoding="utf-8") as f: with open(json_path, encoding="utf-8") as f:
data = json.load(f) data = json.load(f)
return data return data

View file

@ -46,7 +46,7 @@ def fake_openalex_response():
located in the same directory as this test file. located in the same directory as this test file.
""" """
json_path = os.path.join(os.path.dirname(__file__), "srep45389.json") json_path = os.path.join(os.path.dirname(__file__), "srep45389.json")
with open(json_path, "r", encoding="utf-8") as f: with open(json_path, encoding="utf-8") as f:
data = json.load(f) data = json.load(f)
return data return data

View file

@ -1,5 +1,5 @@
import pytest from doi2dataset import License, LicenseProcessor
from doi2dataset import LicenseProcessor, License
def test_license_processor_cc_by(): def test_license_processor_cc_by():
"""Test processing a CC BY license""" """Test processing a CC BY license"""
@ -59,4 +59,4 @@ def test_license_processor_no_primary_location():
assert isinstance(license_obj, License) assert isinstance(license_obj, License)
assert license_obj.short == "unknown" assert license_obj.short == "unknown"
assert license_obj.name == "" assert license_obj.name == ""
assert license_obj.uri == "" assert license_obj.uri == ""

View file

@ -11,7 +11,7 @@ from doi2dataset import MetadataProcessor
def openalex_data(): def openalex_data():
"""Load the saved JSON response from the file 'srep45389.json'""" """Load the saved JSON response from the file 'srep45389.json'"""
json_path = os.path.join(os.path.dirname(__file__), "srep45389.json") json_path = os.path.join(os.path.dirname(__file__), "srep45389.json")
with open(json_path, "r", encoding="utf-8") as f: with open(json_path, encoding="utf-8") as f:
data = json.load(f) data = json.load(f)
return data return data

View file

@ -1,10 +1,10 @@
import json
import os
import pytest
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pytest
from doi2dataset import MetadataProcessor from doi2dataset import MetadataProcessor
@pytest.fixture @pytest.fixture
def metadata_processor(): def metadata_processor():
"""Create a MetadataProcessor instance with mocked dependencies""" """Create a MetadataProcessor instance with mocked dependencies"""
@ -54,4 +54,4 @@ def test_get_publication_year_with_invalid_data(metadata_processor):
"publication_date": "invalid-date" "publication_date": "invalid-date"
} }
year = metadata_processor._get_publication_year(data) year = metadata_processor._get_publication_year(data)
assert year == "not-a-year" assert year == "not-a-year"