How to use the cookiecutter.exceptions.CookiecutterException function in cookiecutter

To help you get started, we’ve selected a few cookiecutter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tencentyun / scfcli / tcfcli / cmds / init / cli.py View on Github external
params = {
            "template": location if location else Init._runtime_path(runtime),
            "output_dir": output_dir,
            "no_input": no_input,
        }
        Operation("Template: %s" % params["template"]).process()
        Operation("Output-Dir: %s" % params["output_dir"]).process()
        if name is not None:
            params["no_input"] = True
            params['extra_context'] = {'project_name': name, 'runtime': runtime, 'namespace': namespace, 'type': type}
            Operation("Project-Name: %s" % params['extra_context']["project_name"]).process()
            Operation("Type: %s" % params['extra_context']["type"]).process()
            Operation("Runtime: %s" % params['extra_context']["runtime"]).process()
        try:
            cookiecutter(**params)
        except exceptions.CookiecutterException as e:
            Operation(e, err_msg=traceback.format_exc(), level="ERROR").no_output()
            # raise click.Abort()
            raise InitException(e)
        if runtime in infor.SERVICE_RUNTIME:
            Operation("[*] Project initing,please wait.....", fg="green").echo()
            zipfile_path = os.path.join(os.path.abspath(output_dir), name, 'node_modules.zip')
            zipobj = zipfile.ZipFile(zipfile_path, mode="r")
            zipobj.extractall(os.path.join(os.path.abspath(output_dir), name))
            zipobj.close()
            os.remove(zipfile_path)
        Operation("[*] Project initialization is complete", fg="green").echo()
        Operation(
            "You could 'cd %s', and start this project." % (params['extra_context']["project_name"])).information()
github awslabs / aws-sam-cli / samcli / local / init / __init__.py View on Github external
LOG.debug("%s", params)

    try:
        LOG.debug("Baking a new template with cookiecutter with all parameters")
        cookiecutter(**params)
    except RepositoryNotFound as e:
        # cookiecutter.json is not found in the template. Let's just clone it directly without using cookiecutter
        # and call it done.
        LOG.debug(
            "Unable to find cookiecutter.json in the project. Downloading it directly without treating "
            "it as a cookiecutter template"
        )
        project_output_dir = str(Path(output_dir, name)) if name else output_dir
        generate_non_cookiecutter_project(location=params["template"], output_dir=project_output_dir)

    except CookiecutterException as e:
        raise GenerateProjectFailedError(project=name, provider_error=e)
github cookiecutter / cookiecutter / cookiecutter / exceptions.py View on Github external
Raised during cleanup when remove_repo() can't find a generated project
    directory inside of a repo.
    """
    # unused locally


class ConfigDoesNotExistException(CookiecutterException):
    """
    Exception for missing config file.

    Raised when get_config() is passed a path to a config file, but no file
    is found at that path.
    """


class InvalidConfiguration(CookiecutterException):
    """
    Exception for invalid configuration file.

    Raised if the global configuration file is not valid YAML or is
    badly constructed.
    """


class UnknownRepoType(CookiecutterException):
    """
    Exception for unknown repo types.

    Raised if a repo's type cannot be determined.
    """
github cookiecutter / cookiecutter / cookiecutter / exceptions.py View on Github external
The name of the input directory should always contain a string that is
    rendered to something else, so that input_dir != output_dir.
    """


class UnknownTemplateDirException(CookiecutterException):
    """
    Exception for ambiguous project template directory.

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


class MissingProjectDir(CookiecutterException):
    """
    Exception for missing generated project directory.

    Raised during cleanup when remove_repo() can't find a generated project
    directory inside of a repo.
    """
    # unused locally


class ConfigDoesNotExistException(CookiecutterException):
    """
    Exception for missing config file.

    Raised when get_config() is passed a path to a config file, but no file
    is found at that path.
    """
github tencentyun / tcfcli / tcfcli / cmds / init / cli.py View on Github external
params = {
            "template": location if location else Init._runtime_path(runtime),
            "output_dir": output_dir,
            "no_input": no_input,
        }
        click.secho("Template: %s" % params["template"])
        click.secho("Output-Dir: %s" % params["output_dir"])
        if not location and name is not None:
            params["no_input"] = True
            params['extra_context'] = {'project_name': name, 'runtime': runtime, 'namespace': namespace}
            click.secho("Project-Name: %s" % params['extra_context']["project_name"])
            click.secho("Runtime: %s" % params['extra_context']["runtime"])

        try:
            cookiecutter(**params)
        except exceptions.CookiecutterException as e:
            click.secho(str(e), fg="red")
            raise click.Abort()
        click.secho("[*] Project initialization is complete", fg="green")
github cookiecutter / cookiecutter / cookiecutter / exceptions.py View on Github external
Exception for existing output directory.

    Raised when the output directory of the project exists already.
    """


class InvalidModeException(CookiecutterException):
    """
    Exception for incompatible modes.

    Raised when cookiecutter is called with both `no_input==True` and
    `replay==True` at the same time.
    """


class FailedHookException(CookiecutterException):
    """
    Exception for hook failures.

    Raised when a hook script fails.
    """


class UndefinedVariableInTemplate(CookiecutterException):
    """
    Exception for out-of-scope variables.

    Raised when a template uses a variable which is not defined in the
    context.
    """

    def __init__(self, message, error, context):
github cookiecutter / cookiecutter / cookiecutter / exceptions.py View on Github external
template, e.g. more than one dir appears to be a template dir.
    """
    # unused locally


class MissingProjectDir(CookiecutterException):
    """
    Exception for missing generated project directory.

    Raised during cleanup when remove_repo() can't find a generated project
    directory inside of a repo.
    """
    # unused locally


class ConfigDoesNotExistException(CookiecutterException):
    """
    Exception for missing config file.

    Raised when get_config() is passed a path to a config file, but no file
    is found at that path.
    """


class InvalidConfiguration(CookiecutterException):
    """
    Exception for invalid configuration file.

    Raised if the global configuration file is not valid YAML or is
    badly constructed.
    """
github cookiecutter / cookiecutter / cookiecutter / exceptions.py View on Github external
Exception for invalid configuration file.

    Raised if the global configuration file is not valid YAML or is
    badly constructed.
    """


class UnknownRepoType(CookiecutterException):
    """
    Exception for unknown repo types.

    Raised if a repo's type cannot be determined.
    """


class VCSNotInstalled(CookiecutterException):
    """
    Exception when version control is unavailable.

    Raised if the version control system (git or hg) is not installed.
    """


class ContextDecodingException(CookiecutterException):
    """
    Exception for failed JSON decoding.

    Raised when a project's JSON context file can not be decoded.
    """


class OutputDirExistsException(CookiecutterException):
github cookiecutter / cookiecutter / cookiecutter / exceptions.py View on Github external
"""
    Exception when version control is unavailable.

    Raised if the version control system (git or hg) is not installed.
    """


class ContextDecodingException(CookiecutterException):
    """
    Exception for failed JSON decoding.

    Raised when a project's JSON context file can not be decoded.
    """


class OutputDirExistsException(CookiecutterException):
    """
    Exception for existing output directory.

    Raised when the output directory of the project exists already.
    """


class InvalidModeException(CookiecutterException):
    """
    Exception for incompatible modes.

    Raised when cookiecutter is called with both `no_input==True` and
    `replay==True` at the same time.
    """
github cookiecutter / cookiecutter / cookiecutter / exceptions.py View on Github external
return (
            "{self.message}. "
            "Error message: {self.error.message}. "
            "Context: {self.context}"
        ).format(**locals())


class UnknownExtension(CookiecutterException):
    """
    Exception for un-importable extention.

    Raised when an environment is unable to import a required extension.
    """


class RepositoryNotFound(CookiecutterException):
    """
    Exception for missing repo.

    Raised when the specified cookiecutter repository doesn't exist.
    """


class RepositoryCloneFailed(CookiecutterException):
    """
    Exception for un-cloneable repo.

    Raised when a cookiecutter template can't be cloned.
    """


class InvalidZipRepository(CookiecutterException):