Skip to content

CI: Correct ruff scope and add basedpyright pre-commit hook - #301

Merged
keanjapesan merged 3 commits into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:chore/linting-standardization
Aug 17, 2026
Merged

keanjapesan merged 3 commits into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:chore/linting-standardization

Conversation

@ModeSevenIndustrialSolutions

@ModeSevenIndustrialSolutions ModeSevenIndustrialSolutions commented Aug 17, 2026 •

Copy link
Copy Markdown
Member

Summary

A generalised linting-configuration update that standardises this
repository's pre-commit setup against the canonical
lfreleng-actions/actions-template reference. Three focused commits.

1. Correct the ruff hook scope (remove a Home Assistant artefact)

The ruff and ruff-format hooks filtered files through
^(scripts|tests|custom_components)/.+\.py$ — a pattern inherited from a
Home Assistant configuration. This repository has no custom_components/
directory, no Python under scripts/ (only shell scripts), and its
package source under src/. So the filter silently excluded the whole
package from ruff
— only tests/ was ever linted or formatted in the
gate. Dropping the filter lets ruff and ruff-format apply to all Python.
The package source already conforms, so no source changes were required.

2. Guard the generated _version import for type-checkers

src/tag_validate/_version.py is generated by hatch-vcs at build time
and is absent from a plain source checkout. The runtime import is now
moved into an else branch with __version__ declared under
TYPE_CHECKING, so static analysis resolves the symbol without the
generated module. Runtime behaviour is unchanged (the
importlib.metadata fallback still runs).

3. Add the basedpyright pre-commit hook (Closes #258)

Added the hook from DetachHead/basedpyright-prek-mirror, pinned to
1.39.9, inserted without disturbing the repo's own customizations (mypy
additional_dependencies, write-good/codespell excludes and args, the
skip: list).

basedpyright is skipped on pre-commit.ci. The mirror bundles a Node
runtime, so its hook environment is ~246 MiB on its own — only ~4 MiB
under pre-commit.ci's 250 MiB tier limit. Installing the project's
dependencies via additional_dependencies (needed to resolve imports in
the sandbox's clean, .venv-less environment) pushed the build to
300.1 MiB and it was rejected. Since there is no room for the imports in
that environment, the hook is added to the ci.skip list — the same
pattern already used for gha-workflow-linter. It still runs for local
developers via prek/pre-commit, where the project .venv provides
import resolution.

Validation

  • prek run --all-files — all hooks pass (basedpyright runs locally; the
    ci.skip entry only affects pre-commit.ci).
  • prek run basedpyright --all-files → 0 errors.

Acceptance criteria (#258)

  • Remaining basedpyright errors resolved or scoped (0 errors)
  • basedpyright hook added, preserving existing config
  • prek run basedpyright --all-files reports 0 errors
  • CI green (basedpyright skipped on the pre-commit.ci sandbox)

Closes #258

The ruff and ruff-format hooks filtered files through
"^(scripts|tests|custom_components)/.+\.py$", a pattern inherited
from a Home Assistant configuration. This repository has no
custom_components directory and no Python under scripts, and its
package source lives under src/, so the filter silently excluded
the whole package: only tests/ was ever linted or formatted.

Drop the filter so ruff and ruff-format apply to every Python file
in the repository. The package source already conforms, so this
needs no source changes.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions requested review from a team and a balanced review from Copilot August 17, 2026 07:32
@github-actions github-actions Bot added the CI CI and tests updates label Aug 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates linting coverage and adds basedpyright validation.

Changes:

  • Expands Ruff checks to all Python files.
  • Adds the pinned basedpyright pre-commit hook.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .pre-commit-config.yaml Resolved
hatch-vcs generates src/tag_validate/_version.py at build time, so it
is absent from a plain source checkout such as the isolated
environment a pre-commit type-checker hook runs in. basedpyright
could not resolve "from tag_validate._version import __version__"
there and, in turn, flagged "from . import __version__" in the CLI
modules that re-export it.

Move the runtime import into an else branch and declare __version__
under TYPE_CHECKING, so static analysis resolves the symbol without
the generated module present. Runtime behaviour is unchanged: the
try/importlib.metadata fallback still runs.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
Copilot AI review requested due to automatic review settings August 17, 2026 07:42

This comment was marked as outdated.

The canonical linting setup in lfreleng-actions/actions-template runs
the basedpyright type-checker as a pre-commit hook. This repository
already carries a [tool.basedpyright] configuration block
(typeCheckingMode = "standard") but never wired up the hook, so the
type-checker only ran in editors, not in the gate.

Add the hook from the DetachHead/basedpyright-prek-mirror, pinned to
1.39.9 to match the canonical reference, inserted without disturbing
the repo's own customizations (mypy additional_dependencies,
write-good/codespell excludes and args, the skip list).

Skip the hook on pre-commit.ci. The mirror bundles a Node runtime, so
its hook environment is ~246MiB before any project dependencies, and
the runtime imports needed for type resolution push it past the
250MiB tier limit. The hook still runs for local developers via prek/
pre-commit, where the project .venv resolves imports, so this follows
the existing pattern of skipping sandbox-incompatible hooks such as
gha-workflow-linter.

Closes: lfreleng-actions#258

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
Copilot AI review requested due to automatic review settings August 17, 2026 07:51

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@keanjapesan
keanjapesan merged commit 00f2e13 into lfreleng-actions:main Aug 17, 2026
37 checks passed

@zxiiro zxiiro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Auto-approved by agent: reviewed workflow/code change for security and CI/CD impact, found low risk. Corrects an overly-narrow ruff file scope, adds a basedpyright pre-commit hook (skipped on pre-commit.ci due to a documented size-tier limit, still runs locally), and makes the version import resolve correctly under static type-checking. No security or CI-pipeline impact.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the chore/linting-standardization branch August 17, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI CI and tests updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add basedpyright pre-commit hook to match canonical linting

4 participants