Question: how to programmatically bootstrap a cookiecutter
See original GitHub issue- Cookiecutter version:
cookiecutter==1.7.2
(current stable) - Python version:
Python==3.8.6
Description:
I am spooling up a cookiecutter
repository called my-cookiecutter
(not the real name), and have it checked out locally.
cookiecutter.json
{
"foo": "",
}
I have another repo called instance-01
(not the real name) where I want to have pre-supplied parameters for cookiecutter.json
in a file.
instance-01-cookiecutter-config.json
{
"foo": "bar",
}
I would like to run cookiecutter ../path/to/my-cookiecutter
and somehow take in the instance-01-cookiecutter-config.json
(instead of having to manually fill out prompts).
I have read through most of the cookiecutter
docs and many issues, and can’t figure out if this is something cookiecutter
can do.
In other words, how can I programmatically bootstrap a cookiecutter
? Is it possible?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
cookiecutter 1.7.0 documentation - Read the Docs
A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python package project ...
Read more >Compare Cookiecutter to Yeoman
Cookiecutter has a few questions to personalize the template — users specify how to name your project, what the license is, directory names...
Read more >Cookiecutter - Vue - Django: bootstrap your project with the ...
Great question. Properties can be passed directly from Django templates to top-level Vue components, without REST. There's an example: https:// ...
Read more >cookiecutter 0.9.1 - PyPI
cookiecutter -django: A bleeding edge Django project template with Bootstrap 3, customizable users app, starter templates, and working user registration.
Read more >Bootstrap Your Next Python Project With Cookiecutter - PyBites
I finally did it! I bootstrapped my first project with Cookiecutter. There is a lot to discover but wow this tool can save...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @jamesbraza, unless I’m misunderstanding the issue, this is exactly what
cookiecutter
’s--config-file
(docs) command line argument is designed to address. This is a YAML file that accepts adefault-context
block consisting of the template parameter’s name-value pairs (specified incookiecutter.json
) that will be injected as default values when you generate a templated project withcookiecutter
. This partly supports an input-less workflow. So, for example if you had{"foo": ""}
in yourcookiecutter.json
, then you could specify{"foo": "bar"}
as one of the name-value pairs in thedefault-context
block of a configuration file.With this, the template’s default values from this config file are set to be used when rendering the template. If you now run
cookiecutter --config-file <your-config-file>.yaml
,cookiecutter
will still prompt for input, but now the values from<your-config-file>.yaml
will be injected as the default values at the corresponding prompts. With this setup, you could usecookiecutter
in two wayscookiecutter
template as usual with then you would get as the prompt forfoo
but you have to manually enter a value before you can pressEnter
.foo
. Now, you can simply pressEnter
without needing to supply any value because the value forfoo
will be automatically set tobar
(which comes from<your-config-file>.yaml
).So, what’s left to do now, is to inform
cookiecutter
to actually skip all prompts. To avoid any user input, the CLI argument--no-input
(docs) is required. This skips any prompts and uses the values fromcookiecutter.json
. However, since a custom configuration file is also being specified, those config file settings are treated like the defaults incookiecutter.json
and so those parameters are used in the template.To summarize all this, here’s a simple example of the overall workflow
/home/<username>/my-cookiecutter/cookiecutter.json
/home/<username>/my-cookiecutter/config.yaml
, which will allow you to automatically specify a value forfoo
when generating a templateNotes
default_context
block of the user config file are injected into all cookiecutter projects. So, after generating your first project template (but before you generate your second project template), you would need to replace these config file values with a new set of defaults that are specific to the second template to be rendered.Hope this helps with your question.
Additional Links
I was looking at last commits and I saw this one :
https://github.com/cookiecutter/cookiecutter/commit/d74b085260248f5ab180f9e582ea973108fa3e2b
Cookiecutter authors added a new option for selecting replay file.
This is not exactly what we want 😃 but it can be an alternative or the beginning of a new option 😃