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

First cut at issue 35: single file templates #885

Conversation

talwrii
Copy link

@talwrii talwrii commented Jan 6, 2017

Pull request for issue #35

I imagine people might have quite a lot of opinions about how this should be implemented. But I really want this feature, so I'll throw up a strawman for people to have opinions on.

The approach here is to add a _target setting to cookiecutter.json which gets rendered to a directory into which files get copied.

Demonstrating I've read the contributing file:

  • Can someone add a please-help tag to this request I don't have the permissions?
  • It is definitely possible to implement this outside of cookiecutter... but it's slightly perverse to have a separate utility for expanding a specific type of template.
  • I've written tests and run them with tox they pass for py27 and py35. If someone can tell me how to easily install 7 versions of python that would be useful.

Some thorny issues that people might have opinions on:

  • How file overwriting should work. I overwrite nothign unless the -f flag is given
  • Are we actually happy with relative paths
  • It's a bit perverse that you have to use a directory name like '{{cookiecutter.source}}' in the template which then gets ignored.

I've written some documentation but was unable to get make the documentation run, make servedocs hangs with

python -c "$BROWSER_PYSCRIPT" docs/_build/html/index.html
watchmedo shell-command -p '*.rst' -c 'make -C docs html' -R -D .

and no ports are listened on.

If __target__ is set in cookiecutter.json then
files are placed at this location within the directory
tree rather than creating a new directory.

Pre-existing files are unaffected. A common case
would be __target__ to '.' . The source directory
in the template can be any cookiecutter template expression,
but this is ignored. A value like {{cookiecutter.files}}
is suggested.
@talwrii talwrii force-pushed the talwrii--freestanding-files--issue-35--2017-01-06 branch from 71e3163 to 439112c Compare January 6, 2017 22:52
@talwrii talwrii changed the title First cut at issue 36: single file templates First cut at issue 35: single file templates Jan 6, 2017
@codecov-io
Copy link

codecov-io commented Jan 6, 2017

Current coverage is 100% (diff: 100%)

Merging #885 into master will not change coverage

@@           master   #885   diff @@
====================================
  Files          17     17          
  Lines         685    708    +23   
  Methods         0      0          
  Messages        0      0          
  Branches        0      0          
====================================
+ Hits          685    708    +23   
  Misses          0      0          
  Partials        0      0          

Powered by Codecov. Last update a111ed8...1cdb9d7

@talwrii
Copy link
Author

talwrii commented Jan 6, 2017

Fixing coverage at the moment.

Raise errors when overwriting files if not rendering
@talwrii
Copy link
Author

talwrii commented Jan 6, 2017

Okay that should fix the coverage.

Cue argument about "#pragma: no cover" in switch statement...

@talwrii
Copy link
Author

talwrii commented Jan 7, 2017

Okay, I've actually rendered the documentation and looked at it now.

At this point I'm tempted to do a rebase but imagine this might annoy people...

@talwrii
Copy link
Author

talwrii commented Jan 7, 2017

Some thoughts on actually using this in anger:

This feature allows you for have generated code co-existing with code that people have written, this opens up a number of issues:

  • We have to be very careful about some of the deletion logic here ("whoops I deleted your entire repository by mistake, sorry"). I started thinking things like "you should only overwrite this if I haven't changed it or marked it as modified)"
  • I found myself wanting to overwrite some files but not others. A specific use case: I created a setup.py (which I wanted to overwrite), but I also created a module in a package directory which I didn't.
  • This creates various complexities, is this (stable) tool actually the best place to deal with them?

@talwrii
Copy link
Author

talwrii commented Jan 11, 2017

Another potential-complexity / creeping-feature from using this in practice:

  • When using different templates in the same project I kept on wanting to have a shared context / replay between the different templates. The use case goes like this:

"Right, lets set up the base project with this cookie cutter"
"Let's add testing like this - hmm I need to re-enter all these details agauin"
"Let's add testing with nose rather py.test - hmm I need add the details again"
"Let's add a license as well"

I don't know what I think about the argument that these should all be in the same template...

@michaeljoseph michaeljoseph added the please-help This issue/PR contain help request to cookiecutter users or first-time contributors label Jan 14, 2017
@sergray
Copy link

sergray commented Jan 16, 2017

@talwrii,

  1. overwriting only if explicitly requested with a flag should be good enough
  2. not sure about {{cookiecutter.source}}, imagine someone would like to have such variable. What about using something like {{cookicutter.__tree__}}?

@talwrii
Copy link
Author

talwrii commented Jan 17, 2017

Thanks for the feedback @sergray

overwriting only if explicitly requested with a flag should be good enough

This is the current behaviour.

not sure about {{cookiecutter.source}}

I have no strong opinions about this. The directory can be called anything: {{cookiecutter.source}}, {{cookiecutter.foo}} or {{cookiecutter.__tree__}} all work fine. Using the value for something else has no effect. This implementation kind of naturally falls out of how the code is currently structured. I can throw in an assertion about the value though if constraining this prevents confusion.

@turing4ever
Copy link

It seems all checks have passed but the code hasn’t been merged?

@mmynsted
Copy link

Is anybody working on resolving the conflicts?

@insspb insspb added 1.8.0 and removed please-help This issue/PR contain help request to cookiecutter users or first-time contributors labels Dec 22, 2019
@ssbarnea ssbarnea added this to the 1.8.0 milestone Mar 30, 2020
@ssbarnea ssbarnea removed the 1.8.0 label Mar 30, 2020
@insspb insspb modified the milestones: 1.8.0, 2.0.0 May 26, 2020
@kurtmckee
Copy link
Member

I'm closing this PR due to its age.

@kurtmckee kurtmckee closed this Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants