Skip to content

Commit 551c671

Browse files
authored
refactor: use backend instead of project_type (#171)
1 parent 15ab696 commit 551c671

10 files changed

Lines changed: 45 additions & 44 deletions

File tree

.github/workflows/reusable-cookie.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
strategy:
5656
fail-fast: false
5757
matrix:
58-
python-version: ["3.7", "3.11", "3.12-dev"]
58+
python-version: ["3.7", "3.12"]
5959
runs-on: [ubuntu-latest, macos-latest, windows-latest]
6060

6161
include:
@@ -68,6 +68,7 @@ jobs:
6868
- uses: actions/setup-python@v4
6969
with:
7070
python-version: ${{ matrix.python-version }}
71+
allow-prereleases: true
7172

7273
- name: Install nox
7374
run: pip install nox

cookiecutter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"org": "org",
44
"url": "https://github.com/{{ cookiecutter.org }}/{{ cookiecutter.project_name }}",
55
"full_name": "My Name",
6-
"project_type": [
6+
"backend": [
77
"hatch",
88
"setuptools",
99
"setuptools621",

hooks/post_gen_project.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from pathlib import Path
22

33
project_name = "{{ cookiecutter.project_name }}"
4-
project_type = "{{ cookiecutter.project_type }}"
5-
project_types = {
4+
backend = "{{ cookiecutter.backend }}"
5+
backends = {
66
"setuptools",
77
"pybind11",
88
"skbuild",
@@ -16,25 +16,25 @@
1616
"hatch",
1717
"setuptools621",
1818
}
19-
other_project_types = project_types - {project_type}
19+
other_backends = backends - {backend}
2020

2121
files = (p for p in Path(".").rglob("*") if p.is_file() and "-" in p.stem)
2222

2323
for f in files:
2424
base, current = f.stem.rsplit("-", 1)
2525
currents = set(current.split(","))
26-
if project_type in currents:
26+
if backend in currents:
2727
# with_stem requires python 3.9
2828
f.replace(f.with_name(f"{base}{f.suffix}"))
29-
elif currents & other_project_types:
29+
elif currents & other_backends:
3030
f.unlink()
3131

3232
files = (p for p in Path(".").rglob("*") if p.is_file() and "^" in p.stem)
3333

3434
for f in files:
3535
base, current = f.stem.rsplit("^", 1)
3636
currents = set(current.split(","))
37-
if project_type in currents:
37+
if backend in currents:
3838
f.unlink()
3939
else:
4040
# with_stem requires python 3.9

noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
DIR = Path(__file__).parent.resolve()
2121
with DIR.joinpath("cookiecutter.json").open() as f:
22-
BACKENDS = json.load(f)["project_type"]
22+
BACKENDS = json.load(f)["backend"]
2323

2424
JOB_FILE = """\
2525
default_context:
2626
project_name: cookie-{backend}
27-
project_type: {backend}
27+
backend: {backend}
2828
"""
2929

3030
nox.options.sessions = ["lint", "tests", "native"]

{{cookiecutter.project_name}}/.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ environment for each run.
3030

3131
You can set up a development environment by running:
3232

33-
{% if cookiecutter.project_type == "poetry" -%}
33+
{% if cookiecutter.backend == "poetry" -%}
3434

3535
```bash
3636
poetry install

{{cookiecutter.project_name}}/.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{%- set compiled = cookiecutter.project_type in ["pybind11", "maturin", "skbuild", "mesonpy"] -%}
1+
{%- set compiled = cookiecutter.backend in ["pybind11", "maturin", "skbuild", "mesonpy"] -%}
22
name: CI
33

44
on:
@@ -64,7 +64,7 @@ jobs:
6464
with:
6565
python-version: {% raw %}${{ matrix.python-version }}{% endraw %}
6666

67-
{%- if cookiecutter.project_type == "mesonpy" %}
67+
{%- if cookiecutter.backend == "mesonpy" %}
6868
- name: Activate MSVC for Meson
6969
if: runner.os == 'Windows'
7070
uses: ilammy/msvc-dev-cmd@v1
@@ -100,7 +100,7 @@ jobs:
100100
with:
101101
path: dist
102102

103-
{%- if cookiecutter.project_type != "trampolim" %}
103+
{%- if cookiecutter.backend != "trampolim" %}
104104

105105
- name: Check products
106106
run: pipx run twine check dist/*
@@ -128,7 +128,7 @@ jobs:
128128
# Remember to tell (test-)pypi about this repo before publishing
129129
# Remove this line to publish to PyPI
130130
repository-url: https://test.pypi.org/legacy/
131-
{%- if cookiecutter.project_type == "trampolim" %}
131+
{%- if cookiecutter.backend == "trampolim" %}
132132
# Check not supported currently by twine + trampolim
133133
verify-metadata: false
134134
{%- endif %}

{{cookiecutter.project_name}}/.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ repos:
5050
- id: ruff
5151
args: ["--fix", "--show-fixes"]
5252

53-
{%- if cookiecutter.project_type == "setuptools" or cookiecutter.project_type == "pybind11" %}
53+
{%- if cookiecutter.backend == "setuptools" or cookiecutter.backend == "pybind11" %}
5454

5555
- repo: https://github.com/asottile/setup-cfg-fmt
5656
rev: "v2.2.0"
@@ -60,7 +60,7 @@ repos:
6060

6161
{%- endif %}
6262

63-
{%- if cookiecutter.project_type in ["pybind11", "skbuild", "mesonpy"] %}
63+
{%- if cookiecutter.backend in ["pybind11", "skbuild", "mesonpy"] %}
6464

6565
- repo: https://github.com/pre-commit/mirrors-clang-format
6666
rev: "v16.0.2"
@@ -97,7 +97,7 @@ repos:
9797
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
9898
exclude: .pre-commit-config.yaml
9999

100-
{%- if cookiecutter.project_type in ["setuptools", "pybind11"] %}
100+
{%- if cookiecutter.backend in ["setuptools", "pybind11"] %}
101101

102102
- repo: https://github.com/mgedmin/check-manifest
103103
rev: "0.49"
@@ -106,7 +106,7 @@ repos:
106106
stages: [manual]
107107
{%- endif %}
108108

109-
{%- if cookiecutter.project_type == "skbuild" %}
109+
{%- if cookiecutter.backend == "skbuild" %}
110110

111111
- repo: https://github.com/cheshirekow/cmake-format-precommit
112112
rev: "v0.6.13"

{{cookiecutter.project_name}}/noxfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from __future__ import annotations
22

33
import argparse
4-
{%- if cookiecutter.project_type != "pybind11" %}
4+
{%- if cookiecutter.backend != "pybind11" %}
55
import shutil
66
from pathlib import Path
77
{%- endif %}
88

99
import nox
1010

11-
{% if cookiecutter.project_type != "pybind11" -%}
11+
{% if cookiecutter.backend != "pybind11" -%}
1212
DIR = Path(__file__).parent.resolve()
1313

1414
{% endif -%}
@@ -83,7 +83,7 @@ def build_api_docs(session: nox.Session) -> None:
8383
)
8484

8585

86-
{%- if cookiecutter.project_type != "pybind11" %}
86+
{%- if cookiecutter.backend != "pybind11" %}
8787

8888

8989
@nox.session

{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
[build-system]
2-
{%- if cookiecutter.project_type == "trampolim" %}
2+
{%- if cookiecutter.backend == "trampolim" %}
33
requires = ["trampolim>=0.1.0"]
44
build-backend = "trampolim"
5-
{%- elif cookiecutter.project_type == "whey" %}
5+
{%- elif cookiecutter.backend == "whey" %}
66
requires = ["whey>=0.0.17"]
77
build-backend = "whey"
8-
{%- elif cookiecutter.project_type == "pdm" %}
8+
{%- elif cookiecutter.backend == "pdm" %}
99
requires = ["pdm-backend"]
1010
build-backend = "pdm.backend"
11-
{%- elif cookiecutter.project_type == "maturin" %}
11+
{%- elif cookiecutter.backend == "maturin" %}
1212
requires = ["maturin>=0.12,<0.15"]
1313
build-backend = "maturin"
14-
{%- elif cookiecutter.project_type == "hatch" %}
14+
{%- elif cookiecutter.backend == "hatch" %}
1515
requires = ["hatchling"]
1616
build-backend = "hatchling.build"
17-
{%- elif cookiecutter.project_type == "setuptools621" %}
17+
{%- elif cookiecutter.backend == "setuptools621" %}
1818
requires = ["setuptools>=61.0"]
1919
build-backend = "setuptools.build_meta"
20-
{%- elif cookiecutter.project_type == "flit" %}
20+
{%- elif cookiecutter.backend == "flit" %}
2121
requires = ["flit_core >=3.4"]
2222
build-backend = "flit_core.buildapi"
23-
{%- elif cookiecutter.project_type == "setuptools" %}
23+
{%- elif cookiecutter.backend == "setuptools" %}
2424
requires = ["setuptools>=42", "setuptools_scm[toml]>=3.4"]
2525
build-backend = "setuptools.build_meta"
26-
{%- elif cookiecutter.project_type == "pybind11" %}
26+
{%- elif cookiecutter.backend == "pybind11" %}
2727
requires = ["setuptools>=42", "setuptools_scm[toml]>=3.4", "pybind11"]
2828
build-backend = "setuptools.build_meta"
29-
{%- elif cookiecutter.project_type == "skbuild" %}
29+
{%- elif cookiecutter.backend == "skbuild" %}
3030
requires = ["pybind11", "scikit-build-core"]
3131
build-backend = "scikit_build_core.build"
32-
{%- elif cookiecutter.project_type == "mesonpy" %}
32+
{%- elif cookiecutter.backend == "mesonpy" %}
3333
requires = ["pybind11", "meson-python"]
3434
build-backend = "mesonpy"
35-
{%- elif cookiecutter.project_type == "poetry" %}
35+
{%- elif cookiecutter.backend == "poetry" %}
3636
requires = ["poetry_core>=1.0.0"]
3737
build-backend = "poetry.core.masonry.api"
3838
{%- endif %}
3939

40-
{%- if cookiecutter.project_type in ["setuptools", "pybind11"] %}
40+
{%- if cookiecutter.backend in ["setuptools", "pybind11"] %}
4141

4242

4343
[tool.setuptools_scm]
@@ -54,7 +54,7 @@ ignore = [
5454
"noxfile.py",
5555
]
5656

57-
{%- elif cookiecutter.project_type == "poetry" %}
57+
{%- elif cookiecutter.backend == "poetry" %}
5858

5959

6060
[tool.poetry]
@@ -120,7 +120,7 @@ docs = [
120120

121121
[project]
122122
name = "{{ cookiecutter.project_name }}"
123-
{%- if cookiecutter.project_type not in ["trampolim", "flit", "hatch"] %}
123+
{%- if cookiecutter.backend not in ["trampolim", "flit", "hatch"] %}
124124
version = "0.1.0"
125125
{%- endif %}
126126
authors = [
@@ -158,7 +158,7 @@ classifiers = [
158158
"Topic :: Scientific/Engineering",
159159
"Typing :: Typed",
160160
]
161-
{%- if cookiecutter.project_type in ["trampolim", "flit", "hatch"] %}
161+
{%- if cookiecutter.backend in ["trampolim", "flit", "hatch"] %}
162162
dynamic = ["version"]
163163
{%- endif %}
164164
dependencies = [
@@ -190,24 +190,24 @@ Changelog = "{{ cookiecutter.url }}/releases"
190190
{%- endif %}
191191

192192

193-
{%- if cookiecutter.project_type == "skbuild" %}
193+
{%- if cookiecutter.backend == "skbuild" %}
194194
[tool.scikit-build]
195195
minimum-version = "0.2"
196196
build-dir = "build/{cache_tag}"
197-
{%- elif cookiecutter.project_type == "whey" %}
197+
{%- elif cookiecutter.backend == "whey" %}
198198
[tool.whey]
199199
source-dir = "src"
200-
{%- elif cookiecutter.project_type == "trampolim" %}
200+
{%- elif cookiecutter.backend == "trampolim" %}
201201
[tool.trampolim]
202202
module-location = "src"
203-
{%- elif cookiecutter.project_type == "hatch" %}
203+
{%- elif cookiecutter.backend == "hatch" %}
204204
[tool.hatch]
205205
version.path = "src/{{ cookiecutter.__project_slug }}/__init__.py"
206206
envs.default.dependencies = [
207207
"pytest",
208208
"pytest-cov",
209209
]
210-
{%- elif cookiecutter.project_type == "pdm" %}
210+
{%- elif cookiecutter.backend == "pdm" %}
211211
[tool.pdm.dev-dependencies]
212212
devtest = ["pytest", "pytest-cov"]
213213
{%- endif %}

{{cookiecutter.project_name}}/src/{{cookiecutter.__project_slug}}/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from __future__ import annotations
99

10-
{% if cookiecutter.project_type == "setuptools" or cookiecutter.project_type == "pybind11" -%}
10+
{% if cookiecutter.backend == "setuptools" or cookiecutter.backend == "pybind11" -%}
1111
from ._version import version as __version__
1212
{%- else -%}
1313
__version__ = "0.1.0"

0 commit comments

Comments
 (0)