Using and Mastering Cookiecutter Transcripts
Chapter: Programmatic Cookiecutter: Using the API
Lecture: Concept: Cookiecutter API

Login or purchase this course to watch this video and the rest of the course contents.
0:01 The Cookiecutter API is quite rich, but also simple to use.
0:06 Basically, the way it works is you ship your app with a template in some way,
0:11 or I suppose if you care to depend on the internet
0:14 you can even ship it straight off GitHub, right, just use the URL.
0:17 And we want to call one function, cookicutter.main.cookiecutter
0:21 So, we just call this, we need to pass it an absolute path to our template
0:26 so it knows where that is and in Python it's really easy,
0:29 you just use the dunder file and you can sort of work out a relative path
0:32 with os.path module; now you want to be sure to set no_input to True.
0:37 Otherwise Cookiecutter is going to ask the questions
0:40 that are in cookiecutter.json well, you don't want that, right,
0:44 this is your application, it can ask those questions
0:47 and it can be much smarter and conditional
0:49 and retrying about the answers that it gets.
0:52 You also need to specify where this is going to output the data
0:56 so we're going to set-up a directory here we've already computed this
0:59 actually we asked the user where that was and verified it,
1:02 and then you need to pass along the questions
1:05 that Cookiecutter itself would ask in the extra context here.
1:09 So we've gathered all of the questions that would have been asked
1:13 what is a project_name, full_name and game_type we've asked the user
1:16 what that was, and then we just passed it along,
1:19 so Cookiecutter just takes those and applies them directly
1:22 and doesn't ask any questions.
1:25 And then what comes back is the project directory
1:27 and we can open that up, we can execute code in there, whatever.
1:30 We also want to make sure that we're leveraging the defaults,
1:33 so if somebody is using Cookiecutter already, and they have a default file,
1:37 we want to be sure to use that, so we can import cookiecutter.config
1:41 and then call .get_user_config(), alright, and that will give us this whole dictionary back,
1:47 everything about them as far as Cookiecutter is concerned,
1:50 Cookiecutetr directory, the replay directory, even their aliases
1:54 which are not shown in here, but the pert that matters to us is the default context,
1:57 so grab that and then you can use that before we even start asking questions
2:02 propose that as a default, or even don't ask the question if you find it here.
2:05 We've just scratched the surface of the API here
2:08 there is quite a bit going on so jump over to the read the docs
2:10 for the Cookicutter package and you can explore the full API here.