cookiecutter Package

cookiecutter Package

cookiecutter

Main package for Cookiecutter.

cleanup Module

cookiecutter.cleanup

Functions for cleaning up after Cookiecutter project generation occurs.

cookiecutter.cleanup.remove_repo(repo_dir, generated_project)[source]

Move the generated project to the same level as repo_dir, then delete repo_dir.

Called when Cookiecutter receives a repo as an argument instead of a project template directory.

Parameters:
  • repo_dir – Local directory of the cloned repo.
  • generated_project – Name of project that Cookiecutter just generated. All lowercase, no spaces or funny characters.
Returns:

True if successful, else False.

exceptions Module

cookiecutter.exceptions

All exceptions used in the Cookiecutter code base are defined here.

exception cookiecutter.exceptions.CookiecutterException[source]

Bases: exceptions.Exception

Base exception class. All Cookiecutter-specific exceptions should subclass this class.

exception cookiecutter.exceptions.MissingProjectDir[source]

Bases: cookiecutter.exceptions.CookiecutterException

Raised during cleanup when remove_repo() can’t find a generated project directory inside of a repo.

exception cookiecutter.exceptions.NonTemplatedInputDirException[source]

Bases: cookiecutter.exceptions.CookiecutterException

Raised when a project’s input dir is not templated. The name of the input directory should always contain a string that is rendered to something else, so that input_dir != output_dir.

exception cookiecutter.exceptions.UnknownTemplateDirException[source]

Bases: cookiecutter.exceptions.CookiecutterException

Raised when Cookiecutter cannot determine which directory is the project template, e.g. more than one dir appears to be a template dir.

find Module

cookiecutter.find

Functions for finding Cookiecutter templates and other components.

cookiecutter.find.find_template(repo_dir)[source]

Determines which child directory of repo_dir is the project template.

Parameters:repo_dir – Local directory of newly cloned repo.
Returns project_template:
 Relative path to project template.

generate Module

cookiecutter.generate

Functions for generating a project from a project template.

cookiecutter.generate.generate_context(config_file=u'cookiecutter.json')[source]

Generates the context for a Cookiecutter project template. Loads the JSON file as a Python object, with key being the JSON filename.

Parameters:config_file (filename) – JSON file containing project config values.
cookiecutter.generate.generate_file(infile, context, env)[source]
  1. Render the contents of infile.
  2. Render the filename of infile as the name of outfile.

3. Write the rendered infile to outfile. :param infile: Input file to generate the file from.

cookiecutter.generate.generate_files(template_dir, context=None)[source]

Renders the templates and saves them to files. :param input_dir: Project template input directory. :paramtype input_dir: directory

main Module

cookiecutter.main

Main entry point for the cookiecutter command.

The code in this module is also a good example of how to use Cookiecutter as a library rather than a script.

cookiecutter.main.cookiecutter(input_dir)[source]

API equivalent to using Cookiecutter at the command line.

Parameters:input_dir – A directory containing a project template dir, or a URL to git repo.
cookiecutter.main.main()[source]

Entry point for the package, as defined in setup.py.

cookiecutter.main.parse_cookiecutter_args(args)[source]

Parse the command-line arguments to Cookiecutter.

utils Module

cookiecutter.utils

Helper functions used throughout Cookiecutter.

cookiecutter.utils.make_sure_path_exists(path)[source]

Ensures that a directory exists. :param path: A directory path.

cookiecutter.utils.unicode_open(filename, *args, **kwargs)[source]

Opens a file as usual on Python 3, and with UTF-8 encoding on Python 2. :param filename: Name of file to open.

vcs Module

cookiecutter.vcs

Helper functions for working with version control systems.

cookiecutter.vcs.git_clone(repo)[source]

Clone a git repo to the current directory.

Parameters:repo – Git repo URL ending with .git.