The project I'm trying to template has the following line in a YAML file:
- v1-dependencies-{{ checksum "requirements.txt" }}
It runs on CircleCI and creates a hash of the requirements file to determine if the cached packages are still valid. The file also has parts that I'd like to template in like {{cookiecutter.project_name}}. When I run it on this project, cookiecutter tries to replace the first line and fails.
DB_NAME [MYTEST_local]:
DB_USER []:
DB_PASSWORD []:
DB_PORT [5432]:
DATABASE_URL [127.0.0.1]:
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 364, in generate_files
generate_file(project_dir, infile, context, env)
File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/cookiecutter/generate.py", line 166, in generate_file
tmpl = env.get_template(infile_fwd_slashes)
File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/jinja2/environment.py", line 830, in get_template
return self._load_template(name, self.make_globals(globals))
File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/jinja2/environment.py", line 804, in _load_template
template = self.loader.load(self, name, globals)
File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/jinja2/loaders.py", line 125, in load
code = environment.compile(source, name, filename)
File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/jinja2/environment.py", line 591, in compile
self.handle_exception(exc_info, source_hint=source_hint)
File "/usr/local/Cellar/cookiecutter/1.6.0/libexec/lib/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "./.circle/config.yml", line 21, in template
jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got 'string'
File "./.circle/config.yml", line 21
- v1-dependencies-{{ checksum "requirements.txt" }}
I see two options, but I'm not sure if there's a way to implement them without changes to the codebase:
cookiecutter.json and suppress the prompt to change them. I've seen that there is a --no-input flag, but this will apply to all variables in the project.I read some suggestions in jinja documentation.
In particular this circleci/config.yml snippet works in the cookie cutter template:
- restore_cache:
key: {{ cookiecutter.project_dash_slug }}-{% raw %}{{ .Branch }}-{{ checksum "Pipfile.lock" }}-{{ checksum "_tmp_file" }}{% endraw %}
The first item is a cookiecutter config, the last three are circleci options
Most helpful comment
In particular this circleci/config.yml snippet works in the cookie cutter template:
The first item is a cookiecutter config, the last three are circleci options