Skip to content

Commit 061c902

Browse files
committed
auto-copy reactpy embedded wheel at start-up
1 parent e221ded commit 061c902

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

src/reactpy_django/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import filecmp
2+
import shutil
3+
from pathlib import Path
4+
5+
import reactpy
6+
17
from reactpy_django import (
28
components,
39
decorators,
@@ -18,3 +24,13 @@
1824
"types",
1925
"utils",
2026
]
27+
28+
# Copy ReactPy core's wheel to ReactPy-Django's static directory if
29+
# any file within the SOURCE_DIR is not within the DEST_DIR (or is not identical)
30+
SOURCE_DIR = Path(reactpy.__file__).parent / "static/wheels"
31+
DEST_DIR = Path(__file__).parent.parent / "reactpy_django/static/reactpy_django/wheels"
32+
if not DEST_DIR.exists() or any(
33+
not (DEST_DIR / file.name).exists() or not filecmp.cmp(file, DEST_DIR / file.name)
34+
for file in SOURCE_DIR.glob("reactpy-*-py3-none-any.whl")
35+
):
36+
shutil.copytree(SOURCE_DIR, DEST_DIR, dirs_exist_ok=True)

src/reactpy_django/templatetags/reactpy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import TYPE_CHECKING
55
from uuid import uuid4
66

7+
import reactpy
78
from django import template
89
from django.templatetags.static import static
910
from django.urls import NoReverseMatch, reverse
@@ -244,7 +245,11 @@ def pyscript_setup(
244245
return {
245246
"pyscript_config": mark_safe(
246247
extend_pyscript_config(
247-
extra_py, extra_js, config, {static("reactpy_django/morphdom/morphdom-esm.js"): "morphdom"}
248+
extra_py,
249+
extra_js,
250+
config,
251+
{static("reactpy_django/morphdom/morphdom-esm.js"): "morphdom"},
252+
static(f"reactpy_django/wheels/reactpy-{reactpy.__version__}-py3-none-any.whl"),
248253
)
249254
),
250255
"pyscript_layout_handler": mark_safe(PYSCRIPT_LAYOUT_HANDLER),

src/scripts/install_deps.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""
2-
Development/debug script to parse pyproject.toml to find dependecies then install them in the local
3-
environment via `uv pip install -U <pkg_names>`
2+
Development/debug script to parse pyproject.toml to find dependencies, then install them in the
3+
current Python environment via `python -m uv pip install -U <pkg_names>`.
44
"""
55

66
import subprocess
7+
import sys
78
from pathlib import Path
89

910
import toml
@@ -29,8 +30,11 @@ def install_deps():
2930
pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml"
3031
pyproject_data = toml.load(pyproject_path)
3132
find_deps(pyproject_data)
32-
DEPENDENCIES.remove("ruff") # ruff only exists in dev dependencies for CI purposes.
33-
subprocess.run(["uv", "pip", "install", "-U", *DEPENDENCIES], check=False) # noqa: S607
33+
DEPENDENCIES.discard("ruff") # ruff only exists in dev dependencies for CI purposes.
34+
subprocess.run(
35+
[sys.executable, "-m", "uv", "pip", "install", "-U", *sorted(DEPENDENCIES)],
36+
check=True,
37+
)
3438

3539

3640
if __name__ == "__main__":

tests/test_app/tests/test_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def test_channel_layer_components(self):
577577
@navigate_to_page("/pyscript/")
578578
def test_pyscript_0_hello_world(self):
579579
# Use this test to wait for PyScript to fully load on the page
580-
self.page.wait_for_selector("#hello-world-loading")
580+
self.page.wait_for_selector("#hello-world-loading", timeout=30000)
581581
self.page.wait_for_selector("#hello-world")
582582

583583
@navigate_to_page("/pyscript/")

0 commit comments

Comments
 (0)