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:
parent
2f41906e6a
commit
c2a5190237
1 changed files with 6 additions and 7 deletions
|
@ -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.")
|
||||||
|
|
Loading…
Reference in a new issue