fix: Standardize package imports and configure explicit exports
This commit is contained in:
parent
d96b07777e
commit
d5bd11a8ed
8 changed files with 35 additions and 17 deletions
17
__init__.py
17
__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",
|
||||
]
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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)
|
||||
sys.path.insert(0, parent_dir)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 == ""
|
||||
assert license_obj.uri == ""
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"
|
||||
assert year == "not-a-year"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue