Cookiecutter: NonTemplatedInputDirException on template with static file names.

Created on 19 Apr 2018  路  7Comments  路  Source: cookiecutter/cookiecutter

  • Cookiecutter version: 1.6.0
  • Python version: 2.7
  • Operating System: macOS High Sierra

Description:

I'm trying to generate a template that creates a couple of test files for my project.

my-template/
--- cookiecutter.json
--- resolvers.test.js
--- test-fixtures.js

What I've run:

// Inside dir where I want to create the test files.
cookiecutter /path/to/my-template

I get cookiecutter.exceptions.NonTemplatedInputDirException

Traceback (most recent call last):
  File "/usr/local/bin/cookiecutter", line 11, in <module>
    load_entry_point('cookiecutter==1.6.0', 'console_scripts', 'cookiecutter')()
  File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/cookiecutter/cli.py", line 120, in main
    password=os.environ.get('COOKIECUTTER_REPO_PASSWORD')
  File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/cookiecutter/main.py", line 94, in cookiecutter
    output_dir=output_dir
  File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/cookiecutter/generate.py", line 257, in generate_files
    template_dir = find_template(repo_dir)
  File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/cookiecutter/find.py", line 36, in find_template
    raise NonTemplatedInputDirException
cookiecutter.exceptions.NonTemplatedInputDirException

I believe this is because none of my template files use variables in their names, e.g. {{cookiecutter.modelName}}-resolvers.test.js is there a way to skip that requirement?

Most helpful comment

But wait what? So I _have_ to use a templated root dir? What if I want cookiecutter to create a templated dir inside an existing dir, such as A/b/{{cookiecutter.slug_name}}? Is that really something that breaks the initial vision you mentioned earlier?

Or perhaps you just want to create some templated files inside an existing folder. Why is there a requirement for every folder to be templated?

All 7 comments

I just got this error as well! Is there any updates on how to resolve it?

$ cookiecutter --version
Cookiecutter 1.6.0 from /home/vanessa/anaconda3/lib/python3.6/site-packages (Python 3.6)

Apologies, but you are asking for a proven feature of Cookiecutter to be removed.

The design of Cookiecutter is for the template to have a top level directory to have template configuration files. For example, this means you can use continuous integration and pytest-cookies to confirm your project template isn't broken on a change. Reference Cookiecutter Django's root directory, including tests, travis-ci.yml, tox.ini, and others to see how this works in a real-world project.

So allowing top level files to be included in a generated template just isn't going to happen. It breaks the original architecture envisioned by @audreyr. Instead, you need to create a {{cookiecutter.project_slug}} or other similarly named directory for your project.

thanks @pydanny ! I'm a new user and was able to figure this out - I just didn't know that the entire thing needed to be in a subfolder (I had the cookiecutter.json on the same level as a bunch of things). Once I put everything into a directory named by the slug, it worked. I am adding this note so others know my predicament (and solution) as well. The other challenge I ran into was having jinja2 files templated, and the solution was to add {% raw %} and {% endraw %} This is a great project!

But wait what? So I _have_ to use a templated root dir? What if I want cookiecutter to create a templated dir inside an existing dir, such as A/b/{{cookiecutter.slug_name}}? Is that really something that breaks the initial vision you mentioned earlier?

Or perhaps you just want to create some templated files inside an existing folder. Why is there a requirement for every folder to be templated?

I don't see the point.
In which way does it make impossible to test?

Having to have a templated root does break some use cases, like using it to create dev files inside a pre-created repository. Forces me to hack around with hooks when it could easily (and safely) be handled by cookiecutter.

Basically what nobody will actually come out and say is you need a directory structure like this:

 - template
      - cookiecutter.json
      - somefolder
            - filea.txt
      - some_file.py

Your cookiecutter.json needs to be in the template root

I ran into the same issue. Without commenting on whether cookiecutter should support this use case or not, this is the workaround I came up with. This template will add a license.txt to the current directory:

# cookiecutter.json
{}

# {{cookiecutter and '%'}}/license.txt
[the license]

# hooks/post_gen_project.sh
#! /usr/bin/env bash

set -eu
mv * ..
rm ../%

% is just used as the name of the directory created when the template is instantiated and removed later. Mind you that implemented like this, it will overwrite already existing files with the same name as in the template.

Was this page helpful?
0 / 5 - 0 ratings