Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
exclude: '^docs'
default_stages: [pre-commit]

default_language_version:
python: python3

repos:
- repo: https://github.com/rcolfin/pre-commit-hooks
rev: v0.3.0
rev: v0.3.1
hooks:
- id: mypy-linter
- id: shellcheck-linter
Expand Down Expand Up @@ -31,6 +37,11 @@ repos:
# Formatter
- id: ruff-format

- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
hooks:
- id: nbstripout

# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
ci:
autoupdate_schedule: weekly
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Add this to your `.pre-commit-config.yaml`

```yaml
- repo: https://github.com/rcolfin/pre-commit-hooks
rev: v0.3.0
rev: v0.3.1
hooks:
- id: mypy-linter
- id: shellcheck-linter
Expand Down
3 changes: 2 additions & 1 deletion pre_commit_hooks/mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ def main() -> int:
logger.error("unable to locate either poetry or uv.")
return 1

cwd = Path(args.cwd)
cwd = Path(args.cwd).resolve()
if not cwd.is_dir():
logger.error("%s is not a directory.", cwd)
return 1

os.chdir(str(cwd))
packages = _get_changed_packages(args.filenames)

Expand Down
3 changes: 2 additions & 1 deletion pre_commit_hooks/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ def main() -> int:
return 1

cmd = args.cmd
cwd = Path(args.cwd)
cwd = Path(args.cwd).resolve()
if not cwd.is_dir():
logger.error("%s is not a directory.", cwd)
return 1

os.chdir(str(cwd))
packages = _get_changed_packages(args.filenames)

Expand Down
21 changes: 18 additions & 3 deletions pre_commit_hooks/shellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import argparse
import logging
import os
import shutil
import subprocess
from pathlib import Path
from typing import TYPE_CHECKING, Final
from typing import TYPE_CHECKING, Final, cast

from pre_commit_hooks import util

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

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


def _get_files(filenames: Sequence[str]) -> set[Path]:
Expand All @@ -30,18 +32,31 @@ def main() -> int:
nargs="*",
help="Filenames pre-commit believes are changed.",
)
parser.add_argument(
"--cwd",
type=str,
default=str(Path.cwd()),
help="The current working directory.",
)

args, extra_args = parser.parse_known_args()

if SHELLCHECK_PATH is None:
if SHELLCHECK_PATH is None and UV_SHELLCHECK_PATH is None:
logger.error("shellcheck not found.")
return 1

cwd = Path(args.cwd).resolve()
if not cwd.is_dir():
logger.error("%s is not a directory.", cwd)
return 1

os.chdir(str(cwd))
files = _get_files(args.filenames)
cwd = Path.cwd().resolve()

exitcode = 0
cmds = ("shellcheck", *extra_args)
if SHELLCHECK_PATH is None:
cmds = (cast(str, UV_SHELLCHECK_PATH), "run", *cmds)
for file in files:
if not util.is_shell_script(file):
logger.debug("%s is not a shell script.", file.relative_to(cwd))
Expand Down
2 changes: 1 addition & 1 deletion pre_commit_hooks/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main() -> int:
return 1

cmd = args.cmd
cwd = Path(args.cwd)
cwd = Path(args.cwd).resolve()
if not cwd.is_dir():
logger.error("%s is not a directory.", cwd)
return 1
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requires-python = "<4.0,>=3.10"
dependencies = []
name = "pre-commit-hooks"
version = "0.3.0"
version = "0.3.1"
description = ""
authors = [
{name = "Robert Colfin", email = "robert.m.colfin@gmail.com"},
Expand Down
3 changes: 2 additions & 1 deletion scripts/setup-uv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function activate() {
uv venv
fi

[ -f .venv/bin/activate ] && source .venv/bin/activate
# shellcheck disable=SC1091
[ -f .venv/bin/activate ] && source ".venv/bin/activate"
}

function main() {
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.