Browse Source

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

* clean pycache after downloading template, fixes #4135

* simplify logic
Khaleel Al-Adhami 1 month ago
parent
commit
c7b9bb3e4e
1 changed files with 6 additions and 5 deletions
  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.