Skip to content

Commit

Permalink
docs: mention support for cruft
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Jun 29, 2023
1 parent fd07d70 commit b9c811a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 26 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/reusable-cookie.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ jobs:
- name: Test meson-python
run: nox -s 'tests(mesonpy)'

- name: Compare template generation
run: nox -s compare
- name: Compare copier template generation
run: nox -s compare_copier

- name: Compare cruft template generation
run: nox -s compare_cruft

nox:
name: Check included Noxfile
Expand Down
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ templates for Python packages?
clearly documented and every tool described, and everything is kept in sync.
- Twelve different backends to choose from for building packages.
- Template generation tested in GitHub Actions using nox.
- Supports generation with both [copier][] and [cookiecutter][].
- Supports generation with [copier][], [cookiecutter][], and [cruft][].
- Includes several compiled backends using [pybind11][], with wheels produced
for all platforms using [cibuildwheel][].
- Provides [`sp-repo-review`][pypi-link] to evaluate existing repos against the
Expand Down Expand Up @@ -98,12 +98,25 @@ below, and skip installation). Then run:
cookiecutter gh:scientific-python/cookie
```

#### To use (classic cruft version)

You can also use [cruft][], which adds the ability update to cookiecutter
projects. Install with `pipx install cruft` (or prepend `pipx run` to the
command below, and skip installation). Then run:

```bash
cruft create gh:scientific-python/cookie
```

#### Post generation

Check the key setup files, `pyproject.toml`, and possibly `setup.cfg` and
`setup.py` (pybind11 example). Update README.md. Also update and add docs to
`setup.py` (pybind11 example). Update `README.md`. Also update and add docs to
`docs/`.

There are a few example dependencies and a minimum Python version of 3.8, feel
free to change it to whatever you actually need/want.
free to change it to whatever you actually need/want. There is also a basic
backports structure with a small typing example.

#### Contained components:

Expand Down Expand Up @@ -169,7 +182,8 @@ system fairly easily if you don't want to use GHA. It also forces the use of
Poetry (instead of having a backend selection), and doesn't support compiled
projects. It currently dumps all development dependencies into a shared
environment, causing long solve times and high chance of conflicts. It also does
not use pre-commit properly. It also has quite a bit of custom code.
not use pre-commit the way it was intended to be used. It also has quite a bit
of custom code.

#### History

Expand All @@ -184,6 +198,7 @@ A lot of the guide, cookiecutter, and repo-review started out as part of
[cibuildwheel]: https://cibuildwheel.readthedocs.io
[cookiecutter]: https://cookiecutter.readthedocs.io
[copier]: https://copier.readthedocs.io
[cruft]: https://cruft.github.io/cruft
[flit]: https://flit.readthedocs.io/en/latest/
[github-discussions-badge]: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github
[github-discussions-link]: https://github.com/scientific-python/cookie/discussions
Expand Down
86 changes: 66 additions & 20 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ def make_cookie(session: nox.Session, backend: str) -> None:
return package_dir


def make_cruft(session: nox.Session, backend: str) -> None:
package_dir = Path(f"cruft-{backend}")
if package_dir.exists():
shutil.rmtree(package_dir)

tmp_dir = Path("tmp_loc")
tmp_dir.mkdir()

session.cd(tmp_dir)
Path("input.yml").write_text(
JOB_FILE.format(backend=backend, pkg=package_dir), encoding="utf-8"
)
session.run(
"cruft",
"create",
"--no-input",
f"{DIR}",
"--config-file=input.yml",
)
session.cd("..")
tmp_dir.joinpath(f"cookie-{backend}").rename(package_dir)
shutil.rmtree(tmp_dir)

init_git(session, package_dir)

return package_dir


def init_git(session: nox.Session, package_dir: Path) -> None:
session.run("git", "-C", f"{package_dir}", "init", "-q", external=True)
session.run("git", "-C", f"{package_dir}", "add", ".", external=True)
Expand All @@ -96,10 +124,11 @@ def init_git(session: nox.Session, package_dir: Path) -> None:
session.run("git", "-C", f"{package_dir}", "tag", "v0.1.0", external=True)


IGNORE_FILES = {"__pycache__", ".git", ".copier-answers.yml", ".cruft.json"}


def valid_path(path: Path):
return path.is_file() and not {"__pycache__", ".git", ".copier-answers.yml"} & set(
path.parts
)
return path.is_file() and not IGNORE_FILES & set(path.parts)


def diff_files(p1: Path, p2: Path) -> bool:
Expand Down Expand Up @@ -169,23 +198,6 @@ def tests(session, backend):
session.run("python", "-m", "pytest", "-ra")


@nox.session()
def compare(session):
session.install("cookiecutter", "copier", "copier-templates-extensions")

tmp_dir = session.create_tmp()
session.cd(tmp_dir)

for backend in BACKENDS:
cookie = make_cookie(session, backend)
copier = make_copier(session, backend)

if diff_files(cookie, copier):
session.log(f"{backend} passed")
else:
session.error(f"{backend} files are not the same!")


@nox.session()
@nox.parametrize("backend", ("poetry", "pdm", "hatch"), ids=("poetry", "pdm", "hatch"))
def native(session, backend):
Expand Down Expand Up @@ -245,6 +257,40 @@ def nox_session(session, backend):
session.run("nox")


@nox.session()
def compare_copier(session):
session.install("cookiecutter", "copier", "copier-templates-extensions")

tmp_dir = session.create_tmp()
session.cd(tmp_dir)

for backend in BACKENDS:
cookie = make_cookie(session, backend)
copier = make_copier(session, backend)

if diff_files(cookie, copier):
session.log(f"{backend} passed")
else:
session.error(f"{backend} files are not the same!")


@nox.session()
def compare_cruft(session):
session.install("cookiecutter", "cruft")

tmp_dir = session.create_tmp()
session.cd(tmp_dir)

for backend in BACKENDS:
cookie = make_cookie(session, backend)
copier = make_cruft(session, backend)

if diff_files(cookie, copier):
session.log(f"{backend} passed")
else:
session.error(f"{backend} files are not the same!")


PC_VERS = re.compile(
r"""\
^- repo: (.*?)
Expand Down

0 comments on commit b9c811a

Please sign in to comment.