mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
chore: lint with ruff in CI, drop mypy baseline
The code now carries no type error and no ruff finding. CI runs mypy bare and ruff with the rule set of pyproject.toml; pr_checks.py and the contribution guide list both. The baseline and its tooling go.
This commit is contained in:
1 parent
f1e5cb3f5f
commit
8f1b88bb7e
7 files changed
+54
-73
No files matched your search
@@ -35,9 +35,8 @@ on:
|
||||
- "recipes/**"
|
||||
- "measurements/**"
|
||||
- "website/**"
|
||||
# The type check's configuration and baseline.
|
||||
# The type check's and the lint's configuration.
|
||||
- "pyproject.toml"
|
||||
- "mypy-baseline.txt"
|
||||
# Spelled out twice because the workflow parser reads no YAML anchor. A test
|
||||
# holds the two lists equal.
|
||||
push:
|
||||
@@ -67,7 +66,6 @@ on:
|
||||
- "measurements/**"
|
||||
- "website/**"
|
||||
- "pyproject.toml"
|
||||
- "mypy-baseline.txt"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
@@ -173,16 +171,21 @@ jobs:
|
||||
- name: Validate platform configs and emulator profiles
|
||||
run: python scripts/validate_schemas.py --source-only
|
||||
|
||||
# The annotations are checked against mypy-baseline.txt, the errors the
|
||||
# code carried when the check started: a new error fails, and so does
|
||||
# an entry that no longer occurs until the baseline is synced. mypy
|
||||
# reads no installed package (no_site_packages in pyproject.toml), so
|
||||
# what this job has installed does not change the result.
|
||||
# The code carries no type error, so any error fails. mypy reads no
|
||||
# installed package (no_site_packages in pyproject.toml), so what this
|
||||
# job has installed does not change the result.
|
||||
- name: Type-check the scripts and the installer
|
||||
run: |
|
||||
pip install "mypy==2.4.1" "mypy-baseline==0.7.4"
|
||||
mypy > "$RUNNER_TEMP/mypy.txt" || true
|
||||
mypy-baseline filter --no-colors < "$RUNNER_TEMP/mypy.txt"
|
||||
pip install "mypy==2.4.1"
|
||||
mypy
|
||||
|
||||
# The rule set lives in pyproject.toml: pyflakes, the B rules,
|
||||
# simplify, perf, pyupgrade, and the complexity and size limits that
|
||||
# keep a function to one stage. No finding is waived in a baseline.
|
||||
- name: Lint the scripts, the tests and the installer
|
||||
run: |
|
||||
pip install "ruff==0.17.3"
|
||||
ruff check --output-format=github .
|
||||
|
||||
# A profile written from a clone can cite lines that do not hold the value
|
||||
# it declares, and schemas and tests pass it. Each profile a change adds is
|
||||
|
||||
+2
-1
@@ -85,7 +85,8 @@ does, and names at the end each check that failed or could not run:
|
||||
```bash
|
||||
python scripts/validate_pr.py --changed # the BIOS files the branch adds
|
||||
python scripts/validate_schemas.py --source-only # profiles and platform files
|
||||
mypy | mypy-baseline filter --no-colors # no type error beyond mypy-baseline.txt
|
||||
mypy # no type error in install.py and scripts/
|
||||
ruff check . # the lint rules of pyproject.toml
|
||||
python scripts/profile_sync.py --added --strict # each profile the branch adds
|
||||
vermin --no-tips -t=3.8- --violations install.py # install.py stays on Python 3.8
|
||||
shellcheck --version # the launcher test runs shellcheck
|
||||
|
||||
+4
-12
@@ -43,10 +43,10 @@ dev = [
|
||||
"setuptools>=61",
|
||||
# scripts/build_pypi.py runs `uv build` for the PyPI package and its test.
|
||||
"uv==0.13.4",
|
||||
# The type check CI runs, pinned: another mypy reports other errors
|
||||
# than the ones mypy-baseline.txt holds.
|
||||
# The type check CI runs, pinned: another mypy reports other errors.
|
||||
"mypy==2.4.1",
|
||||
"mypy-baseline==0.7.4",
|
||||
# The lint CI runs, pinned for the same reason.
|
||||
"ruff==0.17.3",
|
||||
]
|
||||
# The site is built by Astro Starlight from website/package.json and its
|
||||
# lockfile (npm ci --prefix website): no Python package builds it.
|
||||
@@ -57,10 +57,7 @@ Repository = "https://github.com/Abdess/retrobios"
|
||||
# The annotations are checked, not only written. Third-party packages are left
|
||||
# out (no_site_packages) so the result does not depend on what the machine
|
||||
# has installed: yaml, jsonschema and the rest read as Any everywhere. The
|
||||
# errors the code carried when the check started sit in mypy-baseline.txt.
|
||||
# CI fails on an error that is not there and on an entry that no longer
|
||||
# occurs: `mypy > out.txt`, then `mypy-baseline filter < out.txt`, and
|
||||
# `mypy-baseline sync < out.txt` once the fix is in.
|
||||
# code carries no type error and CI fails on any.
|
||||
[tool.mypy]
|
||||
files = ["install.py", "scripts"]
|
||||
# The oldest target mypy 2 checks against. install.py's own floor, 3.8, is
|
||||
@@ -72,11 +69,6 @@ no_site_packages = true
|
||||
disable_error_code = ["import-untyped"]
|
||||
cache_dir = "tmp/mypy_cache"
|
||||
|
||||
[tool.mypy-baseline]
|
||||
baseline_path = "mypy-baseline.txt"
|
||||
ignore_categories = ["note"]
|
||||
sort_baseline = true
|
||||
|
||||
# CI runs this rule set over every Python file (validate.yml, pr_checks.py).
|
||||
# C901 and the PLR limits hold function size: a function past them is split
|
||||
# by stage, not exempted.
|
||||
|
||||
+6
-10
@@ -30,9 +30,6 @@ class Step:
|
||||
needs: str = ""
|
||||
provider: str = ""
|
||||
env: dict[str, str] = field(default_factory=dict)
|
||||
# A second command that reads the first one's output, as a shell pipe
|
||||
# would: mypy's report goes through mypy-baseline filter.
|
||||
then: str = ""
|
||||
# validate.yml marks the step continue-on-error: its failure is shown
|
||||
# and does not fail the run.
|
||||
may_fail: bool = False
|
||||
@@ -43,8 +40,10 @@ class Step:
|
||||
STEPS: tuple[Step, ...] = (
|
||||
Step("python scripts/validate_pr.py --changed", "the BIOS files the branch adds"),
|
||||
Step("python scripts/validate_schemas.py --source-only", "profiles and platform files"),
|
||||
Step("mypy", "no type error beyond mypy-baseline.txt", needs="mypy",
|
||||
provider="the pip line of CONTRIBUTING.md", then="mypy-baseline filter --no-colors"),
|
||||
Step("mypy", "no type error in install.py and scripts/", needs="mypy",
|
||||
provider='pip install -e ".[dev]"'),
|
||||
Step("ruff check .", "the lint rules of pyproject.toml", needs="ruff",
|
||||
provider='pip install -e ".[dev]"'),
|
||||
Step("python scripts/profile_sync.py --added --strict", "each profile the branch adds"),
|
||||
Step("vermin --no-tips -t=3.8- --violations install.py", "install.py stays on Python 3.8",
|
||||
needs="vermin", provider="the pip line of CONTRIBUTING.md"),
|
||||
@@ -76,15 +75,12 @@ def argv(command: str) -> list[str]:
|
||||
|
||||
|
||||
def shown(step: Step) -> str:
|
||||
return f"{step.command} | {step.then}" if step.then else step.command
|
||||
return step.command
|
||||
|
||||
|
||||
def execute(step: Step) -> int:
|
||||
env = {**os.environ, **step.env}
|
||||
if not step.then:
|
||||
return subprocess.run(argv(step.command), cwd=ROOT, env=env, check=False).returncode
|
||||
first = subprocess.run(argv(step.command), cwd=ROOT, env=env, stdout=subprocess.PIPE, check=False)
|
||||
return subprocess.run(argv(step.then), cwd=ROOT, env=env, input=first.stdout, check=False).returncode
|
||||
return subprocess.run(argv(step.command), cwd=ROOT, env=env, check=False).returncode
|
||||
|
||||
|
||||
def run(steps: tuple[Step, ...] = STEPS) -> int:
|
||||
|
||||
@@ -3085,45 +3085,28 @@ class DeclaredDependenciesMatchTheDocumentedWorkflows(unittest.TestCase):
|
||||
class TheAnnotationsAreChecked(unittest.TestCase):
|
||||
"""Every signature carried type hints and nothing read them: six pack
|
||||
helpers declared `zipfile.ZipFile` while every caller also passed a
|
||||
PackRecord, and 990 such contradictions went through CI green. mypy now
|
||||
runs in CI against mypy-baseline.txt, the errors the code carried when the
|
||||
check started."""
|
||||
PackRecord, and 990 such contradictions went through CI green. They sat
|
||||
in a baseline until the last one was fixed: the code now carries no
|
||||
type error, and CI runs mypy bare, so any new one fails."""
|
||||
|
||||
BASELINE = ROOT / "mypy-baseline.txt"
|
||||
ENTRY = re.compile(r"(?P<path>[^:]+\.py):0: error: .+ \[[a-z-]+\]")
|
||||
|
||||
def test_ci_holds_the_code_to_the_baseline(self):
|
||||
def test_ci_runs_mypy_without_a_baseline(self):
|
||||
body = (ROOT / ".github" / "workflows" / "validate.yml").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
self.assertIn("mypy-baseline filter", body)
|
||||
self.assertNotIn("--allow-unsynced", body)
|
||||
self.assertRegex(body, r"(?m)^\s+mypy$")
|
||||
self.assertNotIn("mypy-baseline", body)
|
||||
self.assertFalse((ROOT / "mypy-baseline.txt").exists())
|
||||
|
||||
def test_every_baseline_entry_names_a_file_that_exists(self):
|
||||
stale = []
|
||||
for line in self.BASELINE.read_text(encoding="utf-8").splitlines():
|
||||
match = self.ENTRY.fullmatch(line)
|
||||
self.assertIsNotNone(match, f"unreadable baseline entry: {line}")
|
||||
if not (ROOT / match["path"]).is_file():
|
||||
stale.append(match["path"])
|
||||
self.assertEqual(stale, [], "baseline entries for files that are gone")
|
||||
|
||||
def test_the_code_reports_no_error_outside_the_baseline(self):
|
||||
for module in ("mypy", "mypy_baseline"):
|
||||
try:
|
||||
__import__(module)
|
||||
except ImportError:
|
||||
self.skipTest(f"{module} is not installed (pip install -e '.[dev]')")
|
||||
def test_the_code_reports_no_type_error(self):
|
||||
try:
|
||||
__import__("mypy")
|
||||
except ImportError:
|
||||
self.skipTest("mypy is not installed (pip install -e '.[dev]')")
|
||||
report = subprocess.run(
|
||||
[sys.executable, "-m", "mypy"],
|
||||
cwd=ROOT, capture_output=True, text=True, check=False,
|
||||
)
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "mypy_baseline", "filter", "--no-colors"],
|
||||
cwd=ROOT, input=report.stdout, capture_output=True, text=True,
|
||||
check=False,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stdout)
|
||||
self.assertEqual(report.returncode, 0, report.stdout[-4000:])
|
||||
|
||||
|
||||
class TheProjectInstallsWithPip(unittest.TestCase):
|
||||
|
||||
@@ -239,7 +239,7 @@ class OneCommandRunsTheChecks(unittest.TestCase):
|
||||
skipping one (refresh_data_dirs) failed the pack tests with no hint."""
|
||||
|
||||
CHECK = re.compile(r"(?:xargs -0 |run: |^\s*)((?:python3?\.?8? -m unittest|python scripts/\w+\.py"
|
||||
r"|vermin|npm (?:ci|run build)|mypy-baseline filter|mypy|shellcheck))")
|
||||
r"|vermin|npm (?:ci|run build)|mypy|ruff check|shellcheck))")
|
||||
|
||||
def test_every_check_ci_runs_is_a_step(self):
|
||||
import pr_checks
|
||||
@@ -248,7 +248,7 @@ class OneCommandRunsTheChecks(unittest.TestCase):
|
||||
ran = {m.group(1) for line in workflow.splitlines()
|
||||
if not line.strip().startswith("#") for m in [self.CHECK.search(line)] if m}
|
||||
self.assertGreaterEqual(len(ran), 10)
|
||||
steps = [c for step in pr_checks.STEPS for c in (step.command, step.then) if c]
|
||||
steps = [step.command for step in pr_checks.STEPS]
|
||||
for check in sorted(ran):
|
||||
with self.subTest(check=check):
|
||||
self.assertTrue(any(command.startswith(check) for command in steps))
|
||||
|
||||
+13
-7
@@ -530,16 +530,22 @@ with BIOS validation and auto-labeling too. Those two read pull request context
|
||||
and stay behind an event guard.
|
||||
|
||||
The schema job also runs mypy over `install.py` and `scripts/`. The code
|
||||
carried 993 type errors when the check started, so they sit in
|
||||
`mypy-baseline.txt` and only a new one fails. An error the change removes fails
|
||||
too until the baseline is synced, so the file never hides a later error that
|
||||
reads the same:
|
||||
carried 993 type errors when the check started. They sat in a baseline until the
|
||||
last one was fixed, and the baseline is gone: the code carries no type error and
|
||||
any new one fails.
|
||||
|
||||
```bash
|
||||
pip install -e ".[dev]"
|
||||
mypy > tmp/mypy.txt
|
||||
mypy-baseline filter < tmp/mypy.txt # what CI runs
|
||||
mypy-baseline sync < tmp/mypy.txt # after a fix, commit the new baseline
|
||||
mypy
|
||||
```
|
||||
|
||||
The same job runs ruff with the rule set of `pyproject.toml`: pyflakes, the B
|
||||
rules, simplify, perf, pyupgrade, and the complexity and size limits (15 branches,
|
||||
60 statements, 8 arguments per function). A long function is split by stage and
|
||||
its shared state carried in a dataclass, never waived: there is no lint baseline.
|
||||
|
||||
```bash
|
||||
ruff check .
|
||||
```
|
||||
|
||||
A push series collapses to the tip, so what a green run states is that the head
|
||||
|
||||
Reference in new issue
Block a user