Skip to content

Commit 07047e1

Browse files
committed
Migrate template from Cookiecutter to Copier
1 parent b4f7606 commit 07047e1

24 files changed

+383
-88
lines changed

README.md

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# 🍪 Python Cookie Cutter
1+
# 🍪 Copier Python Template
22

3-
[Cookiecutter](https://github.com/cookiecutter/cookiecutter) template for a Python package.
3+
A [Copier](https://copier.readthedocs.io/en/stable/) template for a Python package.
44

55
## Features
66
- Testing with [pytest](https://docs.pytest.org/en/latest/)
@@ -11,31 +11,20 @@
1111
- Continuous Integration with [GitHub Actions](https://github.com/features/actions)
1212
- Architecture decisions documented in an [Architecture Decision Record](https://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions)
1313

14-
## Quickstart
1514

16-
Install the latest Cookiecutter if you haven't installed it yet (this requires Cookiecutter 1.4.0 or higher):
15+
## Getting started 🚀
16+
### Prerequisites
17+
To use this template, first [install `copier`](https://github.com/copier-org/copier?tab=readme-ov-file#installation):
18+
```
19+
pip install pipx
20+
pipx install copier
21+
```
1722

18-
pip install -U cookiecutter
23+
### Usage
24+
Once `copier` is installed, generate a new python project with:
1925

20-
Generate a Python package project:
2126

22-
cookiecutter gh:Debakel/python-cookiecutter
23-
24-
Or, with `pipx` installed:
25-
26-
pipx run cookiecutter gh:Debakel/python-cookiecutter
27-
28-
**Then:**
29-
30-
# Enter project directory
31-
cd <repo_name>
32-
33-
# Initialise git repo
34-
git init
35-
36-
# Install dependencies
37-
pipenv install --dev
38-
39-
# Setup pre-commit and pre-push hooks
40-
pipenv run pre-commit install
27+
```
28+
copier copy https://github.com/Debakel/python-template.git --trust
29+
```
4130

cookiecutter.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

copier.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
template_version:
2+
default: 0.1.0
3+
when: false
4+
5+
_subdirectory: template
6+
7+
_tasks:
8+
- git init
9+
- git add .
10+
- git commit -m "Initial commit"
11+
12+
13+
project_name:
14+
type: str
15+
help: "Project name"
16+
default: "Lorem Ipsum"
17+
18+
project_description:
19+
type: str
20+
help: "Project description"
21+
22+
package_name:
23+
type: str
24+
help: "Package name"
25+
default: "{{ project_name.lower().replace(' ', '_').replace('-', '_') }}"
26+
validator: >-
27+
{% if not (package_name | regex_search('^[a-z][a-z0-9\_]+$')) %}
28+
project_name must start with a letter, followed one or more letters, digits or dashes all lowercase.
29+
{% endif %}
30+
31+
python_version:
32+
type: str
33+
help: "Python version"
34+
default: "3.12"

hooks/post_gen_project.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

hooks/pre_gen_project.py

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[run]
2-
source = {{cookiecutter.repo_name}}
3-
omit = {{cookiecutter.repo_name}}/__main__.py
2+
source = {{package_name}}
3+
omit = {{package_name}}/__main__.py
44

55
[report]
66
exclude_lines =
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
**
33

44
# ... except for dependencies and source
5-
!Pipfile
5+
!Pipfile.jinja
66
!Pipfile.lock
7-
!{{cookiecutter.repo_name}}
7+
!{{package_name}}

{{cookiecutter.repo_name}}/.github/workflows/code-quality.yml renamed to template/.github/workflows/code-quality.yml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup Python
1414
uses: actions/setup-python@v1
1515
with:
16-
python-version: '{{cookiecutter.python_version}}'
16+
python-version: '{{python_version}}'
1717

1818
- name: Install dependencies with pipenv
1919
run: |

{{cookiecutter.repo_name}}/.github/workflows/test.yml renamed to template/.github/workflows/test.yml.jinja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Setup Python
1515
uses: actions/setup-python@v1
1616
with:
17-
python-version: '{{cookiecutter.python_version}} '
17+
python-version: '{{python_version}} '
1818

1919
- name: Install dependencies with pipenv
2020
run: |
@@ -29,8 +29,8 @@ jobs:
2929
- uses: actions/checkout@v2
3030

3131
- name: Build docker image
32-
run: docker build . -t {{cookiecutter.repo_name}}:test
32+
run: docker build . -t {{package_name}}:test
3333

3434
- name: Smoke test docker image
3535
run: |
36-
docker run --rm {{cookiecutter.repo_name}}:test 10
36+
docker run --rm {{package_name}}:test 10

0 commit comments

Comments
 (0)