Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: Path templates will be rendered when copy_without_render used #839

Merged
merged 1 commit into from May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cookiecutter/generate.py
Expand Up @@ -323,6 +323,7 @@ def generate_files(
for copy_dir in copy_dirs:
indir = os.path.normpath(os.path.join(root, copy_dir))
outdir = os.path.normpath(os.path.join(project_dir, indir))
outdir = env.from_string(outdir).render(**context)
logger.debug('Copying dir %s to %s without rendering', indir, outdir)
shutil.copytree(indir, outdir)

Expand Down
11 changes: 11 additions & 0 deletions docs/advanced/copy_without_render.rst
Expand Up @@ -15,3 +15,14 @@ To avoid rendering directories and files of a cookiecutter, the `_copy_without_r
"rendered_dir/not_rendered_file.ini"
]
}

**Note**: Only the content of the files will be copied without being rendered. The paths are subject to rendering. This allows you to write::

{
"project_slug": "sample",
"_copy_without_render": [
"{{cookiecutter.repo_name}}/templates/*.html",
]
}

In this example, `{{cookiecutter.repo_name}}` will be rendered as expected but the html file content will be copied without rendering.
@@ -0,0 +1,3 @@
# Fake Project

{{cookiecutter.render_test}}
12 changes: 10 additions & 2 deletions tests/test_generate_copy_without_render.py
Expand Up @@ -31,6 +31,7 @@ def test_generate_copy_without_render_extensions():
'*not-rendered',
'rendered/not_rendered.yml',
'*.txt',
'{{cookiecutter.repo_name}}-rendered/README.md',
],
}
},
Expand All @@ -39,7 +40,7 @@ def test_generate_copy_without_render_extensions():

dir_contents = os.listdir('test_copy_without_render')

assert '{{cookiecutter.repo_name}}-not-rendered' in dir_contents
assert 'test_copy_without_render-not-rendered' in dir_contents
assert 'test_copy_without_render-rendered' in dir_contents

with open('test_copy_without_render/README.txt') as f:
Expand All @@ -59,9 +60,16 @@ def test_generate_copy_without_render_extensions():
assert 'I have been rendered' in f.read()

with open(
'test_copy_without_render/{{cookiecutter.repo_name}}-not-rendered/README.rst'
'test_copy_without_render/'
'test_copy_without_render-not-rendered/'
'README.rst'
) as f:
assert '{{cookiecutter.render_test}}' in f.read()

with open('test_copy_without_render/rendered/not_rendered.yml') as f:
assert '{{cookiecutter.render_test}}' in f.read()

with open(
'test_copy_without_render/' 'test_copy_without_render-rendered/' 'README.md'
) as f:
assert '{{cookiecutter.render_test}}' in f.read()