Skip to content

Commit

Permalink
manubot#337 fix allowed types.
Browse files Browse the repository at this point in the history
  • Loading branch information
xihh87 committed Jul 28, 2022
1 parent b1fe35e commit 3e1b783
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions manubot/cite/cite_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def cli_cite(args: argparse.Namespace):
infer_citekey_prefixes=args.infer_prefix,
prune_csl_items=args.prune_csl,
sort_csl_items=False,
timeout_seconds=args.timeout_seconds,
)
citations.load_manual_references(paths=args.bibliography)
citations.inspect(log_level="WARNING")
Expand Down
6 changes: 4 additions & 2 deletions manubot/cite/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ def standardize_prefix_accession(self, accession):
accession = accession.lower()
return self.standard_prefix, accession

def get_csl_item(self, citekey):
return get_doi_csl_item(citekey.standard_accession)
def get_csl_item(self, citekey, timeout_seconds=default_timeout):
return get_doi_csl_item(
citekey.standard_accession, timeout_seconds=timeout_seconds
)


def expand_short_doi(short_doi: str, timeout_seconds: int = default_timeout) -> str:
Expand Down
15 changes: 9 additions & 6 deletions manubot/cite/isbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .handlers import Handler

default_timeout = 3
default_timeout = (3.05, 15)


def set_isbnlib_timeout(seconds=default_timeout):
Expand All @@ -24,7 +24,7 @@ class Handler_ISBN(Handler):
]

def inspect(self, citekey, timeout_seconds: int = default_timeout):
isbnlib = set_isbnlib_timeout(timeout_seconds)
isbnlib = set_isbnlib_timeout(timeout_seconds[0])

fail = isbnlib.notisbn(citekey.accession, level="strict")
if fail:
Expand All @@ -36,7 +36,8 @@ def standardize_prefix_accession(self, accession):
accession = to_isbn13(accession)
return self.standard_prefix, accession

def get_csl_item(self, citekey, timeout_seconds: int = default_timeout):
def get_csl_item(self, citekey, timeout_seconds: int = default_timeout[0]):

return get_isbn_csl_item(
citekey.standard_accession, timeout_seconds=timeout_seconds
)
Expand All @@ -51,7 +52,7 @@ def get_isbn_csl_item(isbn: str, timeout_seconds: int = default_timeout):
in order, with this function returning the metadata from the first
non-failing method.
"""
isbnlib = set_isbnlib_timeout(default_timeout)
isbnlib = set_isbnlib_timeout(default_timeout[0])

isbn = isbnlib.to_isbn13(isbn)
for retriever in isbn_retrievers:
Expand All @@ -75,7 +76,9 @@ def get_isbn_csl_item_zotero(isbn: str, timeout_seconds: int = default_timeout):
return get_csl_item(f"isbn:{isbn}", timeout_seconds=timeout_seconds)


def get_isbn_csl_item_citoid(isbn: str, timeout_seconds: int = default_timeout):
def get_isbn_csl_item_citoid(
isbn: str, timeout_seconds: tp.Union[tuple, int, float, None] = default_timeout
):
"""
Return CSL JSON Data for an ISBN using the Wikipedia Citoid API.
https://en.wikipedia.org/api/rest_v1/#!/Citation/getCitation
Expand Down Expand Up @@ -141,7 +144,7 @@ def get_isbn_csl_item_isbnlib(isbn: str, timeout_seconds: int = default_timeout)
"""
Generate CSL JSON Data for an ISBN using isbnlib.
"""
isbnlib = set_isbnlib_timeout(timeout_seconds)
isbnlib = set_isbnlib_timeout(timeout_seconds[0])
metadata = isbnlib.meta(isbn)
csl_json = isbnlib.registry.bibformatters["csl"](metadata)
csl_data = json.loads(csl_json)
Expand Down
11 changes: 8 additions & 3 deletions manubot/cite/pubmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ def inspect(self, citekey: CiteKey) -> Optional[str]:
elif not self._get_pattern().fullmatch(identifier):
return "PubMed Identifiers should be 1-8 digits with no leading zeros."

def get_csl_item(self, citekey: CiteKey) -> Dict[str, Any]:
return get_pubmed_csl_item(citekey.standard_accession)
def get_csl_item(
self, citekey: CiteKey, timeout_seconds=default_timeout
) -> Dict[str, Any]:
return get_pubmed_csl_item(
citekey.standard_accession, timeout_seconds=timeout_seconds
)


class Handler_PMC(Handler):
Expand Down Expand Up @@ -129,7 +133,8 @@ def _get_literature_citation_exporter_csl_item(


def get_pubmed_csl_item(
pmid: Union[str, int], timeout_seconds: int = default_timeout
pmid: Union[str, int],
timeout_seconds: Union[tuple, int, float, None] = default_timeout,
) -> Dict[str, Any]:
"""
Query NCBI E-Utilities to create CSL Items for PubMed IDs.
Expand Down

0 comments on commit 3e1b783

Please sign in to comment.