From d5bd11a8ed25354a7aa6a9cd50df5dbc1e5217a7 Mon Sep 17 00:00:00 2001 From: Alexander Minges Date: Thu, 10 Jul 2025 15:07:42 +0200 Subject: [PATCH] fix: Standardize package imports and configure explicit exports --- __init__.py | 17 +++++++++++++++++ doi2dataset.py | 13 +++++++------ tests/conftest.py | 2 +- tests/test_citation_builder.py | 2 +- tests/test_fetch_doi_mock.py | 2 +- tests/test_license_processor.py | 6 +++--- tests/test_metadata_processor.py | 2 +- tests/test_publication_utils.py | 8 ++++---- 8 files changed, 35 insertions(+), 17 deletions(-) diff --git a/__init__.py b/__init__.py index f1bd259..3a5d0a7 100644 --- a/__init__.py +++ b/__init__.py @@ -14,3 +14,20 @@ from .doi2dataset import ( sanitize_filename, 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", +] diff --git a/doi2dataset.py b/doi2dataset.py index ddbf365..6d5d694 100755 --- a/doi2dataset.py +++ b/doi2dataset.py @@ -65,11 +65,12 @@ except ImportError: # TODO: Remove once the warning is stripped from idutils warnings.filterwarnings("ignore", category=DeprecationWarning) -from idutils.normalizers import normalize_doi, normalize_orcid, normalize_pmid -from idutils.validators import is_doi - -# Script version -VERSION = "1.0" +from idutils.normalizers import ( # noqa: E402 + normalize_doi, + normalize_orcid, + normalize_pmid, +) +from idutils.validators import is_doi # noqa: E402 # Icon definitions for console output ICONS = { @@ -558,7 +559,7 @@ class APIClient: Attributes: 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. diff --git a/tests/conftest.py b/tests/conftest.py index e762592..e198900 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,4 +5,4 @@ import sys parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) # Add the parent directory to sys.path -sys.path.insert(0, parent_dir) \ No newline at end of file +sys.path.insert(0, parent_dir) diff --git a/tests/test_citation_builder.py b/tests/test_citation_builder.py index 055e93e..08045fd 100644 --- a/tests/test_citation_builder.py +++ b/tests/test_citation_builder.py @@ -10,7 +10,7 @@ from doi2dataset import CitationBuilder, Person, PIFinder def openalex_data(): """Load the saved JSON response from the 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) return data diff --git a/tests/test_fetch_doi_mock.py b/tests/test_fetch_doi_mock.py index 6e2745c..d63effe 100644 --- a/tests/test_fetch_doi_mock.py +++ b/tests/test_fetch_doi_mock.py @@ -46,7 +46,7 @@ def fake_openalex_response(): located in the same directory as this test file. """ 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) return data diff --git a/tests/test_license_processor.py b/tests/test_license_processor.py index bdb5ef5..560fe5a 100644 --- a/tests/test_license_processor.py +++ b/tests/test_license_processor.py @@ -1,5 +1,5 @@ -import pytest -from doi2dataset import LicenseProcessor, License +from doi2dataset import License, LicenseProcessor + def test_license_processor_cc_by(): """Test processing a CC BY license""" @@ -59,4 +59,4 @@ def test_license_processor_no_primary_location(): assert isinstance(license_obj, License) assert license_obj.short == "unknown" assert license_obj.name == "" - assert license_obj.uri == "" \ No newline at end of file + assert license_obj.uri == "" diff --git a/tests/test_metadata_processor.py b/tests/test_metadata_processor.py index b8a3c62..ffacf4e 100644 --- a/tests/test_metadata_processor.py +++ b/tests/test_metadata_processor.py @@ -11,7 +11,7 @@ from doi2dataset import MetadataProcessor def openalex_data(): """Load the saved JSON response from the 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) return data diff --git a/tests/test_publication_utils.py b/tests/test_publication_utils.py index 9f042f5..d9dc978 100644 --- a/tests/test_publication_utils.py +++ b/tests/test_publication_utils.py @@ -1,10 +1,10 @@ -import json -import os -import pytest from unittest.mock import MagicMock +import pytest + from doi2dataset import MetadataProcessor + @pytest.fixture def metadata_processor(): """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" } year = metadata_processor._get_publication_year(data) - assert year == "not-a-year" \ No newline at end of file + assert year == "not-a-year"