Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 53d8194

Browse files
committedOct 23, 2024·
create generic copy_js_files util
1 parent 25ff8c6 commit 53d8194

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed
 

‎setup.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@
9999
# ----------------------------------------------------------------------------
100100
# Build Javascript
101101
# ----------------------------------------------------------------------------
102+
def copy_js_files(source_dir: Path, destination: Path) -> None:
103+
if destination.exists():
104+
shutil.rmtree(destination)
105+
destination.mkdir()
106+
107+
for file in source_dir.iterdir():
108+
if file.is_file():
109+
shutil.copy(file, destination / file.name)
110+
else:
111+
copy_js_files(file, destination / file.name)
112+
113+
102114
def build_javascript_first(build_cls: type):
103115
class Command(build_cls):
104116
def run(self):
@@ -133,18 +145,12 @@ def run(self):
133145
log.info("Copying @pyscript/core distribution")
134146
pyscript_dist = js_dir / "node_modules" / "@pyscript" / "core" / "dist"
135147
pyscript_static_dir = static_dir / "pyscript"
136-
if not pyscript_static_dir.exists():
137-
pyscript_static_dir.mkdir()
138-
for file in pyscript_dist.iterdir():
139-
shutil.copy(file, pyscript_static_dir / file.name)
148+
copy_js_files(pyscript_dist, pyscript_static_dir)
140149

141150
log.info("Copying Morphdom distribution")
142151
morphdom_dist = js_dir / "node_modules" / "morphdom" / "dist"
143152
morphdom_static_dir = static_dir / "morphdom"
144-
if not morphdom_static_dir.exists():
145-
morphdom_static_dir.mkdir()
146-
for file in morphdom_dist.iterdir():
147-
shutil.copy(file, morphdom_static_dir / file.name)
153+
copy_js_files(morphdom_dist, morphdom_static_dir)
148154

149155
log.info("Successfully built Javascript")
150156
super().run()

‎tests/test_app/__init__.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,39 @@
2121
== 0
2222
)
2323

24-
# Make sure the current PyScript distribution is always available
25-
pyscript_dist = js_dir / "node_modules" / "@pyscript" / "core" / "dist"
26-
pyscript_static_dir = (
24+
25+
# Make sure the test environment is always using the latest JS
26+
def copy_js_files(source_dir: Path, destination: Path) -> None:
27+
if destination.exists():
28+
shutil.rmtree(destination)
29+
destination.mkdir()
30+
31+
for file in source_dir.iterdir():
32+
if file.is_file():
33+
shutil.copy(file, destination / file.name)
34+
else:
35+
copy_js_files(file, destination / file.name)
36+
37+
38+
# Copy PyScript
39+
copy_js_files(
40+
js_dir / "node_modules" / "@pyscript" / "core" / "dist",
2741
Path(__file__).parent.parent.parent
2842
/ "src"
2943
/ "reactpy_django"
3044
/ "static"
3145
/ "reactpy_django"
32-
/ "pyscript"
46+
/ "pyscript",
3347
)
34-
if not pyscript_static_dir.exists():
35-
pyscript_static_dir.mkdir()
36-
for file in pyscript_dist.iterdir():
37-
shutil.copy(file, pyscript_static_dir / file.name)
38-
39-
# Make sure the current Morphdom distrubiton is always available
40-
morphdom_dist = js_dir / "node_modules" / "morphdom" / "dist"
41-
morphdom_static_dir = (
48+
49+
50+
# Copy MorphDOM
51+
copy_js_files(
52+
js_dir / "node_modules" / "morphdom" / "dist",
4253
Path(__file__).parent.parent.parent
4354
/ "src"
4455
/ "reactpy_django"
4556
/ "static"
4657
/ "reactpy_django"
47-
/ "morphdom"
58+
/ "morphdom",
4859
)
49-
if not morphdom_static_dir.exists():
50-
morphdom_static_dir.mkdir()
51-
for file in morphdom_dist.iterdir():
52-
shutil.copy(file, morphdom_static_dir / file.name)

0 commit comments

Comments
 (0)
Please sign in to comment.