Skip to content

Commit d14a285

Browse files
authored
Merge pull request #33 from rcolfin/uv
Updating pre-commit-hooks to use uv checks.
2 parents bc87e2c + 09987b1 commit d14a285

9 files changed

Lines changed: 40 additions & 11 deletions

File tree

.pre-commit-config.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
exclude: '^docs'
2+
default_stages: [pre-commit]
3+
4+
default_language_version:
5+
python: python3
6+
17
repos:
28
- repo: https://github.com/rcolfin/pre-commit-hooks
3-
rev: v0.3.0
9+
rev: v0.3.1
410
hooks:
511
- id: mypy-linter
612
- id: shellcheck-linter
@@ -31,6 +37,11 @@ repos:
3137
# Formatter
3238
- id: ruff-format
3339

40+
- repo: https://github.com/kynan/nbstripout
41+
rev: 0.8.1
42+
hooks:
43+
- id: nbstripout
44+
3445
# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
3546
ci:
3647
autoupdate_schedule: weekly

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Add this to your `.pre-commit-config.yaml`
2929

3030
```yaml
3131
- repo: https://github.com/rcolfin/pre-commit-hooks
32-
rev: v0.3.0
32+
rev: v0.3.1
3333
hooks:
3434
- id: mypy-linter
3535
- id: shellcheck-linter

pre_commit_hooks/mypy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ def main() -> int:
4444
logger.error("unable to locate either poetry or uv.")
4545
return 1
4646

47-
cwd = Path(args.cwd)
47+
cwd = Path(args.cwd).resolve()
4848
if not cwd.is_dir():
4949
logger.error("%s is not a directory.", cwd)
5050
return 1
51+
5152
os.chdir(str(cwd))
5253
packages = _get_changed_packages(args.filenames)
5354

pre_commit_hooks/poetry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ def main() -> int:
4949
return 1
5050

5151
cmd = args.cmd
52-
cwd = Path(args.cwd)
52+
cwd = Path(args.cwd).resolve()
5353
if not cwd.is_dir():
5454
logger.error("%s is not a directory.", cwd)
5555
return 1
56+
5657
os.chdir(str(cwd))
5758
packages = _get_changed_packages(args.filenames)
5859

pre_commit_hooks/shellcheck.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import argparse
44
import logging
5+
import os
56
import shutil
67
import subprocess
78
from pathlib import Path
8-
from typing import TYPE_CHECKING, Final
9+
from typing import TYPE_CHECKING, Final, cast
910

1011
from pre_commit_hooks import util
1112

@@ -15,6 +16,7 @@
1516
logger = logging.getLogger(__name__)
1617

1718
SHELLCHECK_PATH: Final[str | None] = shutil.which("shellcheck")
19+
UV_SHELLCHECK_PATH: Final[str | None] = shutil.which("uv")
1820

1921

2022
def _get_files(filenames: Sequence[str]) -> set[Path]:
@@ -30,18 +32,31 @@ def main() -> int:
3032
nargs="*",
3133
help="Filenames pre-commit believes are changed.",
3234
)
35+
parser.add_argument(
36+
"--cwd",
37+
type=str,
38+
default=str(Path.cwd()),
39+
help="The current working directory.",
40+
)
3341

3442
args, extra_args = parser.parse_known_args()
3543

36-
if SHELLCHECK_PATH is None:
44+
if SHELLCHECK_PATH is None and UV_SHELLCHECK_PATH is None:
3745
logger.error("shellcheck not found.")
3846
return 1
3947

48+
cwd = Path(args.cwd).resolve()
49+
if not cwd.is_dir():
50+
logger.error("%s is not a directory.", cwd)
51+
return 1
52+
53+
os.chdir(str(cwd))
4054
files = _get_files(args.filenames)
41-
cwd = Path.cwd().resolve()
4255

4356
exitcode = 0
4457
cmds = ("shellcheck", *extra_args)
58+
if SHELLCHECK_PATH is None:
59+
cmds = (cast(str, UV_SHELLCHECK_PATH), "run", *cmds)
4560
for file in files:
4661
if not util.is_shell_script(file):
4762
logger.debug("%s is not a shell script.", file.relative_to(cwd))

pre_commit_hooks/uv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def main() -> int:
4949
return 1
5050

5151
cmd = args.cmd
52-
cwd = Path(args.cwd)
52+
cwd = Path(args.cwd).resolve()
5353
if not cwd.is_dir():
5454
logger.error("%s is not a directory.", cwd)
5555
return 1

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
requires-python = "<4.0,>=3.10"
33
dependencies = []
44
name = "pre-commit-hooks"
5-
version = "0.3.0"
5+
version = "0.3.1"
66
description = ""
77
authors = [
88
{name = "Robert Colfin", email = "robert.m.colfin@gmail.com"},

scripts/setup-uv.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ function activate() {
4444
uv venv
4545
fi
4646

47-
[ -f .venv/bin/activate ] && source .venv/bin/activate
47+
# shellcheck disable=SC1091
48+
[ -f .venv/bin/activate ] && source ".venv/bin/activate"
4849
}
4950

5051
function main() {

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)