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

View file

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