Using and Mastering Cookiecutter Transcripts
Chapter: Advanced Cookiecutter usage
Lecture: Setting up default values

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Okay so here we are in chapter 4, in the source control area. Let's go ahead and try cookiecutter cookiecutter-bottle
0:09 You can see it's asking various things, like these are just the defaults, let's see how we can change these, so what we can do is
0:16 we can actually create a default file and the format of this file is going to be a YAML file.
0:21 And you can put it wherever you want and then you point to it in Cookiecutter, but I am going to put it in that Cookiecutters folder
0:28 because that's where I go for my Cookiecutter stuff. So you can call this whatever you want, it doesn't matter,
0:33 there is no like convention around naming, so I am going to call mine defaults-kennedy.yaml,
0:37 we open this up and what we can put in here is a couple of things, so we can start out by saying our default_context
0:44 and then we set properties by doing colon here, so we can set our full name, go and set our email here,
0:50 now there is no scheme or anything here, it just happens to be if the template asks you for full_name it's going to look in here
0:59 to see if there is a value and use this instead of their default. So you might have fullname, you might have also fullName, right,
1:07 you might have to enter these things several times, but once we have this here, we can save this
1:12 and we can run the same thing with specifying the config file. Like so, let's see what we got, oh look, what is your full_name,
1:27 my full name is Michael, and my email is this, and my GitHub username is this, oh so refreshing.
1:32 And of course we probably don't have a default project name or app name or things like that, or a really project description,
1:38 so these I don't really know how to set defaults for these unless you create almost exactly the same app all the time,
1:43 so that's cool, so we can do this, now it would be great if I just ran it like this,
1:47 I don't have to say the config file, it would give me my values but clearly,
1:50 it's not, so there is one final step for us to do, we need to go into our profile, that starts our shell, and set an environment variable,
1:59 now if you're on Windows, you have to do this in a slightly different way, you just set an environment variable under the "Advanced system settings".
2:05 Okay, but for now, let's do it on my Mac and then I can show you how to do it on Windows as well.
2:11 So we're going to manage our ~/.profile here and notice, I've got my path and my prompt but let's put it at the bottom,
2:17 what we want to do is we just want to put export statement that says the Cookiecutter config that you use is here,
2:25 /Users/screeencaster/.cookiecutters/defaults-kennedy.yaml alright, so if we go back over here, and we try to run this,
2:34 it's still the same, why, because we have to exit and start over. Now, let's try one more time, okay,
2:43 so we're going to say cookiecutter cookiecutter-bottle hit enter, and perfect, it's now taken our defaults, so what we had to do is
2:53 we had to create that YAML file with our defaults, and then we had to set an environment variable here
2:58 the name of the environment variable is COOKICUTTER_CONFIG all caps and then just point at whatever the path is, so let's go ahead and roll with this,
3:06 enter, enter, enter, oh, that felt good, I'll call this Second Bottle App, let's just call it secondbottle and a demo of default values,
3:16 off it goes, and there we know we have our secondbottle created, this time, using our default values.

Talk Python's Mastodon Michael Kennedy's Mastodon