From 3bcddba0527d101b09f22a7118891665b5d72076 Mon Sep 17 00:00:00 2001 From: aram yegiazaryan Date: Sat, 31 Aug 2024 08:20:06 -0700 Subject: [PATCH] #514: use importlib to validate weasyprint install --- pebblo/app/config/config_validation.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pebblo/app/config/config_validation.py b/pebblo/app/config/config_validation.py index ee156be2..d864893d 100644 --- a/pebblo/app/config/config_validation.py +++ b/pebblo/app/config/config_validation.py @@ -1,3 +1,4 @@ +import importlib.util import logging import os import sys @@ -112,13 +113,9 @@ def validate(self): def validate_optional_weasyprint_dependency(self): """Check if WeasyPrint is installed""" - try: - from weasyprint import CSS, HTML - except ImportError: - error = """Could not import weasyprint package. Please install weasyprint and Pango to generate - report using weasyprint. - Follow documentation for more details - https://daxa-ai.github.io/pebblo/installation" - """ + if importlib.util.find_spec("weasyprint") is None: + error = """Error: `renderer: weasyprint` was specified, but weasyprint was not found. + Follow documentation for more details - https://daxa-ai.github.io/pebblo/installation""" self.errors.append(error) @staticmethod @@ -152,7 +149,7 @@ def validate_config(config_dict): "logging": LoggingConfig, "reports": ReportsConfig, "classifier": ClassifierConfig, - "storage": StorageConfig + "storage": StorageConfig, } validation_errors = []