Using and Mastering Cookiecutter Transcripts
Chapter: Advanced Cookiecutter usage
Lecture: Concept: Default values

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Here is a slightly richer default configuration file, for Cookiecutter. So we've seen the default context, and these are the values
0:10 that get past to the actual templates to overwrite their defaults, so we've added full name, email and GitHub username,
0:18 so we don't have to type that again, we can also set some directories, right, so we can come down here and say if I don't want .cookiecutters
0:27 to be the folder where it does a checkout and where it manages all my Cookiecutter data, well, I can change cookiecutters_dir put that somewhere else.
0:35 Similarly, there is a replay directory that takes the inputs you give the template,
0:39 we'll talk about that later, but you can overwrite that directory as well. You can also create little shortcuts, so if you want to
0:45 instead of type https://bitbucket.org/something, you could just type bb:thatthing, or even if you want just a shorter version, just ps,
0:54 so if I want to run Pyramid Cookiecutter starter often, I could just say cookiecutter ps enter and that would run that template over and over again.
1:03 You can see, we have the little {0} string format type things to fill in pieces, so you can create really interesting little aliases here.
1:10 In order for you to avoid typing the config file name all the time, just do set up an environment variable, COOKIECUTTER_CONFIG
1:19 and set its value to be wherever that file lives. So on Linux or macOS you say export COOKIECUTTER_CONFIG=this
1:27 and you put that into your ~/.profile, your ~/.zshrc wherever your shell startup script is.
1:34 So this sets the environment variable so Cookiecutter will always use it, unless you specify --default-config and then it says
1:41 I know there is this environment variable set, but just run the thing entirely from scratch, which is mostly used
1:47 for when you either want to see what their defaults would have been or if you're developing your own templates
1:53 and you want to make sure the defaults work okay. Now, how about on Windows, if we're going to do this on Windows,
1:58 you don't have like a ~/.profile file, instead, you have a GUI for managing your environment variables, so open up the Control panel,
2:05 go to System and then click on Advanced system settings, it will open up this dialogue, click on Environment Variables there,
2:12 it will open up this dialogue and then you can add a New User Variable. So COOKIECUTTER_CONFIG and then you put the path
2:21 to wherever you happen to want it to be, right, I put it in the .cookiecutters folder, you can put it wherever you like.
2:27 Now, just, it seemed odd to me, but for some reason, I think actually I had to reboot Windows, at least log out, for it to take this value,
2:34 it seems like it was really not working, like restarting my terminal or my command prompt was not enough, I had to actually reboot Windows or log out,
2:41 so just be aware that you might have to give this thing a strong kick to get it to take it, maybe you will have better luck than me, I don't know.
2:48 Alright, so let's see these default values in action, create that file and register the environment variable either in ~/.profile
2:53 or in Windows in the environment variables, we run it, we can say hit enter, go. And now, you can see it's pulling all of our variables in,
3:01 and putting them as the default, so you can just hit enter, enter, enter, and it will accept Michael Kennedy, michael@talkPython,fm, and so on.
3:08 That's much better.


Talk Python's Mastodon Michael Kennedy's Mastodon