-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: determine dependency group for
pre-commit
(#116)
* DX: run `pyright` with `venv` * ENH: use sparce checkout in `get-skipped-pre-commit-hooks` * FIX: install `PyYAML` in `style group * FIX: install `style` group in `dev` dependencies
- Loading branch information
Showing
6 changed files
with
80 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
"noreply", | ||
"numprocesses", | ||
"pyright", | ||
"rtoml", | ||
"taplo", | ||
"tomllib" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Run pre-commit hooks with style environment | ||
description: >- | ||
Run local pre-commit hooks that may require the installation of a virtual environment. | ||
outputs: | ||
cmd: | ||
description: >- | ||
The uv run command to use for `pre-commit` | ||
value: ${{ steps.uv-run.outputs.cmd }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- env: | ||
UV_SYSTEM_PYTHON: 1 | ||
id: uv-run | ||
name: Determine skipped hooks | ||
run: echo "cmd=$(uv run -p3.12 $GITHUB_ACTION_PATH/main.py)" | tee -a $GITHUB_OUTPUT | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Determine which pre-commit hooks should be skipped.""" | ||
|
||
# /// script | ||
# dependencies = ["rtoml"] | ||
# /// | ||
from pathlib import Path | ||
|
||
import rtoml | ||
|
||
|
||
def main() -> None: | ||
cmd = _get_uv_run_command() | ||
print(cmd) | ||
|
||
|
||
def _get_uv_run_command() -> str: | ||
pyproject_path = Path("pyproject.toml") | ||
if pyproject_path.is_file(): | ||
pyproject = rtoml.load(pyproject_path) | ||
dependency_groups = pyproject.get("dependency-groups") | ||
candidate_groups = [ | ||
"style", | ||
"sty", | ||
"lint", | ||
] | ||
if dependency_groups is not None: | ||
for group in candidate_groups: | ||
if group in dependency_groups: | ||
return f"uv run --group {group} --no-dev" | ||
project_table = pyproject.get("project", {}) | ||
extras = project_table.get("optional-dependencies") | ||
if extras is not None: | ||
for extra in candidate_groups: | ||
if extra in extras: | ||
return f"uv run --extra {extra} --no-dev" | ||
if "dependencies" in project_table: | ||
return "uv run --no-dev" | ||
return "uvx" | ||
|
||
|
||
if __name__ == "__main__": | ||
raise SystemExit(main()) |