Skip to content

Commit 20b1d6f

Browse files
committed
Puppeteer/Playwright cache_dir: drop env-var fallback, go passthrough when install_root=None
``cache_dir`` is now a tiny computed helper that returns ``<install_root>/cache`` when ``install_root`` is pinned and ``None`` otherwise — no env-var fallback. This flips the ``install_root=None`` mode to pure passthrough: - The caller's ambient ``PUPPETEER_CACHE_DIR`` / ``PLAYWRIGHT_BROWSERS_PATH`` passes through to every subprocess unchanged (abxpkg exports nothing of its own). - ``load()`` trusts whatever ``puppeteer-browsers list`` / playwright-core ``executablePath()`` reports — no scoping applied. - ``uninstall()`` is a no-op when ``install_root=None``: we refuse to rmtree the user's cache because we don't own it. Users who want managed uninstall should set ``install_root``; users who stay in ambient mode manage their own cache via the CLI or their own tooling. - ``install()`` only passes ``--path=`` / sets ``PLAYWRIGHT_BROWSERS_PATH`` when we own the root; otherwise the CLIs install into their own default. Every existing call site already guarded on ``self.cache_dir is not None``, so dropping the env-var branch changes no managed-mode behaviour — it just stops abxpkg from claiming ownership of a cache dir the user controls.
1 parent 061d436 commit 20b1d6f

3 files changed

Lines changed: 25 additions & 35 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ cache_dir = <install_root>/cache # computed; None when install_root is unset
10781078
```
10791079

10801080
- Install root: set `install_root` for the root dir and `bin_dir` for symlinked executables. Leave it unset for ambient/global mode, where cache ownership stays with the host and `INSTALLER_BINARY` must already be resolvable from the ambient provider set.
1081-
- Cache dir / `PUPPETEER_CACHE_DIR`: `cache_dir` is a computed property. When `install_root` is pinned it's always `<install_root>/cache`. When `install_root` is unset it reads the ambient `$PUPPETEER_CACHE_DIR` env var so ``load()`` / ``uninstall()`` / scope checks target the same directory the user configured externally (``None`` when the env var is also unset — puppeteer-browsers then falls back to `~/.cache/puppeteer`). The resolved `cache_dir` is exported as `PUPPETEER_CACHE_DIR` to every subprocess the provider runs.
1081+
- Cache dir: `cache_dir` is a computed helper property. When `install_root` is pinned it's `<install_root>/cache` and abxpkg owns it — exported as `PUPPETEER_CACHE_DIR` to every subprocess, used for `--path=` on `puppeteer-browsers install` / `list`, and rmtree'd per-browser on `uninstall()`. When `install_root` is unset, `cache_dir` is `None`: the provider is in pure passthrough mode. The caller's ambient `$PUPPETEER_CACHE_DIR` (or the CLI's `~/.cache/puppeteer` default) flows through to subprocesses unchanged, `load()` trusts whatever path `puppeteer-browsers list` reports, and `uninstall()` is a no-op — we don't touch the user's own cache.
10821082
- Auto-switching: bootstraps `@puppeteer/browsers` through `NpmProvider` and then uses that CLI for browser installs.
10831083
- `dry_run`: shared behavior.
10841084
- Security: `min_release_age` is unsupported for browser installs and is ignored with a warning if explicitly requested. `postinstall_scripts=False` is supported for the underlying npm bootstrap path, and `ABXPKG_POSTINSTALL_SCRIPTS` hydrates the provider default here.
@@ -1102,7 +1102,7 @@ euid = 0 # routes exec() through sudo-first-then-fallbac
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-
- Cache dir / `PLAYWRIGHT_BROWSERS_PATH`: `cache_dir` is a computed property. When `install_root` is pinned it's always `<install_root>/cache`. When `install_root` is unset it reads the ambient `$PLAYWRIGHT_BROWSERS_PATH` env var so ``load()`` / ``uninstall()`` / scope checks target the same directory the user configured externally (``None`` when the env var is also unset — playwright then falls back to `~/.cache/ms-playwright` on Linux). The resolved `cache_dir` is exported as `PLAYWRIGHT_BROWSERS_PATH` to every subprocess (including the `env KEY=VAL -- ...` wrapper used when we go through sudo). `uninstall()` deletes matching `<browser>-*/` dirs from the resolved `cache_dir` — and when neither `install_root` nor `$PLAYWRIGHT_BROWSERS_PATH` is set, it touches nothing, leaving playwright's OS-default cache alone.
1105+
- Cache dir: `cache_dir` is a computed helper property. When `install_root` is pinned it's `<install_root>/cache` and abxpkg owns it — exported as `PLAYWRIGHT_BROWSERS_PATH` to every subprocess (including the `env KEY=VAL -- ...` wrapper used when we go through sudo), used to scope `executablePath()` hits on `load()`, and walked for per-browser rmtree on `uninstall()`. When `install_root` is unset, `cache_dir` is `None`: the provider is in pure passthrough mode. The caller's ambient `$PLAYWRIGHT_BROWSERS_PATH` (or playwright's `~/.cache/ms-playwright` default on Linux) flows through to subprocesses unchanged, `load()` trusts whatever path `executablePath()` reports, and `uninstall()` is a no-op — we don't touch the user's own cache.
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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,19 @@ class PlaywrightProvider(BinProvider):
8080
@computed_field
8181
@property
8282
def cache_dir(self) -> Path | None:
83-
"""Where browser downloads land.
84-
85-
When ``install_root`` is pinned we always use
86-
``<install_root>/cache``. When ``install_root`` is unset we fall
87-
back to the caller's ``PLAYWRIGHT_BROWSERS_PATH`` env var
88-
(playwright's native convention) so ``load``/``uninstall``/
89-
scope checks all target the same directory the user already
90-
configured externally. When neither is set we return ``None``
91-
and let playwright pick its own default
92-
(``~/.cache/ms-playwright`` on Linux etc.).
83+
"""``<install_root>/cache`` when managed, else ``None``.
84+
85+
Internal helper for the install/uninstall/load sites. When
86+
``install_root`` is unset we stay out of the way: the ambient
87+
``PLAYWRIGHT_BROWSERS_PATH`` (or playwright's
88+
``~/.cache/ms-playwright`` default) passes through to
89+
subprocesses untouched, ``default_abspath_handler`` trusts
90+
whatever path ``executablePath()`` reports, and
91+
``default_uninstall_handler`` skips rmtree of the user's cache.
9392
"""
94-
if self.install_root is not None:
95-
return self.install_root / "cache"
96-
env_override = os.environ.get("PLAYWRIGHT_BROWSERS_PATH")
97-
if env_override:
98-
return Path(env_override).expanduser()
99-
return None
93+
if self.install_root is None:
94+
return None
95+
return self.install_root / "cache"
10096

10197
@computed_field
10298
@property

abxpkg/binprovider_puppeteer.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,22 @@ class PuppeteerProvider(BinProvider):
7070
@computed_field
7171
@property
7272
def cache_dir(self) -> Path | None:
73-
"""Where browser downloads land.
74-
75-
When ``install_root`` is pinned we always use
76-
``<install_root>/cache``. When ``install_root`` is unset we fall
77-
back to the caller's ``PUPPETEER_CACHE_DIR`` env var (the
78-
puppeteer-browsers native convention) so ``load``/``uninstall``/
79-
scope checks all target the same directory the user already
80-
configured externally. When neither is set we return ``None``
81-
and let puppeteer-browsers pick its own default
82-
(``~/.cache/puppeteer``).
73+
"""``<install_root>/cache`` when managed, else ``None``.
74+
75+
Internal helper for the install/uninstall/load sites. When
76+
``install_root`` is unset we stay out of the way: the ambient
77+
``PUPPETEER_CACHE_DIR`` (or the CLI's ``~/.cache/puppeteer``
78+
default) passes through to subprocesses untouched, and we
79+
refuse to rmtree anything in the user's cache on ``uninstall``.
8380
"""
84-
if self.install_root is not None:
85-
return self.install_root / "cache"
86-
env_override = os.environ.get("PUPPETEER_CACHE_DIR")
87-
if env_override:
88-
return Path(env_override).expanduser()
89-
return None
81+
if self.install_root is None:
82+
return None
83+
return self.install_root / "cache"
9084

9185
@computed_field
9286
@property
9387
def ENV(self) -> "dict[str, str]":
94-
if not self.cache_dir:
88+
if self.cache_dir is None:
9589
return {}
9690
return {"PUPPETEER_CACHE_DIR": str(self.cache_dir)}
9791

0 commit comments

Comments
 (0)