Git Product home page Git Product logo

cookiecutter / cookiecutter Goto Github PK

View Code? Open in Web Editor NEW
21.7K 21.7K 2.0K 3.13 MB

A cross-platform command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, C projects.

Home Page: https://pypi.org/project/cookiecutter/

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.79% Shell 0.11% Python 98.89% Batchfile 0.04% Jinja 0.18%
cookiecutter python

cookiecutter's Introduction

cookiecutter Logo

pypi python Build Status codecov discord docs Code Quality

Cookiecutter

Create projects swiftly from cookiecutters (project templates) with this command-line utility. Ideal for generating Python package projects and more.

Installation

Install cookiecutter using pip package manager:

# pipx is strongly recommended.
pipx install cookiecutter

# If pipx is not an option,
# you can install cookiecutter in your Python user directory.
python -m pip install --user cookiecutter

Features

  • Cross-Platform: Supports Windows, Mac, and Linux.
  • User-Friendly: No Python knowledge required.
  • Versatile: Compatible with Python 3.7 to 3.12.
  • Multi-Language Support: Use templates in any language or markup format.

For Users

Quick Start

The recommended way to use Cookiecutter as a command line utility is to run it with pipx, which can be installed with pip install pipx, but if you plan to use Cookiecutter programmatically, please run pip install cookiecutter.

Use a GitHub template

# You'll be prompted to enter values.
# Then it'll create your Python package in the current working directory,
# based on those values.
# For the sake of brevity, repos on GitHub can just use the 'gh' prefix
$ pipx run cookiecutter gh:audreyfeldroy/cookiecutter-pypackage

Use a local template

$ pipx run cookiecutter cookiecutter-pypackage/

Use it from Python

from cookiecutter.main import cookiecutter

# Create project from the cookiecutter-pypackage/ template
cookiecutter('cookiecutter-pypackage/')

# Create project from the cookiecutter-pypackage.git repo template
cookiecutter('gh:audreyfeldroy//cookiecutter-pypackage.git')

Detailed Usage

  • Generate projects from local or remote templates.
  • Customize projects with cookiecutter.json prompts.
  • Utilize pre-prompt, pre- and post-generate hooks.

Learn More

For Template Creators

  • Utilize unlimited directory nesting.
  • Employ Jinja2 for all templating needs.
  • Define template variables easily with cookiecutter.json.

Learn More

Available Templates

Discover a variety of ready-to-use templates on GitHub.

Special Templates

Community

Join the community, contribute, or seek assistance.

Support

  • Star us on GitHub.
  • Stay tuned for upcoming support options.

Feedback

We value your feedback. Share your criticisms or complaints constructively to help us improve.

Waiting for a Response?

  • Be patient and consider reaching out to the community for assistance.
  • For urgent matters, contact @audreyfeldroy for consultation or custom development.

Code of Conduct

Adhere to the PyPA Code of Conduct during all interactions in the project's ecosystem.

Acknowledgements

Created and led by Audrey Roy Greenfeld, supported by a dedicated team of maintainers and contributors.

cookiecutter's People

Contributors

audreyfeldroy avatar benjixx avatar bollwyvl avatar danieleades avatar dependabot[bot] avatar eliasdorneles avatar ericof avatar foobacca avatar freakboy3742 avatar hackebrot avatar insspb avatar jensens avatar kurtmckee avatar luzfcb avatar maiksensi avatar meahow avatar michaeljoseph avatar ozer550 avatar pfmoore avatar pre-commit-ci[bot] avatar pydanny avatar ramiroluz avatar raphigaziano avatar simobasso avatar ssbarnea avatar stevepiercy avatar suledev avatar terryjbates avatar vincentbernat avatar zhongdai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cookiecutter's Issues

Doesn't work with jinja2 2.7.1

I get an error if I have jinja2 2.7.1 installed:

$  cookiecutter cookiecutter-pypackage                                                                                                                    
Traceback (most recent call last):
  File "/Users/sloria1/Envs/cookiecutter/lib/python3.3/site-packages/distribute-0.6.34-py3.3.egg/pkg_resources.py", line 2804, in <module>
    working_set.require(__requires__)
  File "/Users/sloria1/Envs/cookiecutter/lib/python3.3/site-packages/distribute-0.6.34-py3.3.egg/pkg_resources.py", line 696, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/Users/sloria1/Envs/cookiecutter/lib/python3.3/site-packages/distribute-0.6.34-py3.3.egg/pkg_resources.py", line 598, in resolve
    raise VersionConflict(dist,req) # XXX put more info here
pkg_resources.VersionConflict: (Jinja2 2.7.1 (/Users/sloria1/Envs/cookiecutter/lib/python3.3/site-packages), Requirement.parse('jinja2==2.7'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sloria1/Envs/cookiecutter/bin/cookiecutter", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/Users/sloria1/Envs/cookiecutter/lib/python3.3/site-packages/distribute-0.6.34-py3.3.egg/pkg_resources.py", line 2808, in <module>
    parse_requirements(__requires__), Environment()
  File "/Users/sloria1/Envs/cookiecutter/lib/python3.3/site-packages/distribute-0.6.34-py3.3.egg/pkg_resources.py", line 594, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: jinja2==2.7

This is remedied if I run pip install jinja2==2.7, but would it be possible to support jinja2>=2.7?

Allow removal of unnecessary fields in cookiecutter.json

I removed "version", "year", and "release date" from cookiecutter.json since they aren't really applicable to the template I'm creating. When I run the cookiecutter script, I get the following traceback

Traceback (most recent call last):
  File "/Users/sloria1/Envs/cookiecutter-flask/bin/cookiecutter", line 8, in <module>
    load_entry_point('cookiecutter==0.6.1', 'console_scripts', 'cookiecutter')()
  File "/Users/sloria1/Envs/cookiecutter-flask/lib/python2.7/site-packages/cookiecutter/main.py", line 90, in main
    cookiecutter(args.input_dir)
  File "/Users/sloria1/Envs/cookiecutter-flask/lib/python2.7/site-packages/cookiecutter/main.py", line 49, in cookiecutter
    config_file=config_file
  File "/Users/sloria1/Envs/cookiecutter-flask/lib/python2.7/site-packages/cookiecutter/generate.py", line 41, in generate_context
    obj = json.load(file_handle, object_pairs_hook=OrderedDict)
  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load
    **kw)
  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 351, in loads
    return cls(encoding=encoding, **kw).decode(s)
  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 381, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 8 column 1 (char 202)

When I put those properties back, the script runs fine.

It would be nice if one could remove properties and still run the script, though.

--no-input option for cookiecutter script

I want to be able to just call cookiecutter without having to enter data. Something like:

$ cookiecutter https://github.com/pydanny/cookiecutter-thing.git --no-input
$ cookiecutter https://github.com/pydanny/cookiecutter-thing.git -n

Plugin/extension system

Make it possible to implement Cookiecutter plugins like:

This issue is dependent on #29 / #48.

I wonder if there would be a way to implement the plugin system such that #55 would be possible as a plugin. Not sure.

Come up with a better way to represent the escaped {, {{, }, }}

Escaping curly braces in Jinja2 is possible, but it looks awful:

{{ "{" }}
{{ "{{" }}
{{ "}" }}
{{ "}}" }}

{{ {{ url_for('home') }} }}

{% raw %}
<p>Go <a href="{{ url_for('home') }}">Home</a></p>
{% endraw %}

What about supporting something else, since this is a common task? Some possibilities:

Option 1: Use a backslash, like \{ and \{\{

Pro: simple, intuitive.
Con: what if you really want a backslash, like if you're templating Windows paths?

Option 2: Precede brace with an unusual character, like ☃{ and ☃{☃{

Unicode snowmen look kinda like curly braces.

Pro: Avoids the con of option 1, since using this combination is rare.
Con: Hard to type, and kind of weird.

Option 3: Surround them with a character, like _{_ and _{{_

Pro: Don't have to escape every single one, making it more readable.
Con: What if you really wanted to type _{_? Is that ever a common thing to type, in any popular framework?

Jinja breaks on syntax error without reporting where the error occured

I tried to create a project from here and I got the following traceback:

cookiecutter https://github.com/thedrow/cookiecutter-pypackage.git
You've cloned cookiecutter-pypackage before. Is it okay to delete and re-clone it? [Y/n] y
Cloning into 'cookiecutter-pypackage'...
remote: Counting objects: 249, done.
remote: Compressing objects: 100% (131/131), done.
remote: Total 249 (delta 108), reused 230 (delta 96)
Receiving objects: 100% (249/249), 39.41 KiB, done.
Resolving deltas: 100% (108/108), done.
full_name (default is "Omer Katz")? 
email (default is "[email protected]")? 
github_username (default is "thedrow")? testsuite
project_name (default is "Python Boilerplate")? testsuite
repo_name (default is "boilerplate")? testsuite
project_short_description (default is "Python Boilerplate contains all the boilerplate you need to create a Python package.")? Testsuite is a set of plugins & extensions to nose2 that aims to assist you to write better tests.
release_date (default is "2013-08-25")? 
year (default is "2013")? 
version (default is "0.1.0")? 
Traceback (most recent call last):
  File "/usr/local/bin/cookiecutter", line 9, in <module>
    load_entry_point('cookiecutter==0.6.4', 'console_scripts', 'cookiecutter')()
  File "/usr/local/lib/python3.3/dist-packages/cookiecutter/main.py", line 90, in main
    cookiecutter(args.input_dir)
  File "/usr/local/lib/python3.3/dist-packages/cookiecutter/main.py", line 61, in cookiecutter
    context=context
  File "/usr/local/lib/python3.3/dist-packages/cookiecutter/generate.py", line 135, in generate_files
    generate_file(infile, context, env)
  File "/usr/local/lib/python3.3/dist-packages/cookiecutter/generate.py", line 85, in generate_file
    tmpl = env.get_template(infile_fwd_slashes)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/environment.py", line 791, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/usr/local/lib/python3.3/dist-packages/jinja2/environment.py", line 765, in _load_template
    template = self.loader.load(self, name, globals)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/loaders.py", line 125, in load
    code = environment.compile(source, name, filename)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/environment.py", line 554, in compile
    self.handle_exception(exc_info, source_hint=source)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/_compat.py", line 36, in reraise
    raise value.with_traceback(tb)
  File "./cookiecutter-pypackage/{{cookiecutter.repo_name}}/LICENSE", line 13, in <module>
    * Neither the name of {{ cookiecutter.project_name } nor the names of its contributors
  File "/usr/local/lib/python3.3/dist-packages/jinja2/environment.py", line 459, in _parse
    return Parser(self, source, name, encode_filename(filename)).parse()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 893, in parse
    result = nodes.Template(self.subparse(), lineno=1)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 867, in subparse
    add_data(self.parse_tuple(with_condexpr=True))
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 612, in parse_tuple
    args.append(parse())
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 386, in parse_expression
    return self.parse_condexpr()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 391, in parse_condexpr
    expr1 = self.parse_or()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 404, in parse_or
    left = self.parse_and()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 413, in parse_and
    left = self.parse_not()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 424, in parse_not
    return self.parse_compare()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 428, in parse_compare
    expr = self.parse_add()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 450, in parse_add
    left = self.parse_sub()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 460, in parse_sub
    left = self.parse_concat()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 470, in parse_concat
    args = [self.parse_mul()]
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 480, in parse_mul
    left = self.parse_div()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 490, in parse_div
    left = self.parse_floordiv()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 500, in parse_floordiv
    left = self.parse_mod()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 510, in parse_mod
    left = self.parse_pow()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 520, in parse_pow
    left = self.parse_unary()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 539, in parse_unary
    node = self.parse_postfix(node)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 664, in parse_postfix
    node = self.parse_subscript(node)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 692, in parse_subscript
    next(self.stream)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/lexer.py", line 349, in __next__
    self.current = next(self._iter)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/lexer.py", line 552, in wrap
    for lineno, token, value in stream:
  File "/usr/local/lib/python3.3/dist-packages/jinja2/lexer.py", line 677, in tokeniter
    filename)
jinja2.exceptions.TemplateSyntaxError: unexpected '}'

I'm using Python 3.3 on Ubuntu 13.04.

-b --branch argument

Specifying a branch of a project would be nice - that way you could have variations for a project template.

Improve calculation of Cookiecutter's reported coverage stats

  1. The coverage stats from coveralls seem way off. For example, this is a readme change that incorrectly reports "Coverage decreased (-1.49%)": #70

    Things to try:

  2. The coverage stats from make coverage are different from those reported by coveralls. They're only calculated with the current active Python version.

    Try:

Exception when installing on windows

I get the following exception when I try to install cookiecutter-flask with this on windows:

jinja2.exceptions.TemplateNotFound: cookiecutter-flask\{{cookiecutter.repo_name}}\.gitignore

I'm able to get past the prompts for the names and date and such, but immediately after that I hit this exception.

I tried the same thing on ubuntu and it works fine. Not sure if this was a cookiecutter issue or cookiecutter-flask issue.

Support better prompts

Maybe we could support an enhanced cookiecutter.json file, like:

    [
        {
            "full_name": "Audrey Roy",
            "prompt": "Your full name?"
        },
        {
            "email": "[email protected]",
            "prompt": "Your email address?"
        },
        {
            "github_username": "audreyr",
            "prompt": "Your username on github.com?"
        },
        {
            "project_name": "Python Boilerplate",
            "prompt": "Official name of your project, as used in your docs?"
        },
        {
            "repo_name": "boilerplate",
            "prompt": "Lowercase, spaceless, version of your repo name?",
            "help_text": "This should be a name that is importable as a Python package."
        },
        {
            "project_short_description": "Python Boilerplate contains all the boilerplate you need to create a Python package.",
            "prompt": "A 1-liner description of your project?"
        },
        {
            "release_date": "2013-08-11",
            "prompt": "Date that you plan to release your project?"
        },
        {
            "year": "2013",
            "prompt": "What year would you like to use in the copyright text?"
        },
        {
            "version": "0.1.0",
            "prompt": "Version number to start at?",
            "help_text": "We recommend using semantic versioning and starting at 0.1.0. See semver.org."
        }
    ]

missing ordereddict in it's dependencies.

$ cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git
Traceback (most recent call last):
File "/usr/bin/cookiecutter", line 9, in
load_entry_point('cookiecutter==0.6.1', 'console_scripts', 'cookiecutter')()
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 299, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 2229, in load_entry_point
return ep.load()
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1948, in load
entry = import(self.module_name, globals(),globals(), ['name'])
File "/usr/lib/python2.6/site-packages/cookiecutter/main.py", line 22, in
from .generate import generate_context, generate_files
File "/usr/lib/python2.6/site-packages/cookiecutter/generate.py", line 24, in
from ordereddict import OrderedDict
ImportError: No module named ordereddict

after pip install ordereddict it works.

Tutorial

This project would be really better with a simple tutorial.

Context injection from pre hook / access from post hook

It would be good to have a standard way to:

  • inject context vars from the pre script
  • access context vars from the post script

This should also be documented as a best practice so that there aren't multiple ways of doing the same thing.

Put local templates into one configurable local dir

Hi, i stumbled upon cookiecutter, liked the idea, and started playing around with it. Not sure if this is the right place to ask this, but I have a question regarding it, and figured I'd just post it here.

There's something i don't quite understand with the way it deals with local (ie on your drive) templates. Apparently, you need to run it from the directory containing your projects templates, and the created project will be generated in that same directory, using information stored in the template's json config file.

There might be a very good reason for why it works that way, but it seems quite limited to me. My idea would be to store the project templates in some directory referenced in a ~/.cookierc config file (which could define some common options such as your name, email, etc as well), and then infer the project name and path from a second line argument and generate it there.

I'm interested in why it currently works the way it does, and you're interested in the behaviour i just described, i'll gladly contribute some work on it (please disregard the current fork I did - i did it by mistake and ended up slaughtering the current code more than anything else).

Use cookiecutter.json instead of json/project.json

Realistically, project templates only need one file's worth of context data, not a whole directory.

Instead of reading every file from json/project.json, only cookiecutter.json should be read.

Then it can be referenced in templates like so:

{{ cookiecutter.github_username }}

Support for Jinja2 HTML templates (for a Flask template)

I am in the process of making a Flask cookiecutter template, but I'm running into problems when the Flask Jinja templates are added.

As an example, say I have this template:

<p>Go <a href="{{ url_for('home') }}">Home</a></p>

Then when I run cookiecutter cookiecutter-flask, I get a jinja2.exceptions.UndefinedError:

Traceback (most recent call last):
  File "/Users/sloria1/Envs/cookiecutter-flask/bin/cookiecutter", line 8, in <module>
    load_entry_point('cookiecutter==0.6.1', 'console_scripts', 'cookiecutter')()
  File "/Users/sloria1/Envs/cookiecutter-flask/lib/python2.7/site-packages/cookiecutter/main.py", line 90, in main
    cookiecutter(args.input_dir)
  File "/Users/sloria1/Envs/cookiecutter-flask/lib/python2.7/site-packages/cookiecutter/main.py", line 61, in cookiecutter
    context=context
  File "/Users/sloria1/Envs/cookiecutter-flask/lib/python2.7/site-packages/cookiecutter/generate.py", line 88, in generate_files
    rendered_file = tmpl.render(**context)
  File "/Users/sloria1/Envs/cookiecutter-flask/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/sloria1/Envs/cookiecutter-flask/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "./cookiecutter-pypackage/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/templates/home.html", line 1, in top-level template code
    <p>Go <a href="{{ url_for('home') }}">Home</a></p>
jinja2.exceptions.UndefinedError: 'url_for' is undefined

Support for a ~/.cookiecutterrc and/or /path/to/proj/.cookiecutterrc

Support for a ~/.cookiecutterrc and/or /path/to/proj/.cookiecutterrc

Inside, you'd be able to specify defaults for when a Cookiecutter template contains a particular context value.

For example, in my ~/.cookiecutterrc I might have something like:

[defaults]
full_name = Audrey Roy
email = [email protected]
github_username = audreyr

[mappings]
fullName = full_name
githubUsername = github_username
github = github_username

ini seems to be the most common format for .rc files. Would it make sense to use this, or the more flexible json or yaml? Don't know. Are there any examples of tools which use non-ini .rc files?

What would even be in a project/.cookiecutterrc? Don't know.

Additional similar projects

Considering your nice list of similar projects, here's two more you might consider adding there:

init-skeleton - which creates a new project from a skeleton, integrated directly in Brunch, HTML5 app builder

scaffolt - a simple scaffolding system

Place local directory results outside of the cookiecutter template

Currently, if I run: cookiecutter cookiecutter-dj-project

The result is placed inside of cookiecutter-dj-project.

This is hard to find.

What would be really nice is if when I run cookiecutter cookiecutter-dj-project the result would be placed at the same level as cookiecutter-dj-project, not inside.

💯

Add pre_generate and post_generate hooks

It would be nice to be able to do optional pre- and post-processing on a template. Amongst other things this would allow for generation of random hashes for secret keys and other things. Perhaps something like this:

├── cookiecutter.json
├── {{cookiecutter.repo_name}}
├── pre_generate.py (optional)
├── post_generate.py (optional)

Perhaps the pre-generate module would expect a main() callable that returns a dictionary. This dictionary could include things that inject into the cookiecutter context.

For example, this would allow code for generating customized secret keys:

import random
import hashlib

try:
    random = random.SystemRandom()
except NotImplementedError:
    import warnings
    warnings.warn('A secure pseudo-random number generator is not available '
                  'on your system. Falling back to Mersenne Twister.')    

def main():
    chars = list('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)')
    random.shuffle(chars)
    context = {"secret_key" = "".join(chars)}
    return context

if __name__ == "__main__":
    main()

I could imagine cookiecutter's documentation including a recipe page for pre- and post-generate hooks. 🐹

Put in a requirements_test.txt file

The tox.ini and .travis.yml files don't seem to be properly configured.

tox.ini includes -r{toxinidir}/requirements.txt as a dependency, but requirements.txt does not exist in source control.

ERROR:   py26: could not install deps [mock, unittest2, ordereddict, simplejson, -r/Users/sloria1/projects/python-projects/cookiecutter/requirements.txt]
ERROR:   py27: could not install deps [mock, -r/Users/sloria1/projects/python-projects/cookiecutter/requirements.txt]
ERROR:   py33: could not install deps [-r/Users/sloria1/projects/python-projects/cookiecutter/requirements.txt]
ERROR:   pypy: could not install deps [-r/Users/sloria1/projects/python-projects/cookiecutter/requirements.txt]

Deleting -r{toxinidir}/requirements.txt fixes the tox runner. This pull request includes those deletions.

Also, Travis-CI seems to be failing even though tox runs successfully. I think this may be because the testing dependencies aren't being installed, but I'm not sure.

Why was the requirements.txt file removed? FWIW, I like having it around because it makes it easy to find exactly what is needed for developing locally and makes it easy to "sync" dependencies between Travis, tox, and local testing.

cookiecutter.repo_name is hardcoded as app root

This caused some problems with cookiecutter-dj-package. Please do one of the following:

  • Document that there needs to be a top level {{cookiecutter.repo_name}} directory.
  • Remove the hard-coded behavior of cookiecutter.repo_name.

Update from template?

It would be really neat if we could have a way to update the generated project with a newer version of the template.

By having separate templates maintained by various people, myself included, there will obviously be problems both introduced and solved over time. Because of this many or, if there was a serious problem, all of the projects generated from that template may need to be "regenerated". Support for this would definitely be an enhancement I believe.

However the idea of persevering the users current setup at the same time could be a challenge. For the basic values that cookiecutter needs to generate its templates, the json could just be written into the generated project as a dotfile or something to allow simple regeneration. However if some one has edited a generated file, not to replace the templates structure, but to add say, information about the project to the readme, it should be kept somehow.

I have not dug into the implementation details of cookiecutter and its code but if no one else wants to I may make a fork and attempt this in the future and submit a pull request if i can pull it off. However I would like to hear any thoughts on fixing the already edited file issue first.

As a possible extension to this update idea, maybe it could be possible to use the updating system to change a project from one base template to another... just an interesting thought, although admittedly of likely limited use..

Thanks

Support single-file templates

This may be out of scope for you, but personally I like the ability to instantiate single files—such as scripts—without any containing directories. As far as I understand, this is currently not possible with Cookiecutter. Could be a magic option in cookiecutter.json, like "__single_file__": true.

Unicode exception on .DS_Store files

Reported by @sloria in #18:

Just heads up: The unicode error also happens when there's a hidden file called .DS_STORE in a folder on Macs. This file is a hidden file that stores custom info about folders (icon positioning, etc.).

Spent far too much time trying to locate the file that was causing a unicode error, only to find that it was that dang hidden .DS_STORE file that was put there by Mac OSX.

It would be helpful to enable cookiecutter to ignore such files when building a project (sort of like the .gitignore file).

Automatically append ".git" to supplied targets that lack it.

I keep doing this:

cookiecutter https://github.com/pydanny/cookiecutter-dj-package

Which throws this error:

Traceback (most recent call last):
  File "/Users/danielgreenfeld/.virtualenvs/cookiecutter/bin/cookiecutter", line 9, in <module>
    load_entry_point('cookiecutter==0.6.2', 'console_scripts', 'cookiecutter')()
  File "/Users/danielgreenfeld/.virtualenvs/cookiecutter/lib/python2.7/site-packages/cookiecutter/main.py", line 90, in main
    cookiecutter(args.input_dir)
  File "/Users/danielgreenfeld/.virtualenvs/cookiecutter/lib/python2.7/site-packages/cookiecutter/main.py", line 43, in cookiecutter
    project_template = find_template(input_dir)
  File "/Users/danielgreenfeld/.virtualenvs/cookiecutter/lib/python2.7/site-packages/cookiecutter/find.py", line 25, in find_template
    repo_dir_contents = os.listdir(repo_dir)
OSError: [Errno 2] No such file or directory: 'https://github.com/pydanny/cookiecutter-dj-project'

What would be nice is if when cookiecutter spotted a target that did not end with ".git" it would add that for you. 😄

MissingProjectDir The project did not get generated

While testing my new cookiecutter template, I received this error:

Traceback (most recent call last):
  File "/usr/local/bin/cookiecutter", line 8, in <module>
    load_entry_point('cookiecutter==0.6.4', 'console_scripts', 'cookiecutter')()
  File "/Library/Python/2.7/site-packages/cookiecutter/main.py", line 90, in main
    cookiecutter(args.input_dir)
  File "/Library/Python/2.7/site-packages/cookiecutter/main.py", line 68, in cookiecutter
    remove_repo(repo_dir, generated_project)
  File "/Library/Python/2.7/site-packages/cookiecutter/cleanup.py", line 47, in remove_repo
    'The project did not get generated. Please file an issue in '
cookiecutter.exceptions.MissingProjectDir: The project did not get generated. Please file an issue in Cookiecutter with as much detail as possible about what happened.

I received this error when running:

~ $» cookiecutter https://github.com/JackStouffer/cookiecutter-flask-foundation.git

This is on OSX

I am not quite sure what is causing this, but the code is here: https://github.com/JackStouffer/cookiecutter-flask-foundation

On Python3, open() needs encoding

Hi!

With Python 3, open() needs an encoding parameter. The default encoding is platform dependent. On Linux, the locale is used to get the default encoding and it is possible to just have ascii if the locale is C. So, in utils.py, the kwargs['encoding'] = "utf-8" should be moved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.