refactor: Improve module availability checks

Followed ruff (Pyflakes) suggestion to use importlib utils directly
instead of try and erroring with imports.
This commit is contained in:
Marty Oehme 2024-01-24 12:27:21 +01:00
parent 2f41906e6a
commit c2a5190237
Signed by: Marty
GPG Key ID: EDBF2ED917B2EF6A
1 changed files with 6 additions and 7 deletions

View File

@ -1,3 +1,5 @@
from importlib.util import find_spec
import papis.logging
from papis_extract.extraction import Extractor
@ -6,14 +8,11 @@ from papis_extract.extractors.pocketbook import PocketBookExtractor
logger = papis.logging.get_logger(__name__)
all_extractors: dict[str, Extractor] = {
"pdf": pdf.PdfExtractor(),
}
all_extractors: dict[str, Extractor] = {}
try:
import bs4
import magic
all_extractors["pdf"] = pdf.PdfExtractor()
if find_spec("bs4") and find_spec("magic"):
all_extractors["pocketbook"] = PocketBookExtractor()
except ImportError:
else:
logger.debug("pocketbook extractor not activated.")