Skip to content

Commit 323a49e

Browse files
committed
Overwrite existing files when renaming
To support updating projects by regenerating the template, we need to handle the case of existing files. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent fde8ad1 commit 323a49e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cookiecutter/hooks/post_gen_project.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,12 @@ def finish_api_setup() -> None:
358358
* Rename `src` to `py`
359359
* Rename `tests` to `pytests`
360360
"""
361-
_pathlib.Path("src").rename("py")
362-
_pathlib.Path("tests").rename("pytests")
361+
# We can't do a simple rename because the target directory might not be empty if
362+
# overwriting an existing project.
363+
_shutil.copytree("src", "py", dirs_exist_ok=True)
364+
_shutil.rmtree("src")
365+
_shutil.copytree("tests", "pytests", dirs_exist_ok=True)
366+
_shutil.rmtree("tests")
363367

364368

365369
def finish_app_setup() -> None:

0 commit comments

Comments
 (0)