From b8ce11c08dc32051545e73e858f0cd044ac12ef2 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Sun, 3 May 2020 10:51:49 -0500 Subject: [PATCH] add compatibility with isbnlib >= 3.10 --- papis/isbn.py | 21 ++++++++++++--------- setup.py | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/papis/isbn.py b/papis/isbn.py index fe137cd3..0bbfbd52 100644 --- a/papis/isbn.py +++ b/papis/isbn.py @@ -1,6 +1,7 @@ import papis.document import logging import isbnlib +import isbnlib.registry import click # See https://github.com/xlcnd/isbnlib for details from typing import Optional, Dict, Any, List @@ -11,18 +12,20 @@ def get_data( query: str = "", service: Optional[str] = None) -> List[Dict[str, Any]]: - global logger - results = [] # type: List[Dict[str, Any]] + isbnlib_version = tuple(int(n) for n in isbnlib.__version__.split('.')) + if service is None and isbnlib_version >= (3, 10, 0): + service = "default" + logger.debug('Trying to retrieve isbn') isbn = isbnlib.isbn_from_words(query) data = isbnlib.meta(isbn, service=service) - if data is None: - return results - else: - logger.debug('Trying to retrieve isbn') - assert(isinstance(data, dict)) + + results = [] # type: List[Dict[str, Any]] + if data is not None: + assert isinstance(data, dict) results.append(data_to_papis(data)) - return results + + return results def data_to_papis(data: Dict[str, Any]) -> Dict[str, Any]: @@ -45,7 +48,7 @@ def data_to_papis(data: Dict[str, Any]) -> Dict[str, Any]: '--service', '-s', default='goob', - type=click.Choice(['wcat', 'goob', 'openl']) + type=click.Choice(list(isbnlib.registry.services.keys())) ) def explorer(ctx: click.core.Context, query: str, service: str) -> None: """ diff --git a/setup.py b/setup.py index 65fc183c..dd136e71 100644 --- a/setup.py +++ b/setup.py @@ -65,7 +65,7 @@ "bibtexparser>=0.6.2", "click>=7.0.0", "habanero>=0.6.0", - "isbnlib>=3.9.1,<3.10", + "isbnlib>=3.9.1", "prompt_toolkit>=2.0.5", "tqdm>=4.1", "pygments>=2.2.0",