Empty directories correctly named with rendered variable, but files are placed in separate, incorrectly named directory (as unrendered variable)
See original GitHub issue- Cookiecutter version: 1.7.2
- Template project url: https://github.com/ianscottknight/cookiecutter-data-science-poetry-template/tree/0.1.1
- Python version: 3.8.5
- Operating System: macOS Catalina 10.15.6
Description:
I’ve got a basic poetry project cookiecutter template, that I’ve defined to take some basic variables like project_name, author_name, etc., and set up a poetry project with my pre-defined data science project structure. I was running a test using a dummy name “project_name”, which should produce the cookiecutter.__repo_name variable as “project-name”. Running cookiecutter correctly creates the repo “project-name” and populates it with all the correct directories, such that the directories all match up with my designated project structure. However, all the directories are empty, and the actual files are placed in a separately created directory called, literally, “{{ cookiecutter.project_name|lower|replace(’ ‘, ‘-’)|replace(’_', ‘-’) }}”, which is placed in my home directory, adjacent to “project-name”. It is only able to create the files in the top-level directory, and produces a FileNotFoundError since one of the deeper files is missing. So, it seems that there is some problem with filepaths for files that does not exist for directories.
What I’ve run:
cookiecutter.json
{
"project_name": "project_name",
"__repo_name": "{{ cookiecutter.project_name|lower|replace(' ', '-')|replace('_', '-') }}",
"version": "0.1.0",
"description": "",
"author_name": "Ian Scott Knight",
"author_email": "isk@alumni.stanford.edu",
"license": ["MIT", "BSD-3", "GNU GPL v3.0", "Apache Software License 2.0"]
}
Terminal command (note that I am using a specific branch that is not the main branch):
cookiecutter https://github.com/ianscottknight/cookiecutter-data-science-poetry-template.git --checkout 0.1.1
Terminal output:
project_name [project_name]:
version [0.1.0]:
description []:
author_name [Ian Scott Knight]:
author_email [isk@alumni.stanford.edu]:
Select license:
1 - MIT
2 - BSD-3
3 - GNU GPL v3.0
4 - Apache Software License 2.0
Choose from 1, 2, 3, 4 [1]:
Traceback (most recent call last):
File "/usr/local/bin/cookiecutter", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/cookiecutter/cli.py", line 140, in main
cookiecutter(
File "/usr/local/lib/python3.8/site-packages/cookiecutter/main.py", line 101, in cookiecutter
result = generate_files(
File "/usr/local/lib/python3.8/site-packages/cookiecutter/generate.py", line 352, in generate_files
generate_file(
File "/usr/local/lib/python3.8/site-packages/cookiecutter/generate.py", line 179, in generate_file
with io.open(outfile, 'w', encoding='utf-8') as fh:
FileNotFoundError: [Errno 2] No such file or directory: "/Users/ianscottknight/{{ cookiecutter.project_name|lower|replace(' ', '-')|replace('_', '-') }}/project_name/__init__.py"
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5
Top GitHub Comments
Currently working for me install the version from that commit
I’m using CookieCutter v2.1.1 and am facing this issue. The proposed fixes above are not working along with this thread: https://github.com/cookiecutter/cookiecutter/issues/1430#issuecomment-765634948
Anyone have a fix?