Returns whether or not a file is an executable.
Determine if an object is a string.
Prompt the user for a response.
Prints the given prompt (which should be a Unicode string), and returns the text entered by the user as a Unicode string.
Parameters: | prompt – A Unicode string that is presented to the user. |
---|
Given a command, mode, and a PATH string, return the path which conforms to the given mode on the PATH, or None if there is no such file. mode defaults to os.F_OK | os.X_OK. path defaults to the result of os.environ.get(“PATH”), or can be overridden with a custom search path.
Note: This function was backported from the Python 3 source code.
Global configuration handling
Retrieve the config from the specified path, returning it as a config dict.
Retrieve config from the user’s ~/.cookiecutterrc, if it exists. Otherwise, return None.
All exceptions used in the Cookiecutter code base are defined here.
Bases: cookiecutter.exceptions.CookiecutterException
Raised when get_config() is passed a path to a config file, but no file is found at that path.
Bases: cookiecutter.exceptions.CookiecutterException
Raised when a project’s JSON context file can not be decoded.
Bases: exceptions.Exception
Base exception class. All Cookiecutter-specific exceptions should subclass this class.
Bases: cookiecutter.exceptions.CookiecutterException
Raised if the global configuration file is not valid YAML or is badly contructed.
Bases: cookiecutter.exceptions.CookiecutterException
Raised during cleanup when remove_repo() can’t find a generated project directory inside of a repo.
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.
Bases: cookiecutter.exceptions.CookiecutterException
Raised if a repo’s type cannot be determined.
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.
Bases: cookiecutter.exceptions.CookiecutterException
Raised if the version control system (git or hg) is not installed.
Functions for finding Cookiecutter templates and other components.
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. |
Functions for generating a project from a project template.
Ensures that dirname is a templated directory name.
Generates the context for a Cookiecutter project template. Loads the JSON file as a Python object, with key being the JSON filename.
Parameters: |
|
---|
Render the filename of infile as the name of outfile.
Deal with infile appropriately:
- If infile is a binary file, copy it over without rendering.
- If infile is a text file, render its contents and write the rendered infile to outfile.
Precondition:
When calling generate_file(), the root template dir must be the current working directory. Using utils.work_in() is the recommended way to perform this directory change.
Parameters: |
|
---|
Renders the templates and saves them to files.
Parameters: |
|
---|
Renders the name of a directory, creates the directory, and returns its path.
Functions for discovering and executing various cookiecutter hooks.
Must be called with the project template as the current working directory. Returns a dict of all hook scripts provided. Dict’s key will be the hook/script’s name, without extension, while values will be the absolute path to the script. Missing scripts will not be included in the returned dict.
Try to find and execute a hook from the specified project directory.
Parameters: |
|
---|
Executes a script from a working directory.
Parameters: |
|
---|
Executes a script after rendering with it Jinja.
Parameters: |
|
---|
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.
API equivalent to using Cookiecutter at the command line.
Parameters: |
|
---|
Expand abbreviations in a template name.
Parameters: |
|
---|
Functions for prompting the user for project info.
Prompts the user to enter new config, using context as a source for the field names and sample values.
Parameters: | no_input – Prompt the user at command line for manual configuration? |
---|
Ask a yes/no question via read_response() and return their answer.
Parameters: |
|
---|
The “answer” return value is one of “yes” or “no”.
Adapted from http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input http://code.activestate.com/recipes/577058/
Helper functions used throughout Cookiecutter.
Error handler for shutil.rmtree() equivalent to rm -rf Usage: shutil.rmtree(path, onerror=force_delete) From stackoverflow.com/questions/1889597
Makes script_path executable
Parameters: | script_path – The file to change |
---|
Ensures that a directory exists.
Parameters: | path – A directory path. |
---|
Removes a directory and all its contents. Like rm -rf on Unix.
Parameters: | path – A directory path. |
---|
Context manager version of os.chdir. When exited, returns to the working directory prior to entering.
Helper functions for working with version control systems.
Clone a repo to the current directory.
Parameters: |
|
---|
Determines if repo_url should be treated as a URL to a git or hg repo. Repos can be identified prepeding “hg+” or “git+” to repo URL.
Parameters: | repo_url – Repo URL of unknown type. |
---|---|
Returns: | (“git”, repo_url), (“hg”, repo_url), or None. |
Check if the version control system for a repo type is installed.
Parameters: | repo_type – |
---|
Asks the user whether it’s okay to delete the previously-cloned repo. If yes, deletes it. Otherwise, Cookiecutter exits.
Parameters: |
|
---|