Skip to content

Commit 08ab1ae

Browse files
committed
Playwright: rename browsers_path → browser_cache_dir for parity with Puppeteer
Match the Puppeteer provider's field names so both browser-installing providers expose the same API surface: - writable field: ``browser_cache_dir`` (was ``browsers_path``) - computed property: ``cache_dir`` (was ``resolved_browsers_path``) Both still default-factory from their respective env vars (``PUPPETEER_CACHE_DIR`` / ``PLAYWRIGHT_BROWSERS_PATH``) and use the same three-tier precedence documented in the README.
1 parent 30c1e97 commit 08ab1ae

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,12 +1097,12 @@ INSTALLER_BIN = "playwright"
10971097
PATH = ""
10981098
install_root = None # abxpkg-managed root dir for bin_dir / nested npm prefix
10991099
bin_dir = <install_root>/bin # symlink dir for resolved browsers
1100-
browsers_path = None # hydrated from PLAYWRIGHT_BROWSERS_PATH env; overrides install_root/cache
1100+
browser_cache_dir = None # hydrated from PLAYWRIGHT_BROWSERS_PATH env; overrides install_root/cache
11011101
euid = 0 # routes exec() through sudo-first-then-fallback
11021102
```
11031103

11041104
- Install root: set `install_root` to pin the abxpkg-managed root dir (where `bin_dir` symlinks and the nested npm prefix live). Leave it unset to let playwright use its own OS-default browsers path (`~/.cache/ms-playwright` on Linux etc.) — in that case abxpkg maintains no symlink dir or npm prefix at all, the `playwright` npm CLI bootstraps against the host's npm default, and `load()` returns the resolved `executablePath()` directly. `bin_dir` overrides the symlink directory when `install_root` is pinned.
1105-
- Browsers path / `PLAYWRIGHT_BROWSERS_PATH`: the actual browsers cache dir is resolved with three-tier precedence: explicit `browsers_path` / `PLAYWRIGHT_BROWSERS_PATH` env wins → else `<install_root>/cache` when an install root is pinned → else `None` (let playwright pick its OS default). The final value is exported as `PLAYWRIGHT_BROWSERS_PATH` to every subprocess the provider runs.
1105+
- Cache dir / `PLAYWRIGHT_BROWSERS_PATH`: the actual browsers cache dir is resolved via the `cache_dir` computed property with three-tier precedence: explicit `browser_cache_dir` / `PLAYWRIGHT_BROWSERS_PATH` env wins → else `<install_root>/cache` when an install root is pinned → else `None` (let playwright pick its OS default). The final value is exported as `PLAYWRIGHT_BROWSERS_PATH` to every subprocess the provider runs.
11061106
- Auto-switching: bootstraps the `playwright` npm package through `NpmProvider`, then runs `playwright install --with-deps <install_args>` against it. Resolves each installed browser's real executable via the `playwright-core` Node.js API (`chromium.executablePath()` etc.) and writes a symlink into `bin_dir` when one is configured.
11071107
- `dry_run`: shared behavior — the install handler short-circuits to a placeholder without touching the host.
11081108
- Privilege handling: `--with-deps` installs system packages and requires root on Linux. ``euid`` defaults to ``0``, which routes every ``exec()`` call through the base ``BinProvider.exec`` sudo-first-then-fallback path — it tries ``sudo -n -- playwright install --with-deps ...`` first on non-root hosts, falls back to running the command directly if sudo fails or isn't available, and merges both stderr outputs into the final error if both attempts fail.

abxpkg/binprovider_playwright.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PlaywrightProvider(BinProvider):
3939
finds it directly, and ``PLAYWRIGHT_BROWSERS_PATH`` defaults to
4040
``<install_root>/cache`` for the actual browser downloads. Callers
4141
that want to pin the browsers path somewhere else can set the
42-
``browsers_path`` field (hydrated from ``PLAYWRIGHT_BROWSERS_PATH``
42+
``browser_cache_dir`` field (hydrated from ``PLAYWRIGHT_BROWSERS_PATH``
4343
env) — that override always wins over ``install_root/cache``.
4444
When ``playwright_root`` is left unset, playwright picks its own
4545
default browsers path, the npm CLI bootstraps against the host's
@@ -77,9 +77,9 @@ class PlaywrightProvider(BinProvider):
7777
# env var) when unset so callers can pin the cache dir the same way they
7878
# would for a vanilla ``playwright install``. When both this and
7979
# ``install_root`` are unset, playwright falls back to its OS default; when
80-
# only ``install_root`` is set, ``browsers_path`` defaults to
80+
# only ``install_root`` is set, ``cache_dir`` defaults to
8181
# ``<install_root>/cache`` (see ``ENV``).
82-
browsers_path: Path | None = Field(
82+
browser_cache_dir: Path | None = Field(
8383
default_factory=lambda: (
8484
Path(os.environ["PLAYWRIGHT_BROWSERS_PATH"]).expanduser()
8585
if os.environ.get("PLAYWRIGHT_BROWSERS_PATH")
@@ -95,26 +95,26 @@ class PlaywrightProvider(BinProvider):
9595
@computed_field
9696
@property
9797
def ENV(self) -> "dict[str, str]":
98-
resolved = self.resolved_browsers_path
98+
resolved = self.cache_dir
9999
if resolved is None:
100100
return {}
101101
return {"PLAYWRIGHT_BROWSERS_PATH": str(resolved)}
102102

103103
@computed_field
104104
@property
105-
def resolved_browsers_path(self) -> Path | None:
105+
def cache_dir(self) -> Path | None:
106106
"""PLAYWRIGHT_BROWSERS_PATH precedence:
107107
108-
1. Explicit ``browsers_path`` (field / ``PLAYWRIGHT_BROWSERS_PATH`` env)
108+
1. Explicit ``browser_cache_dir`` (field / ``PLAYWRIGHT_BROWSERS_PATH`` env)
109109
wins — the more specific cache-dir override always beats the less
110110
specific install-root.
111111
2. Else, when ``install_root`` is pinned, default to
112112
``<install_root>/cache`` so managed installs stay self-contained.
113113
3. Else leave it unset and let playwright pick its own OS-default
114114
browsers cache directory.
115115
"""
116-
if self.browsers_path is not None:
117-
return self.browsers_path
116+
if self.browser_cache_dir is not None:
117+
return self.browser_cache_dir
118118
if self.install_root is not None:
119119
return self.install_root / "cache"
120120
return None
@@ -326,11 +326,11 @@ def exec(
326326
# contain our bin_dir.
327327
env = self.build_exec_env(base_env=(kwargs.pop("env", None) or os.environ))
328328
env_assignments: list[str] = []
329-
resolved_browsers_path = self.resolved_browsers_path
330-
if resolved_browsers_path is not None:
331-
env["PLAYWRIGHT_BROWSERS_PATH"] = str(resolved_browsers_path)
329+
cache_dir = self.cache_dir
330+
if cache_dir is not None:
331+
env["PLAYWRIGHT_BROWSERS_PATH"] = str(cache_dir)
332332
env_assignments.append(
333-
f"PLAYWRIGHT_BROWSERS_PATH={resolved_browsers_path}",
333+
f"PLAYWRIGHT_BROWSERS_PATH={cache_dir}",
334334
)
335335
needs_sudo_env_wrapper = os.geteuid() != 0 and self.EUID != os.geteuid()
336336
if env_assignments and needs_sudo_env_wrapper:

0 commit comments

Comments
 (0)