How To Create a New Project From a Cookiecutter Template
Quick Start
- Install - Docs
- Browse - Jax Software Tempaltes
- Cut Cookies!
- Tell cookiecutter which tempalte you want to use
- Answer the prompts!
Usage
Cookiecutter knows abbreviations for Github (gh), Bitbucket (bb), and GitLab (gl) projects, but you can also give it the full URL to any repository:
e.g.
- $ cookiecutter gh:audreyr/cookiecutter-pypackage
- $ cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git
- $ cookiecutter git+ssh://git@github.com/audreyr/cookiecutter-pypackage.git
- $ cookiecutter hg+ssh://hg@bitbucket.org/audreyr/cookiecutter-pypackage
cookiecutter-pypackage in the examples above is a cookiecutter template that creates the starter boilerplate for a Python package.
You can specify a branch with --checkout branch-name $ cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git --checkout develop`
Cookiecutter has the ability to organize several templates in one repository or zip file, separating them by directories. This allows using symlinks for general files.
Here’s an example repository demonstrating this feature:
https://github.com/user/repo-name.git
├── directory1-name/
| ├── {{cookiecutter.project_slug}}/
| └── cookiecutter.json
└── directory2-name/
├── {{cookiecutter.project_slug}}/
└── cookiecutter.json
you can specify a directory with --directory directory-name
cookiecutter https://github.com/user/repo-name.git --directory="directory1-name"
Grabbing a Cookiecutter Template From JAX DevOps and Reliability Bitbucket
Template for a Python poetry with typer-cli project
Poetry - Python packaging and dependency management tool
Typer - Typer is a library for building CLI applications
- Pre-requisites
- Python 3.9
-
execute the below command from your terminal and enter the prompted details
cookiecutter git@bitbucket.org:jacksonlaboratory/software-templates.git --directory="python-poetry-cli"
-
then execute
poetry installto download the dependencies and start building your cli application. -
Readily available features imparted to your project from this template:
- Folder structure and pyproject.toml file as per JAX's best practices
- Bitbucket pipeline file to test unittests after each push/pull request
- installs most commonly used dev-dependencies like pytest, pydantic, pytest-cov, requests, pydocstyle, bandit
- checks if the package name entered follows PEP-8 standards before generating the project and deletes poetry.lock file if present
How does cookiecutter work?
So what just happened? You cloned a repo and entered few details, but what did cookiecutter do?
Let’s take a look at cookiecutter-pypackage. Open https://github.com/audreyr/cookiecutter-pypackage in a new browser window.
The /{{ cookiecutter.project_slug }}/
Find the directory called {{ cookiecutter.project_slug }}. Click on it. Observe the files inside. You should see
that this directory and its contents corresponds to the project that you just generated. You can configure the project
details in the cookiecutter.json file if you want.
This happens in find.py, where the find_template() method looks for the first jinja-like( enclosed in {{}} )
directory name that starts with cookiecutter.