From ab0087e106ed8728065479e8a2d46ef4c3fd7dfc Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Sun, 22 Sep 2024 13:17:10 -0700 Subject: [PATCH] cleanup chrome and playwright symlink and app names --- archivebox/builtin_plugins/chrome/apps.py | 49 ++++++++++++------- archivebox/builtin_plugins/playwright/apps.py | 2 +- archivebox/builtin_plugins/puppeteer/apps.py | 2 +- archivebox/main.py | 2 +- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/archivebox/builtin_plugins/chrome/apps.py b/archivebox/builtin_plugins/chrome/apps.py index d24e968b..2682b498 100644 --- a/archivebox/builtin_plugins/chrome/apps.py +++ b/archivebox/builtin_plugins/chrome/apps.py @@ -1,6 +1,7 @@ import platform from pathlib import Path -from typing import List, Optional, Dict +from typing import List, Optional, Dict, Any +from typing_extensions import Self from django.conf import settings @@ -27,26 +28,31 @@ from builtin_plugins.puppeteer.apps import PUPPETEER_BINPROVIDER from builtin_plugins.playwright.apps import PLAYWRIGHT_BINPROVIDER -CHROMIUM_BINARY_NAMES = [ +CHROMIUM_BINARY_NAMES_LINUX = [ "chromium", "chromium-browser", "chromium-browser-beta", "chromium-browser-unstable", "chromium-browser-canary", "chromium-browser-dev", - "/Applications/Chromium.app/Contents/MacOS/Chromium", ] -CHROME_BINARY_NAMES = [ +CHROMIUM_BINARY_NAMES_MACOS = ["/Applications/Chromium.app/Contents/MacOS/Chromium"] +CHROMIUM_BINARY_NAMES = CHROMIUM_BINARY_NAMES_LINUX + CHROMIUM_BINARY_NAMES_MACOS + +CHROME_BINARY_NAMES_LINUX = [ "google-chrome", "google-chrome-stable", "google-chrome-beta", "google-chrome-canary", "google-chrome-unstable", "google-chrome-dev", - # 'chrome', + "chrome" +] +CHROME_BINARY_NAMES_MACOS = [ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary", ] +CHROME_BINARY_NAMES = CHROME_BINARY_NAMES_LINUX + CHROME_BINARY_NAMES_MACOS def autodetect_system_chrome_install(PATH=None) -> Optional[Path]: @@ -56,13 +62,26 @@ def autodetect_system_chrome_install(PATH=None) -> Optional[Path]: return abspath return None +def create_macos_app_symlink(target: Path, shortcut: Path): + """ + on macOS, some binaries are inside of .app, so we need to + create a tiny bash script instead of a symlink + (so that ../ parent relationships are relative to original .app instead of callsite dir) + """ + # TODO: should we enforce this? is it useful in any other situation? + # if platform.system().lower() != 'darwin': + # raise Exception(...) + + shortcut.write_text(f"""#!/usr/bin/env bash\nexec '{target}' "$@"\n""") + shortcut.chmod(0o777) # make sure its executable by everyone + ###################### Config ########################## class ChromeDependencyConfigs(BaseConfigSet): section: ConfigSectionName = 'DEPENDENCY_CONFIG' - CHROME_BINARY: str = Field(default='wget') + CHROME_BINARY: str = Field(default='chrome') CHROME_ARGS: Optional[List[str]] = Field(default=None) CHROME_EXTRA_ARGS: List[str] = [] CHROME_DEFAULT_ARGS: List[str] = ['--timeout={TIMEOUT-10}'] @@ -78,21 +97,18 @@ CHROME_CONFIG = ChromeConfigs(**DEFAULT_GLOBAL_CONFIG) class ChromeBinary(BaseBinary): - name: BinName = 'chrome' + name: BinName = CHROME_CONFIG.CHROME_BINARY binproviders_supported: List[InstanceOf[BinProvider]] = [PUPPETEER_BINPROVIDER, env, PLAYWRIGHT_BINPROVIDER] provider_overrides: Dict[BinProviderName, ProviderLookupDict] = { env.name: { - 'abspath': lambda: - autodetect_system_chrome_install(PATH=env.PATH), + 'abspath': lambda: autodetect_system_chrome_install(PATH=env.PATH), # /usr/bin/google-chrome-stable }, PUPPETEER_BINPROVIDER.name: { - 'packages': lambda: - ['chrome@stable'], + 'packages': lambda: ['chrome@stable'], # npx @puppeteer/browsers install chrome@stable }, PLAYWRIGHT_BINPROVIDER.name: { - 'packages': lambda: - ['chromium'], + 'packages': lambda: ['chromium'], # playwright install chromium }, } @@ -105,8 +121,7 @@ class ChromeBinary(BaseBinary): if platform.system().lower() == 'darwin': # if on macOS, browser binary is inside a .app, so we need to create a tiny bash script instead of a symlink - symlink.write_text(f"""#!/usr/bin/env bash\nexec '{binary.abspath}' "$@"\n""") - symlink.chmod(0o777) # make sure its executable by everyone + create_macos_app_symlink(binary.abspath, symlink) else: # otherwise on linux we can symlink directly to binary executable symlink.symlink_to(binary.abspath) @@ -117,8 +132,8 @@ CHROME_BINARY = ChromeBinary() PLUGIN_BINARIES = [CHROME_BINARY] class ChromePlugin(BasePlugin): - app_label: str ='puppeteer' - verbose_name: str = 'Chrome & Playwright' + app_label: str = 'chrome' + verbose_name: str = 'Chrome Browser' hooks: List[InstanceOf[BaseHook]] = [ CHROME_CONFIG, diff --git a/archivebox/builtin_plugins/playwright/apps.py b/archivebox/builtin_plugins/playwright/apps.py index f7bf1351..0559dd2a 100644 --- a/archivebox/builtin_plugins/playwright/apps.py +++ b/archivebox/builtin_plugins/playwright/apps.py @@ -167,7 +167,7 @@ PLAYWRIGHT_BINPROVIDER = PlaywrightBinProvider() class PlaywrightPlugin(BasePlugin): app_label: str = 'playwright' - verbose_name: str = 'Playwright' + verbose_name: str = 'Playwright (PIP)' hooks: List[InstanceOf[BaseHook]] = [ PLAYWRIGHT_CONFIG, diff --git a/archivebox/builtin_plugins/puppeteer/apps.py b/archivebox/builtin_plugins/puppeteer/apps.py index a7e84e7a..f6992611 100644 --- a/archivebox/builtin_plugins/puppeteer/apps.py +++ b/archivebox/builtin_plugins/puppeteer/apps.py @@ -154,7 +154,7 @@ PUPPETEER_BINPROVIDER = PuppeteerBinProvider() class PuppeteerPlugin(BasePlugin): app_label: str ='puppeteer' - verbose_name: str = 'Puppeteer & Playwright' + verbose_name: str = 'Puppeteer (NPM)' hooks: List[InstanceOf[BaseHook]] = [ PUPPETEER_CONFIG, diff --git a/archivebox/main.py b/archivebox/main.py index 2e4c244e..77a6e443 100755 --- a/archivebox/main.py +++ b/archivebox/main.py @@ -1328,7 +1328,7 @@ def server(runserver_args: Optional[List[str]]=None, from django.core.management import call_command from django.contrib.auth.models import User - print('{green}[+] Starting ArchiveBox webserver...{reset}'.format(**ANSI)) + print('{green}[+] Starting ArchiveBox webserver... {reset}'.format(**ANSI)) print(' > Logging errors to ./logs/errors.log') if not User.objects.filter(is_superuser=True).exists(): print('{lightyellow}[!] No admin users exist yet, you will not be able to edit links in the UI.{reset}'.format(**ANSI))