Skip to content

Commit dd6993e

Browse files
refactor(scripts): share ruff setup in ruff-common.sh
1 parent 131d8b2 commit dd6993e

3 files changed

Lines changed: 27 additions & 30 deletions

File tree

scripts/format

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5-
cd "$root"
6-
dev_requirements="$root/requirements-dev.txt"
4+
source "$(dirname "${BASH_SOURCE[0]}")/ruff-common.sh"
5+
ruff_common_setup
6+
ruff_resolve_targets "$@"
77

8-
if ! command -v ruff >/dev/null 2>&1; then
9-
echo "ruff not found; install with: pip install -r $dev_requirements" >&2
10-
exit 1
11-
fi
12-
13-
targets=("$@")
14-
if [ "${#targets[@]}" -eq 0 ]; then
15-
targets=(".")
16-
fi
17-
18-
ruff check --fix "${targets[@]}"
19-
ruff format "${targets[@]}"
8+
ruff check --fix "${RUFF_TARGETS[@]}"
9+
ruff format "${RUFF_TARGETS[@]}"

scripts/lint

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,9 @@
22
set -euo pipefail
33

44
# Matches the ruff job in .github/workflows/ci.yml (see also scripts/format).
5-
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
6-
cd "$root"
7-
dev_requirements="$root/requirements-dev.txt"
5+
source "$(dirname "${BASH_SOURCE[0]}")/ruff-common.sh"
6+
ruff_common_setup
7+
ruff_resolve_targets "$@"
88

9-
if ! command -v ruff >/dev/null 2>&1; then
10-
echo "ruff not found; install with: pip install -r $dev_requirements" >&2
11-
exit 1
12-
fi
13-
14-
targets=("$@")
15-
if [ "${#targets[@]}" -eq 0 ]; then
16-
targets=(".")
17-
fi
18-
19-
ruff format --check "${targets[@]}"
20-
ruff check "${targets[@]}"
9+
ruff format --check "${RUFF_TARGETS[@]}"
10+
ruff check "${RUFF_TARGETS[@]}"

scripts/ruff-common.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Shared setup for scripts/lint and scripts/format.
2+
ruff_common_setup() {
3+
RUFF_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
4+
cd "$RUFF_ROOT"
5+
6+
if ! command -v ruff >/dev/null 2>&1; then
7+
echo "ruff not found; install with: pip install -r $RUFF_ROOT/requirements-dev.txt" >&2
8+
exit 1
9+
fi
10+
}
11+
12+
ruff_resolve_targets() {
13+
RUFF_TARGETS=("$@")
14+
if [ "${#RUFF_TARGETS[@]}" -eq 0 ]; then
15+
RUFF_TARGETS=(".")
16+
fi
17+
}

0 commit comments

Comments
 (0)