From 19ccfcc453cd6fbbff5daae5d995b348bb8d2386 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Wed, 31 Dec 2025 16:49:23 +0530 Subject: [PATCH] fix: ensure `bench setup-chrome` respects site config path for chromium Signed-off-by: Akhil Narang --- .../pdf_generator/chrome_pdf_generator.py | 38 +------------------ frappe/utils/print_utils.py | 4 ++ 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/frappe/utils/pdf_generator/chrome_pdf_generator.py b/frappe/utils/pdf_generator/chrome_pdf_generator.py index 4f77c33a37..6973b503d3 100644 --- a/frappe/utils/pdf_generator/chrome_pdf_generator.py +++ b/frappe/utils/pdf_generator/chrome_pdf_generator.py @@ -9,17 +9,12 @@ import requests import frappe from frappe import _ +from frappe.utils.print_utils import find_or_download_chromium_executable # TODO: close browser when worker is killed. class ChromePDFGenerator: - EXECUTABLE_PATHS: ClassVar[dict[str, list[str]]] = { - "linux": ["chrome-linux", "headless_shell"], - "darwin": ["chrome-mac", "headless_shell"], - "windows": ["chrome-win", "headless_shell.exe"], - } - _instance = None _browsers: ClassVar[list] = [] @@ -62,8 +57,6 @@ class ChromePDFGenerator: self._devtools_url = self.CHROMIUM_WEBSOCKET_URL return - # only when we want to use chromium from a specific path ( incase we don't have chromium in bench folder ) - self.CHROMIUM_BINARY_PATH = site_config.get("chromium_binary_path", "") """ Number of allowed open websocket connections to chromium. This number will basically define how many concurrent requests can be handled by one chromium instance. @@ -77,38 +70,11 @@ class ChromePDFGenerator: # time to wait for chromium to start and provide dev tools url used in _set_devtools_url. self.START_TIMEOUT = site_config.get("chromium_start_timeout", 3) - self._chromium_path = ( - self._find_chromium_executable() if not self.CHROMIUM_BINARY_PATH else self.CHROMIUM_BINARY_PATH - ) + self._chromium_path = find_or_download_chromium_executable() if self._verify_chromium_installation(): if not self._devtools_url: self.start_chromium_process() - def _find_chromium_executable(self): - """Finds the Chromium executable or raises an error if not found.""" - bench_path = frappe.utils.get_bench_path() - """Determine the path to the Chromium executable. chromium is downloaded by download_chromium in print_designer/install.py""" - chromium_dir = os.path.join(bench_path, "chromium") - - if not os.path.exists(chromium_dir): - frappe.throw(_("Chromium is not downloaded. Please run the setup first.")) - - platform_name = platform.system().lower() - - if platform_name not in ["linux", "darwin", "windows"]: - frappe.throw(f"Unsupported platform: {platform_name}") - - executable_name = self.EXECUTABLE_PATHS.get(platform_name) - - # Construct the full path to the executable - exec_path = Path(chromium_dir).joinpath(*executable_name) - if not exec_path.exists(): - frappe.throw( - f"Chromium executable not found: {exec_path}. please run bench setup-new-pdf-backend" - ) - - return str(exec_path) - def _verify_chromium_installation(self): """Ensures Chromium is available and executable, raising clearer errors if not.""" if not os.path.exists(self._chromium_path): diff --git a/frappe/utils/print_utils.py b/frappe/utils/print_utils.py index 6efa3a119c..dfb17f1038 100644 --- a/frappe/utils/print_utils.py +++ b/frappe/utils/print_utils.py @@ -172,8 +172,12 @@ def setup_chromium(): def find_or_download_chromium_executable(): """Finds the Chromium executable or downloads if not found.""" import platform + import shutil from pathlib import Path + if chromium_path := shutil.which(frappe.get_common_site_config().chromium_path): + return chromium_path + bench_path = frappe.utils.get_bench_path() """Determine the path to the Chromium executable.""" chromium_dir = os.path.join(bench_path, "chromium")