File tree Expand file tree Collapse file tree 6 files changed +80
-8
lines changed
get-skipped-pre-commit-hooks Expand file tree Collapse file tree 6 files changed +80
-8
lines changed Original file line number Diff line number Diff line change 49
49
" noreply" ,
50
50
" numprocesses" ,
51
51
" pyright" ,
52
+ " rtoml" ,
52
53
" taplo" ,
53
54
" tomllib"
54
55
],
Original file line number Diff line number Diff line change 19
19
20
20
env :
21
21
DISABLE_PRE_COMMIT_UV_PATCH : True
22
+ FORCE_COLOR : true
22
23
23
24
jobs :
24
25
determine-hooks :
51
52
**/pyproject.toml
52
53
**/uv.lock
53
54
enable-cache : true
54
- - name : Determine if repository is Python package
55
- run : |
56
- uv_command=$(uv pip install -e '.[sty]' > /dev/null && uv sync --group style --no-dev && echo "uv run --group style --no-dev" || echo uvx)
57
- echo "UV_COMMAND=$uv_command" | tee -a "$GITHUB_ENV"
58
55
- name : Fetch pre-commit cache
59
56
uses : actions/cache@v4
60
57
with :
63
60
restore-keys : |
64
61
pre-commit-${{ runner.os }}-py${{ inputs.python-version }}
65
62
path : ~/.cache/pre-commit/
63
+ - id : uv-run
64
+ uses : ComPWA/actions/run-pre-commit@v2
66
65
- if : needs.determine-hooks.outputs.skipped-hooks == 'ALL'
67
- run : ${{ env.UV_COMMAND }} --with pre-commit-uv pre-commit run --all-files --color always
66
+ run : ${{ steps.uv-run.outputs.cmd }} --with pre-commit-uv pre-commit run --all-files
68
67
- if : needs.determine-hooks.outputs.skipped-hooks != 'ALL'
69
68
name : Run pre-commit hooks that don't work on pre-commit.ci
70
69
run : |-
73
72
export PRETTIER_LEGACY_CLI=1
74
73
fi
75
74
for hook in $skipped_hooks; do
76
- ${{ env.UV_COMMAND }} --with pre-commit-uv pre-commit run $hook --all-files --color always
75
+ ${{ steps.uv-run.outputs.cmd }} --with pre-commit-uv pre-commit run $hook --all-files
77
76
done
78
77
- id : diff
79
78
if : always()
Original file line number Diff line number Diff line change 15
15
using : composite
16
16
steps :
17
17
- uses : actions/checkout@v4
18
+ with :
19
+ sparse-checkout : .pre-commit-config.yaml
18
20
- uses : actions/setup-python@v5
19
21
with :
20
22
python-version : " 3.12"
Original file line number Diff line number Diff line change @@ -15,8 +15,15 @@ content-type = "text/markdown"
15
15
file = " README.md"
16
16
17
17
[dependency-groups ]
18
- dev = [" ruff" ]
19
- style = [" packaging" ]
18
+ dev = [
19
+ " ruff" ,
20
+ {include-group = " style" },
21
+ ]
22
+ style = [
23
+ " PyYAML" ,
24
+ " packaging" ,
25
+ " rtoml" ,
26
+ ]
20
27
21
28
[tool .setuptools ]
22
29
include-package-data = false
@@ -32,6 +39,8 @@ reportUnknownMemberType = false
32
39
reportUnknownParameterType = false
33
40
reportUnknownVariableType = false
34
41
typeCheckingMode = " strict"
42
+ venv = " .venv"
43
+ venvPath = " ."
35
44
36
45
[tool .ruff ]
37
46
preview = true
Original file line number Diff line number Diff line change
1
+ name : Run pre-commit hooks with style environment
2
+ description : >-
3
+ Run local pre-commit hooks that may require the installation of a virtual environment.
4
+
5
+ outputs :
6
+ cmd :
7
+ description : >-
8
+ The uv run command to use for `pre-commit`
9
+ value : ${{ steps.uv-run.outputs.cmd }}
10
+
11
+ runs :
12
+ using : composite
13
+ steps :
14
+ - env :
15
+ UV_SYSTEM_PYTHON : 1
16
+ id : uv-run
17
+ name : Determine skipped hooks
18
+ run : echo "cmd=$(uv run -p3.12 $GITHUB_ACTION_PATH/main.py)" | tee -a $GITHUB_OUTPUT
19
+ shell : bash
Original file line number Diff line number Diff line change
1
+ """Determine which pre-commit hooks should be skipped."""
2
+
3
+ # /// script
4
+ # dependencies = ["rtoml"]
5
+ # ///
6
+ from pathlib import Path
7
+
8
+ import rtoml
9
+
10
+
11
+ def main () -> None :
12
+ cmd = _get_uv_run_command ()
13
+ print (cmd )
14
+
15
+
16
+ def _get_uv_run_command () -> str :
17
+ pyproject_path = Path ("pyproject.toml" )
18
+ if pyproject_path .is_file ():
19
+ pyproject = rtoml .load (pyproject_path )
20
+ dependency_groups = pyproject .get ("dependency-groups" )
21
+ candidate_groups = [
22
+ "style" ,
23
+ "sty" ,
24
+ "lint" ,
25
+ ]
26
+ if dependency_groups is not None :
27
+ for group in candidate_groups :
28
+ if group in dependency_groups :
29
+ return f"uv run --group { group } --no-dev"
30
+ project_table = pyproject .get ("project" , {})
31
+ extras = project_table .get ("optional-dependencies" )
32
+ if extras is not None :
33
+ for extra in candidate_groups :
34
+ if extra in extras :
35
+ return f"uv run --extra { extra } --no-dev"
36
+ if "dependencies" in project_table :
37
+ return "uv run --no-dev"
38
+ return "uvx"
39
+
40
+
41
+ if __name__ == "__main__" :
42
+ raise SystemExit (main ())
You can’t perform that action at this time.
0 commit comments