From 49c520914ceefc3ce798e9cf67e6bc07edc1880b Mon Sep 17 00:00:00 2001 From: Andrew Dunham Date: Sun, 3 Nov 2024 13:59:20 -0500 Subject: [PATCH 1/2] playwright: support PLAYWRIGHT_BROWSERS_PATH environment variable This environment variable is used by Playwright to configure where to install browsers. If specified, the given directory is used instead of the OS-specific cache folder. For compatibility with existing Playwright installations, and better control over where these binaries are installed, check the same environment variable in PlaywrightBinProvider. Signed-off-by: Andrew Dunham --- .../plugins_pkg/playwright/binproviders.py | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/archivebox/plugins_pkg/playwright/binproviders.py b/archivebox/plugins_pkg/playwright/binproviders.py index 7d1238d5..3a522d20 100644 --- a/archivebox/plugins_pkg/playwright/binproviders.py +++ b/archivebox/plugins_pkg/playwright/binproviders.py @@ -37,11 +37,6 @@ class PlaywrightBinProvider(BaseBinProvider): PATH: PATHStr = f"{CONSTANTS.DEFAULT_LIB_DIR / 'bin'}:{DEFAULT_ENV_PATH}" - playwright_browsers_dir: Path = ( - MACOS_PLAYWRIGHT_CACHE_DIR.expanduser() - if OPERATING_SYSTEM == "darwin" else - LINUX_PLAYWRIGHT_CACHE_DIR.expanduser() - ) playwright_install_args: List[str] = ["install"] packages_handler: BinProviderOverrides = Field(default={ @@ -58,6 +53,25 @@ class PlaywrightBinProvider(BaseBinProvider): except Exception as e: return None + @computed_field + @property + def playwright_browsers_dir(self) -> Path: + # The directory where playwright stores browsers can be overridden with + # the "PLAYWRIGHT_BROWSERS_PATH" environment variable; if it's present + # and a directory, we should use that. See the playwright documentation + # for more details: + # https://playwright.dev/docs/browsers#managing-browser-binaries + dir_path = os.environ.get("PLAYWRIGHT_BROWSERS_PATH") + if dir_path and os.path.isdir(dir_path): + return Path(dir_path) + + # Otherwise return the default path based on the operating system. + return ( + MACOS_PLAYWRIGHT_CACHE_DIR.expanduser() + if OPERATING_SYSTEM == "darwin" else + LINUX_PLAYWRIGHT_CACHE_DIR.expanduser() + ) + def setup(self) -> None: # update paths from config if they arent the default from archivebox.config.common import STORAGE_CONFIG From 50a85ec97bbfe7ca039795faa1d91081e872fcf9 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Sun, 3 Nov 2024 15:47:00 -0500 Subject: [PATCH 2/2] Update archivebox/plugins_pkg/playwright/binproviders.py --- archivebox/plugins_pkg/playwright/binproviders.py | 1 - 1 file changed, 1 deletion(-) diff --git a/archivebox/plugins_pkg/playwright/binproviders.py b/archivebox/plugins_pkg/playwright/binproviders.py index 3a522d20..cb8d35cb 100644 --- a/archivebox/plugins_pkg/playwright/binproviders.py +++ b/archivebox/plugins_pkg/playwright/binproviders.py @@ -53,7 +53,6 @@ class PlaywrightBinProvider(BaseBinProvider): except Exception as e: return None - @computed_field @property def playwright_browsers_dir(self) -> Path: # The directory where playwright stores browsers can be overridden with