Skip to content

Fix FileExistsError when using a relative template path#1968

Merged
ericof merged 1 commit intomainfrom
unknown repository
Nov 9, 2023
Merged

Fix FileExistsError when using a relative template path#1968
ericof merged 1 commit intomainfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Oct 25, 2023

When using a local cookiecutter template that contains a pre_prompt script, cookiecutter will exit with a FileExistsError.

Reason for the FileExistsError is the input to create_tmp_repo_dir() which is just a simple dot. By converting the input into a Path object and using the Path.resolve() method we get the absolute path instead of the relative(.) and shutils.copytree() runs without an error.

OS: Windows 10
Launch Command: cookiecutter . --overwrite-if-exists
Fixes #1972

When using a local cookiecutter template ('cookiecutter .')
that contains a pre_prompt script, cookiecutter will exit
with a FileExistsError. The stack trace hints that the temporary
directory already exists and cannot be created by shutils.copytree.

By converting repo_dir into a Path object and calling resolve
to get the absolute path the actual name of the directory is used
instead of '.'.
@ghost ghost marked this pull request as draft October 25, 2023 08:03
@ghost ghost changed the title Fix FileExistsError on Windows when using a local template and pre_prompt.py exists Fix FileExistsError when using a relative path to point to a template Oct 25, 2023
@ghost ghost marked this pull request as ready for review October 25, 2023 08:10
@ghost ghost changed the title Fix FileExistsError when using a relative path to point to a template Fix FileExistsError when using a relative template path Oct 25, 2023
@ericof ericof added the bug This issue/PR relates to a bug. label Nov 9, 2023
Copy link
Copy Markdown
Member

@ericof ericof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this issue

@ericof ericof merged commit e751eb2 into cookiecutter:main Nov 9, 2023
@ghost ghost deleted the fix-windows-file-exists-error-with-pre-prompt branch November 15, 2023 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue/PR relates to a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pre_prompt bug when generating from current folder

1 participant