Skip to content

Commit

Permalink
Update packaing guide and repo-review to match spec13
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Jun 5, 2024
1 parent 8dec1ed commit 84c9489
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/_includes/pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Here is an example of a simple extras:

```toml
[project.optional-dependencies]
test = [
tests = [
"pytest >=6.0",
]
mpl = [
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/guides/packaging_classic.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ called `package`:

```ini
[options.extras_require]
test =
tests =
pytest >=6.0
mpl =
matplotlib >=2.0
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies = [
cli = [
"repo-review[cli]",
]
test = [
tests = [
"pytest >=7",
"repo-review >=0.10.6",
]
Expand Down
15 changes: 14 additions & 1 deletion src/sp_repo_review/checks/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,23 @@ class PY004(General):

@staticmethod
def check(package: Traversable) -> bool:
"Projects must have documentation in a folder called docs (disable if not applicable)"
"Projects must have documentation in a folder called doc or docs (disable if not applicable)"
return len([p for p in package.iterdir() if "doc" in p.name]) > 0


class PY004b(General):
"Documentation folder should be `docs` not `doc`"

requires = {"PY004"}

url = mk_url("packaging-simple")

@staticmethod
def check(package: Traversable) -> bool:
"Projects must have documentation in a folder called `docs` not `doc`"
return any(p.name == "docs" for p in package.iterdir())


class PY005(General):
"Has tests folder"

Expand Down
62 changes: 62 additions & 0 deletions src/sp_repo_review/checks/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,67 @@ def check(pyproject: dict[str, Any]) -> bool:
return "filterwarnings" in options


class PP310(PyProject):
"Tests target is test not test (spec13)"

requires = {"PP301"}
url = mk_url("pytest")

@staticmethod
def check(pyproject: dict[str, Any]) -> bool:
"""
Tests target should be `tests` not `test`
```toml
[project.optional-dependencies]
tests = [
'pytest',
...
]
```
"""
if "tool" not in pyproject:
return True
if "project.optional-dependencies" not in pyproject["tool"]:
return True
optional_deps = pyproject["tool"]["project.optional-dependencies"]
if "tests" in optional_deps:
return True
return "test" not in optional_deps


class PP311(PyProject):
"Tests target is `docs not` `doc` (spec13)"

requires = {"PP301"}
url = mk_url("pytest")

@staticmethod
def check(pyproject: dict[str, Any]) -> bool:
"""
docs target should be `docs` not `doc`
```toml
[project.optional-dependencies]
docs = [
'sphinx',
...
]
```
"""
if "tool" not in pyproject:
return True
if "project.optional-dependencies" not in pyproject["tool"]:
return True
optional_deps = pyproject["tool"]["project.optional-dependencies"]
if "docs" in optional_deps:
return True
return "doc" not in optional_deps

return True # it's ok to have None


def repo_review_checks() -> dict[str, PyProject]:
return {p.__name__: p() for p in PyProject.__subclasses__()}
8 changes: 4 additions & 4 deletions {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pytest = ">= 6"
pytest-cov = ">= 3"

[tool.poetry.extras]
test = ["pytest", "pytest-cov"]
tests = ["pytest", "pytest-cov"]
dev = ["pytest", "pytest-cov"]
docs = [
"furo",
Expand Down Expand Up @@ -195,7 +195,7 @@ dynamic = ["version"]
dependencies = []

[project.optional-dependencies]
test = [
tests = [
"pytest >=6",
"pytest-cov >=3",
]
Expand Down Expand Up @@ -259,7 +259,7 @@ build.hooks.vcs.version-file = "src/{{ cookiecutter.__project_slug }}/_version.p

[tool.hatch.envs.default]
features = ["test"]
scripts.test = "pytest {args}"
scripts.tests = "pytest {args}"


{%- elif cookiecutter.backend == "pdm" %}
Expand All @@ -281,7 +281,7 @@ path = "src/{{ cookiecutter.__project_slug }}/__init__.py"
{%- endif %}

[tool.pdm.dev-dependencies]
devtest = ["pytest", "pytest-cov"]
devtests = ["pytest", "pytest-cov"]

{%- endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ docs =
sphinx>=7.0
sphinx-autodoc-typehints
sphinx-copybutton
test =
tests =
pytest>=6
pytest-cov>=3

0 comments on commit 84c9489

Please sign in to comment.