Skip to content

Commit c09115f

Browse files
committed
Move playwright installation to a build script
1 parent 5219744 commit c09115f

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

pyproject.toml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,8 @@ installer = "uv"
7171
reactpy = "reactpy._console.cli:entry_point"
7272

7373
[[tool.hatch.build.hooks.build-scripts.scripts]]
74-
# Note: `hatch` can't be called within `build-scripts` when installing packages in editable mode, so we have to write the commands long-form
7574
commands = [
76-
'python "src/build_scripts/clean_js_dir.py"',
77-
'bun install --cwd "src/js/packages/event-to-object"',
78-
'bun run --cwd "src/js/packages/event-to-object" build',
79-
'bun install --cwd "src/js/packages/@reactpy/client"',
80-
'bun run --cwd "src/js/packages/@reactpy/client" build',
81-
'bun install --cwd "src/js/packages/@reactpy/app"',
82-
'bun run --cwd "src/js/packages/@reactpy/app" build',
75+
"hatch --env default run javascript:build",
8376
'python "src/build_scripts/copy_dir.py" "src/js/node_modules/@pyscript/core/dist" "src/reactpy/static/pyscript"',
8477
'python "src/build_scripts/copy_dir.py" "src/js/node_modules/morphdom/dist" "src/reactpy/static/morphdom"',
8578
]
@@ -90,15 +83,13 @@ artifacts = []
9083
#############################
9184
[tool.hatch.envs.hatch-test.scripts]
9285
run = [
86+
'hatch --env default run "src/build_scripts/install_playwright.py"',
9387
"hatch --env default build -t wheel",
94-
"playwright install chromium",
95-
"playwright install-deps",
9688
"pytest{env:HATCH_TEST_ARGS:} {args}",
9789
]
9890
run-cov = [
91+
'hatch --env default run "src/build_scripts/install_playwright.py"',
9992
"hatch --env default build -t wheel",
100-
"playwright install chromium",
101-
"playwright install-deps",
10293
"coverage run -m pytest{env:HATCH_TEST_ARGS:} {args}",
10394
]
10495
cov-combine = "coverage combine"
@@ -195,7 +186,6 @@ detached = true
195186
[tool.hatch.envs.javascript.scripts]
196187
check = [
197188
'hatch run javascript:build',
198-
'bun install --cwd "src/js"',
199189
'bun run --cwd "src/js" lint',
200190
'bun run --cwd "src/js/packages/event-to-object" checkTypes',
201191
'bun run --cwd "src/js/packages/@reactpy/client" checkTypes',

src/build_scripts/copy_dir.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def copy_files(source: Path, destination: Path) -> None:
3131
root_dir = Path(__file__).parent.parent.parent
3232
src = Path(root_dir / sys.argv[1])
3333
dest = Path(root_dir / sys.argv[2])
34+
print(f"Copying files from '{sys.argv[1]}' to '{sys.argv[2]}'...") # noqa: T201
3435

3536
if not src.exists():
3637
logging.error("Source directory %s does not exist", src)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# /// script
2+
# requires-python = ">=3.11"
3+
# dependencies = []
4+
# ///
5+
6+
import subprocess
7+
8+
print("Installing Playwright browsers...") # noqa: T201
9+
10+
# Install Chromium browser for Playwright, and fail if it cannot be installed
11+
subprocess.run(["playwright", "install", "chromium"], check=True) # noqa: S607
12+
13+
# Try to install system dependencies. We don't generate an exception if this fails
14+
# as *nix systems (such as WSL) return a failure code if there are *any* dependencies
15+
# that could be cleaned up via `sudo apt autoremove`. This occurs even if we weren't
16+
# the ones to install those dependencies in the first place.
17+
subprocess.run(["playwright", "install-deps"], check=False) # noqa: S607

0 commit comments

Comments
 (0)