Skip to content

Commit b2ce7de

Browse files
committed
feat: add sp-repo-review
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent 0609bcc commit b2ce7de

19 files changed

Lines changed: 1231 additions & 19 deletions

.pre-commit-config.yaml

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ repos:
1010
hooks:
1111
- id: black-jupyter
1212

13+
- repo: https://github.com/asottile/blacken-docs
14+
rev: 1.13.0
15+
hooks:
16+
- id: blacken-docs
17+
additional_dependencies: [black==23.1.0]
18+
19+
- repo: https://github.com/charliermarsh/ruff-pre-commit
20+
rev: "v0.0.270"
21+
hooks:
22+
- id: ruff
23+
args: ["--fix", "--show-fixes"]
24+
1325
- repo: https://github.com/pre-commit/pre-commit-hooks
14-
rev: "v4.4.0"
26+
rev: v4.4.0
1527
hooks:
1628
- id: check-added-large-files
1729
- id: check-case-conflict
@@ -21,8 +33,33 @@ repos:
2133
- id: debug-statements
2234
- id: end-of-file-fixer
2335
- id: mixed-line-ending
36+
- id: name-tests-test
37+
args: ["--pytest-test-first"]
38+
- id: requirements-txt-fixer
2439
- id: trailing-whitespace
2540

41+
- repo: https://github.com/pre-commit/pygrep-hooks
42+
rev: v1.10.0
43+
hooks:
44+
- id: rst-backticks
45+
- id: rst-directive-colons
46+
- id: rst-inline-touching-normal
47+
48+
- repo: https://github.com/pre-commit/mirrors-mypy
49+
rev: v1.3.0
50+
hooks:
51+
- id: mypy
52+
files: "(src|web|tests)"
53+
args:
54+
- click
55+
- markdown-it-py
56+
- pytest
57+
- repo-review
58+
- rich
59+
- tomli
60+
- types-PyYAML
61+
additional_dependencies:
62+
2663
- repo: https://github.com/pre-commit/mirrors-prettier
2764
rev: "v2.7.1"
2865
hooks:
@@ -31,12 +68,6 @@ repos:
3168
args: [--prose-wrap=always]
3269
exclude: ^.readthedocs.yml
3370

34-
- repo: https://github.com/asottile/blacken-docs
35-
rev: "1.13.0"
36-
hooks:
37-
- id: blacken-docs
38-
additional_dependencies: [black==23.3.0]
39-
4071
- repo: https://github.com/codespell-project/codespell
4172
rev: "v2.2.4"
4273
hooks:

noxfile.py

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import re
5+
import shutil
56
import urllib.request
67
from pathlib import Path
78

@@ -28,8 +29,7 @@ def make_cookie(session: nox.Session, backend: str) -> None:
2829

2930
package_dir = Path(f"cookie-{backend}")
3031

31-
with open("input.yml", "w") as f:
32-
f.write(JOB_FILE.format(backend=backend))
32+
Path("input.yml").write_text(JOB_FILE.format(backend=backend), encoding="utf-8")
3333

3434
session.run(
3535
"cookiecutter",
@@ -193,15 +193,15 @@ def gha_bump(session: nox.Session) -> None:
193193
old_versions = {m[1]: m[2] for m in GHA_VERS.finditer(full_txt)}
194194

195195
for repo, old_version in old_versions.items():
196-
print(f"{repo}: {old_version}")
196+
session.log(f"{repo}: {old_version}")
197197
response = urllib.request.urlopen(f"https://api.github.com/repos/{repo}/tags")
198198
tags_js = json.loads(response.read())
199199
tags = [
200200
x["name"] for x in tags_js if x["name"].count(".") == old_version.count(".")
201201
]
202202
new_version = tags[0]
203203
if new_version != old_version:
204-
print(f"Convert {repo}: {old_version} -> {new_version}")
204+
session.log(f"Convert {repo}: {old_version} -> {new_version}")
205205
for page in pages:
206206
txt = page.read_text()
207207
txt = txt.replace(
@@ -210,11 +210,57 @@ def gha_bump(session: nox.Session) -> None:
210210
page.write_text(txt)
211211

212212

213-
@nox.session(venv_backend=None)
214-
def sync(session: nox.Session) -> None:
215-
for f in Path("docs/pages/developers").glob("*.md"):
216-
if f.name == "index.md":
217-
continue
218-
url = f"https://raw.githubusercontent.com/scikit-hep/scikit-hep.github.io/main/pages/developers/{f.name}"
219-
response = urllib.request.urlopen(url)
220-
f.write_text(response.read().decode("utf-8"))
213+
# -- Repo review --
214+
215+
216+
@nox.session(reuse_venv=True)
217+
def rr_run(session: nox.Session) -> None:
218+
"""
219+
Run the program
220+
"""
221+
222+
session.install("-e", ".[cli]")
223+
session.run("python", "-m", "repo_review", *session.posargs)
224+
225+
226+
@nox.session
227+
def rr_lint(session: nox.Session) -> None:
228+
"""
229+
Run the linter.
230+
"""
231+
session.install("pre-commit")
232+
session.run("pre-commit", "run", "--all-files", *session.posargs)
233+
234+
235+
@nox.session
236+
def rr_pylint(session: nox.Session) -> None:
237+
"""
238+
Run PyLint.
239+
"""
240+
# This needs to be installed into the package environment, and is slower
241+
# than a pre-commit check
242+
session.install("-e.[cli]", "pylint")
243+
session.run("pylint", "src", *session.posargs)
244+
245+
246+
@nox.session
247+
def rr_tests(session: nox.Session) -> None:
248+
"""
249+
Run the unit and regular tests.
250+
"""
251+
session.install("-e.[test,cli]")
252+
session.run("pytest", *session.posargs)
253+
254+
255+
@nox.session(reuse_venv=True)
256+
def rr_build(session: nox.Session) -> None:
257+
"""
258+
Build an SDist and wheel.
259+
"""
260+
261+
build_p = DIR.joinpath("build")
262+
if build_p.exists():
263+
shutil.rmtree(build_p)
264+
265+
session.install("build")
266+
session.run("python", "-m", "build")

pyproject.toml

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
6+
[project]
7+
name = "sp_repo_review"
8+
authors = [
9+
{ name = "Henry Schreiner", email = "henryfs@princeton.edu" },
10+
]
11+
license = { file = "LICENSE" }
12+
description = "Review repos for compliance to the Scientific-Python development guidelines"
13+
readme = "README.md"
14+
requires-python = ">=3.10"
15+
classifiers = [
16+
"License :: OSI Approved :: BSD License",
17+
"Topic :: Scientific/Engineering",
18+
"Intended Audience :: Science/Research",
19+
"Intended Audience :: Developers",
20+
"Operating System :: OS Independent",
21+
"License :: OSI Approved :: BSD License",
22+
"Programming Language :: Python",
23+
"Programming Language :: Python :: 3",
24+
"Programming Language :: Python :: 3.10",
25+
"Programming Language :: Python :: 3.11",
26+
"Programming Language :: Python :: 3.12",
27+
"Development Status :: 4 - Beta",
28+
]
29+
dynamic = ["version"]
30+
dependencies = [
31+
"pyyaml",
32+
"repo-review",
33+
]
34+
35+
[project.optional-dependencies]
36+
cli = [
37+
"click>=8",
38+
"rich>=12.2",
39+
]
40+
test = [
41+
"pytest >=7",
42+
]
43+
dev = [
44+
"pytest >=7",
45+
]
46+
47+
[project.urls]
48+
homepage = "https://github.com/scientific-python/cookie"
49+
webpage = "https://scientific-python.github.io/cookie"
50+
51+
[project.scripts]
52+
sp-repo-review = "repo_review.__main__:main"
53+
54+
[project.entry-points."repo_review.checks"]
55+
general = "sp_repo_review.checks.general:repo_review_checks"
56+
pyproject = "sp_repo_review.checks.pyproject:repo_review_checks"
57+
precommit = "sp_repo_review.checks.precommit:repo_review_checks"
58+
ruff = "sp_repo_review.checks.ruff:repo_review_checks"
59+
mypy = "sp_repo_review.checks.mypy:repo_review_checks"
60+
github = "sp_repo_review.checks.github:repo_review_checks"
61+
62+
[project.entry-points."repo_review.fixtures"]
63+
workflows = "sp_repo_review.checks.github:workflows"
64+
dependabot = "sp_repo_review.checks.github:dependabot"
65+
precommit = "sp_repo_review.checks.precommit:precommit"
66+
67+
[project.entry-points."repo_review.families"]
68+
scikit-hep = "sp_repo_review.families:get_familes"
69+
70+
[tool.hatch]
71+
version.path = "src/sp_repo_review/__init__.py"
72+
73+
74+
[tool.pytest.ini_options]
75+
minversion = "7.0"
76+
addopts = ["-ra", "--strict-markers", "--strict-config"]
77+
xfail_strict = true
78+
log_cli_level = "INFO"
79+
filterwarnings = [
80+
'error',
81+
'ignore:(ast.Str|Attribute s|ast.NameConstant|ast.Num) is deprecated:DeprecationWarning:_pytest',
82+
]
83+
norecursedirs = ['{{cookiecutter.project_name}}']
84+
testpaths = ["tests"]
85+
86+
87+
[tool.mypy]
88+
files = ["src", "web", "tests"]
89+
python_version = "3.10"
90+
warn_unused_configs = true
91+
strict = true
92+
show_error_codes = true
93+
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
94+
warn_unreachable = true
95+
disallow_untyped_defs = false
96+
97+
[[tool.mypy.overrides]]
98+
module = "sp_repo_review.*"
99+
disallow_untyped_defs = true
100+
101+
[tool.pylint]
102+
master.py-version = "3.10"
103+
master.ignore-paths= ["src/sp_repo_review/_version.py"]
104+
reports.output-format = "colorized"
105+
similarities.ignore-imports = "yes"
106+
messages_control.disable = [
107+
"design",
108+
"fixme",
109+
"line-too-long",
110+
"wrong-import-position",
111+
"redefined-builtin",
112+
"missing-module-docstring",
113+
"missing-class-docstring",
114+
"missing-function-docstring",
115+
"invalid-name",
116+
"redefined-outer-name",
117+
"no-member", # better handled by mypy, etc.
118+
]
119+
120+
121+
[tool.ruff]
122+
select = [
123+
"E", "F", "W", # flake8
124+
"B", "B904", # flake8-bugbear
125+
"I", # isort
126+
"ARG", # flake8-unused-arguments
127+
"C4", # flake8-comprehensions
128+
"EM", # flake8-errmsg
129+
"ICN", # flake8-import-conventions
130+
"ISC", # flake8-implicit-str-concat
131+
"PGH", # pygrep-hooks
132+
"PIE", # flake8-pie
133+
"PL", # pylint
134+
"PT", # flake8-pytest-style
135+
"PTH", # flake8-use-pathlib
136+
"RET", # flake8-return
137+
"RUF", # Ruff-specific
138+
"SIM", # flake8-simplify
139+
"TID251", # flake8-tidy-imports.banned-api
140+
"T20", # flake8-print
141+
"UP", # pyupgrade
142+
"YTT", # flake8-2020
143+
]
144+
extend-ignore = [
145+
"PLR", # Design related pylint codes
146+
"E501", # Line too long
147+
"PT004", # Incorrect check, usefixtures is the correct way to do this
148+
]
149+
target-version = "py310"
150+
src = ["src"]
151+
unfixable = [
152+
"T20", # Removes print statements
153+
"F841", # Removes unused variables
154+
]
155+
exclude = []
156+
flake8-unused-arguments.ignore-variadic-names = true
157+
158+
[tool.ruff.flake8-tidy-imports.banned-api]
159+
"typing.Callable".msg = "Use collections.abc.Callable instead."
160+
"typing.Iterator".msg = "Use collections.abc.Iterator instead."
161+
"typing.Mapping".msg = "Use collections.abc.Mapping instead."
162+
"typing.Sequence".msg = "Use collections.abc.Sequence instead."
163+
"typing.Set".msg = "Use collections.abc.Set instead."
164+
"importlib.abc".msg = "Use sp_repo_review._compat.importlib.resources.abc instead."
165+
"importlib.resources.abc".msg = "Use sp_repo_review._compat.importlib.resources.abc instead."
166+
167+
[tool.ruff.per-file-ignores]
168+
"src/sp_repo_review/_compat/**.py" = ["TID251"]

src/sp_repo_review/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
Copyright (c) 2022 Henry Schreiner. All rights reserved.
3+
4+
sp-repo-review: Review repos with a set of checks defined by plugins.
5+
"""
6+
7+
8+
from __future__ import annotations
9+
10+
__version__ = "2023.06.01"
11+
12+
__all__ = ["__version__"]

src/sp_repo_review/_compat/__init__.py

Whitespace-only changes.

src/sp_repo_review/_compat/importlib/__init__.py

Whitespace-only changes.

src/sp_repo_review/_compat/importlib/resources/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
5+
if sys.version_info < (3, 11):
6+
from importlib.abc import Traversable
7+
else:
8+
from importlib.resources.abc import Traversable
9+
10+
11+
__all__ = ["Traversable"]
12+
13+
14+
def __dir__() -> list[str]:
15+
return __all__
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
5+
if sys.version_info < (3, 11):
6+
from tomli import load, loads
7+
else:
8+
from tomllib import load, loads
9+
10+
__all__ = ["load", "loads"]
11+
12+
13+
def __dir__() -> list[str]:
14+
return __all__

src/sp_repo_review/checks/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)