question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty directories correctly named with rendered variable, but files are placed in separate, incorrectly named directory (as unrendered variable)

See original GitHub issue

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"

image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
mwilson8commented, Jan 22, 2021

Currently working for me install the version from that commit

pip install git+git://github.com/cookiecutter/cookiecutter.git@623e4b9f03b36bcd0c69acc52046cc4d98baac41
0reactions
xadamxkcommented, Jul 25, 2022

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does Vim create an empty directory named "~"
The fix I used was to leave the netrw_home variable undefined, and let it use the default value of the first directory on...
Read more >
How to Identify and Fix Common Problems in Premiere Pro
Premiere Pro expert Jarle Leirpoll identifies the most common Premiere Pro issues, and tells you how to fix them quickly and easily.
Read more >
Nunjucks Render
Namespace/Package Name: nunjucks. How can I render nunjucks template from controller I want to render html of another module with anycodings_nunjucks.
Read more >
Visualforce in Practice - Salesforce Developers
variables. We'll make the account name member transient so that only the record ID is being saved in the view state. The page...
Read more >
6 Solutions on Folder Shows Empty But Files Are There ...
If you encounter a problem that the folder shows empty but files are there on Windows 10/11, no worries!! This post will walk...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found