From 31a07035b4a00e85438a70ef49f96e0c6ac5aa72 Mon Sep 17 00:00:00 2001 From: w3lld1 <42353747+w3lld1@users.noreply.github.com> Date: Fri, 10 Jul 2026 14:01:31 +0000 Subject: [PATCH] feat: check for a gitignore file --- README.md | 1 + docs/guides/packaging_simple.md | 4 ++-- src/sp_repo_review/checks/general.py | 11 +++++++++++ tests/test_general.py | 20 ++++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 854cf543..aabd8488 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,7 @@ for family, grp in itertools.groupby(collected.checks.items(), key=lambda x: x[1 - [`PY005`](https://learn.scientific-python.org/development/guides/packaging-simple#PY005): Has tests folder - [`PY006`](https://learn.scientific-python.org/development/guides/style#PY006): Has pre-commit config - [`PY007`](https://learn.scientific-python.org/development/guides/tasks#PY007): Supports an easy task runner (nox, tox, pixi, etc.) +- [`PY008`](https://learn.scientific-python.org/development/guides/packaging-simple#PY008): Has a .gitignore file ### PyProject diff --git a/docs/guides/packaging_simple.md b/docs/guides/packaging_simple.md index 87439072..74671840 100644 --- a/docs/guides/packaging_simple.md +++ b/docs/guides/packaging_simple.md @@ -175,8 +175,8 @@ support versioning. This is tool specific. - [Hatchling info here](https://hatch.pypa.io/latest/config/build/#file-selection). - Hatchling uses your VCS ignore file by default, so make sure it is accurate - (which is a good idea anyway). + {rr}`PY008` Hatchling uses your VCS ignore file by default, so make sure your + project has an accurate `.gitignore` file (which is a good idea anyway). - [Flit info here](https://flit.readthedocs.io/en/latest/pyproject_toml.html#sdist-section). Flit requires manual inclusion/exclusion in many cases, like using a dirty working directory. diff --git a/src/sp_repo_review/checks/general.py b/src/sp_repo_review/checks/general.py index 7a23696c..c8ecdcc1 100644 --- a/src/sp_repo_review/checks/general.py +++ b/src/sp_repo_review/checks/general.py @@ -159,5 +159,16 @@ def check(root: Traversable, pyproject: dict[str, Any]) -> bool: return False +class PY008(General): + "Has a .gitignore file" + + url = mk_url("packaging-simple") + + @staticmethod + def check(root: Traversable) -> bool: + "Projects must have a `.gitignore` file" + return root.joinpath(".gitignore").is_file() + + def repo_review_checks() -> dict[str, General]: return {p.__name__: p() for p in General.__subclasses__()} diff --git a/tests/test_general.py b/tests/test_general.py index 634c0f4f..8de75dcb 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -171,3 +171,23 @@ def test_py007_missing(tmp_path: Path): simple = tmp_path / "simple" simple.mkdir() assert not compute_check("PY007", root=simple, pyproject={}).result + + +def test_py008(tmp_path: Path): + simple = tmp_path / "simple" + simple.mkdir() + simple.joinpath(".gitignore").touch() + assert compute_check("PY008", root=simple).result + + +def test_py008_not_file(tmp_path: Path): + simple = tmp_path / "simple" + simple.mkdir() + simple.joinpath(".gitignore").mkdir() + assert not compute_check("PY008", root=simple).result + + +def test_py008_missing(tmp_path: Path): + simple = tmp_path / "simple" + simple.mkdir() + assert not compute_check("PY008", root=simple).result