Using and Mastering Cookiecutter Transcripts
Chapter: Creating Cookiecutter templates
Lecture: Concept: Bare template

Login or purchase this course to watch this video and the rest of the course contents.
0:01 We saw that the project folder structure is one of the core things we have to work with, when creating these templates.
0:08 So here we're going to create a project, a Cookicutter template and we're calling it your project name,
0:15 probably it should be cookiecutter-your-project-name, or something to that effect, the top level directory called
0:20 your project name here, this is actually the name of the Cookicutter template, not the thing it generates,
0:27 and we also have a notes.txt, a readme.md, maintainers.md, these are just files that come along with the template
0:34 that will not ever make their way to the user, but whoever comes to the template they can read those they can use those,
0:40 there could even be a little scripts that do things for you. We saw there is basically two things for this to be a Cookiecutter template,
0:46 one we have to have our JSON file here, our cookiecutter.json, this tells Cookiecutter two things, what are the replaceable values that we can use,
0:57 and what default values do they have, the other thing is what are the prompts, basically they are the same thing, what questions do we ask the user.
1:05 Okay, so that is that one, we also need a project, so here we're going to have a {{cookiecutter.project_name}} thing,
1:13 this is all Jinja type expressions, and then, whatever we want to copy and modify for the users, we're going to put that where ... goes,
1:23 as a subdirectory, or subfiles under this directory here. Now, this is a simplified version of the template,
1:29 there is actually other things like pre and post generation hooks and whatnot, but remember, we're starting from a bare directory,
1:35 a bare project and we're going to get more advanced and bring these things in as they make sense. If we want to run this,
1:40 we are going to come here and we're going to enter the cookiecutter and then we'll say the name or location of the template,
1:46 if we've already installed it off of GitHub or somewhere like that we can say the short name, in this case pyramid-cookiecutter-starter
1:52 already given the full GitHub name and it's cloned into .cookiecutters, but if we don't, of course we have to say the full name, or if it's local,
1:59 we have to say the actual file path to it, and in there, there is a cookiecutter.json with a bunch of questions, project name, repo name,
2:06 notice here we have an interesting pick number 1 or number 2 out of this list. That is called a choice value and we'll get the choice values later,
2:13 so where do these questions come from? They come from cookiecutter.json, right, we've already seen this,
2:19 the keys here in this JSON object are the questions or the replaceable values and the values in the cookiecutter.json those are the default values.
2:27 So that's it, you can see it is really really simple to create these Cookiecutter templates
2:34 and with all the benefits available to you that I laid out at the beginning,
2:37 why not, right, this is so easy to add so much reproducibility and reliability to almost any type of software project
2:44 or just file structured thing that you're doing.


Talk Python's Mastodon Michael Kennedy's Mastodon