Skip to content

Commit 59bbdcd

Browse files
authored
do not delete the .web dir when init-ing (#5319)
1 parent e65a396 commit 59bbdcd

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

reflex/utils/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def setup_frontend(
230230
"""
231231
# Create the assets dir if it doesn't exist.
232232
path_ops.mkdir(constants.Dirs.APP_ASSETS)
233-
path_ops.cp(
233+
path_ops.copy_tree(
234234
src=str(root / constants.Dirs.APP_ASSETS),
235235
dest=str(root / prerequisites.get_web_dir() / constants.Dirs.PUBLIC),
236236
ignore=tuple(f"*.{ext}" for ext in constants.Reflex.STYLESHEETS_SUPPORTED),

reflex/utils/path_ops.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@ def rm(path: str | Path):
4242
path.unlink()
4343

4444

45+
def copy_tree(
46+
src: str | Path,
47+
dest: str | Path,
48+
ignore: tuple[str, ...] | None = None,
49+
):
50+
"""Copy a directory tree.
51+
52+
Args:
53+
src: The path to the source directory.
54+
dest: The path to the destination directory.
55+
ignore: Ignoring files and directories that match one of the glob-style patterns provided
56+
"""
57+
src = Path(src)
58+
dest = Path(dest)
59+
if dest.exists():
60+
for item in dest.iterdir():
61+
rm(item)
62+
shutil.copytree(
63+
src,
64+
dest,
65+
ignore=shutil.ignore_patterns(*ignore) if ignore is not None else ignore,
66+
dirs_exist_ok=True,
67+
)
68+
69+
4570
def cp(
4671
src: str | Path,
4772
dest: str | Path,
@@ -65,12 +90,7 @@ def cp(
6590
if not overwrite and dest.exists():
6691
return False
6792
if src.is_dir():
68-
rm(dest)
69-
shutil.copytree(
70-
src,
71-
dest,
72-
ignore=shutil.ignore_patterns(*ignore) if ignore is not None else ignore,
73-
)
93+
copy_tree(src, dest, ignore)
7494
else:
7595
shutil.copyfile(src, dest)
7696
return True

reflex/utils/prerequisites.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ def initialize_web_directory():
980980
project_hash = get_project_hash()
981981

982982
console.debug(f"Copying {constants.Templates.Dirs.WEB_TEMPLATE} to {get_web_dir()}")
983-
path_ops.cp(constants.Templates.Dirs.WEB_TEMPLATE, str(get_web_dir()))
983+
path_ops.copy_tree(constants.Templates.Dirs.WEB_TEMPLATE, str(get_web_dir()))
984984

985985
console.debug("Initializing the web directory.")
986986
initialize_package_json()

0 commit comments

Comments
 (0)