Non-rendered variable in the project-template name causes error
See original GitHub issue- Cookiecutter version: 1.7.2
- Python version: 3.7.5
- Operating System: OSX (10.14.6)
Description:
When using a non-rendered variable (starting with an underscore) for the directory-name, cookiecutter gives an error.
What I’ve run:
cookiecutter.json
{
"game_name": "",
"_game_slug": "{{ cookiecutter.game_name.lower().replace(' ', '-') }}",
"game_slug": "{{ cookiecutter.game_name.lower().replace(' ', '-') }}",
}
When I set the template-folder-name to {{cookiecutter.game_slug}}
(so I use the variable without the underscore) it will create the right directory:
terminal output
❯ cookiecutter boilerplate-project
game_name []: this is a test with CAPTIALS and spaces
game_slug [this-is-a-test-with-captials-and-spaces]:
👍
But when I replace use the non-rendered variable (_game_slug
) in the template-folder-name, it gives an error. The reason why I want the variable to be non-rendered, is because I want to base the variable-value on the game_name. And I don’t want an user to be able to overwrite this slug.
I get the following error:
❯ cookiecutter boilerplate-project
game_name []: this is a test with spaces and CAPITALS
game_slug [this-is-a-test-with-spaces-and-capitals]:
Traceback (most recent call last):
File "/usr/local/bin/cookiecutter", line 8, in <module>
sys.exit(main())
File "/usr/local/Cellar/cookiecutter/1.7.2/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/Cellar/cookiecutter/1.7.2/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/Cellar/cookiecutter/1.7.2/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/Cellar/cookiecutter/1.7.2/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/Cellar/cookiecutter/1.7.2/libexec/lib/python3.8/site-packages/cookiecutter/cli.py", line 140, in main
cookiecutter(
File "/usr/local/Cellar/cookiecutter/1.7.2/libexec/lib/python3.8/site-packages/cookiecutter/main.py", line 101, in cookiecutter
result = generate_files(
File "/usr/local/Cellar/cookiecutter/1.7.2/libexec/lib/python3.8/site-packages/cookiecutter/generate.py", line 352, in generate_files
generate_file(
File "/usr/local/Cellar/cookiecutter/1.7.2/libexec/lib/python3.8/site-packages/cookiecutter/generate.py", line 161, in generate_file
shutil.copyfile(infile, outfile)
File "/usr/local/Cellar/cookiecutter/1.7.2/libexec/lib/python3.8/shutil.py", line 261, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: "/Users/oskar/projects/gamedev/godot/test/{{ cookiecutter.game_name.lower().replace(' ', '-') }}/screens/.DS_Store"
And I have 2 folders where half of the files are in one and half are in the other:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Project contains too many procedure, variable, and constant ...
A project's procedure, variable, constant, and parameter names are stored in a name table. This error has the following cause and solution:.
Read more >ProjectTemplate.pdf - R Project
This function removes specific (or all by default) named objects from the global environment. If used within a ProjectTemplate project, then ...
Read more >Source code for cookiecutter.generate
"""Functions for generating a project from a project template. ... for variable, overwrite in overwrite_context.items(): if variable not in context: # Do ...
Read more >Project template not found - MicroStation Wiki
template into project folder. Error is caused by: Location of _USTN_PROJECTROOT does not contain "project.template" file. 1. Locate the ...
Read more >Development guide for GitLab CI/CD templates
yml immediately causes a lint error because there are no such jobs named performance in the included template anymore. Therefore, users have to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@edesz This example still fails for me (cookiecutter version 1.7.2):
However, if I rename the
{{cookiecutter.game_slug}}
directory to{{cookiecutter.game_name}}
then everything runs ok, andthis is a test with CAPTIALS and spaces/mytest.txt
is generated and contains the correctly rendered contents that you describe:This outcome, plus the two terminal outputs I’ve posted here, makes me think that maybe the project template is being generated first (before
cookiecutter.game_slug
has been created), and thenpre_gen_project.py
is being run afterwards?@simobasso Thanks for the response - my comment was to remark that @edesz 's example doesn’t work, for me at least, rather than to request help for an issue that I was having.
However, for completeness, the version at 623e4b9 still fails with the same error:
so I still think that maybe the project template is being generated first (before cookiecutter.game_slug has been created), and then pre_gen_project.py is being run afterwards?