Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion reflex/utils/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def setup_frontend(
"""
# Create the assets dir if it doesn't exist.
path_ops.mkdir(constants.Dirs.APP_ASSETS)
path_ops.cp(
path_ops.copy_tree(
src=str(root / constants.Dirs.APP_ASSETS),
dest=str(root / prerequisites.get_web_dir() / constants.Dirs.PUBLIC),
ignore=tuple(f"*.{ext}" for ext in constants.Reflex.STYLESHEETS_SUPPORTED),
Expand Down
32 changes: 26 additions & 6 deletions reflex/utils/path_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ def rm(path: str | Path):
path.unlink()


def copy_tree(
src: str | Path,
dest: str | Path,
ignore: tuple[str, ...] | None = None,
):
"""Copy a directory tree.

Args:
src: The path to the source directory.
dest: The path to the destination directory.
ignore: Ignoring files and directories that match one of the glob-style patterns provided
"""
src = Path(src)
dest = Path(dest)
if dest.exists():
for item in dest.iterdir():
rm(item)
shutil.copytree(
src,
dest,
ignore=shutil.ignore_patterns(*ignore) if ignore is not None else ignore,
dirs_exist_ok=True,
)


def cp(
src: str | Path,
dest: str | Path,
Expand All @@ -65,12 +90,7 @@ def cp(
if not overwrite and dest.exists():
return False
if src.is_dir():
rm(dest)
shutil.copytree(
src,
dest,
ignore=shutil.ignore_patterns(*ignore) if ignore is not None else ignore,
)
copy_tree(src, dest, ignore)
else:
shutil.copyfile(src, dest)
return True
Expand Down
2 changes: 1 addition & 1 deletion reflex/utils/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ def initialize_web_directory():
project_hash = get_project_hash()

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

console.debug("Initializing the web directory.")
initialize_package_json()
Expand Down