浏览代码

clean pycache after downloading template, fixes #4135 (#5014)

* clean pycache after downloading template, fixes #4135

* simplify logic
Khaleel Al-Adhami 1 月之前
父节点
当前提交
c7b9bb3e4e
共有 1 个文件被更改,包括 6 次插入5 次删除
  1. 6 5
      reflex/utils/prerequisites.py

+ 6 - 5
reflex/utils/prerequisites.py

@@ -905,11 +905,12 @@ def initialize_app_directory(
 
     console.debug(f"Using {template_name=} {template_dir=} {template_code_dir_name=}.")
 
-    # Remove all pyc and __pycache__ dirs in template directory.
-    for pyc_file in template_dir.glob("**/*.pyc"):
-        pyc_file.unlink()
-    for pycache_dir in template_dir.glob("**/__pycache__"):
-        pycache_dir.rmdir()
+    # Remove __pycache__ dirs in template directory and current directory.
+    for pycache_dir in [
+        *template_dir.glob("**/__pycache__"),
+        *Path.cwd().glob("**/__pycache__"),
+    ]:
+        shutil.rmtree(pycache_dir, ignore_errors=True)
 
     for file in template_dir.iterdir():
         # Copy the file to current directory but keep the name the same.