Files
dify/dev/pyrefly-check-local
-LAN- 301d00f2df fix(dev): handle empty pyrefly target paths
Build the pyrefly command before execution and append target paths only when provided so Bash 3.2 with nounset does not fail on an empty array.
2026-05-18 15:56:39 +08:00

54 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
REPO_ROOT="$SCRIPT_DIR/.."
cd "$REPO_ROOT"
EXCLUDES_FILE="api/pyrefly-local-excludes.txt"
target_paths=()
for target_path in "$@"; do
if [[ "$target_path" == api/* ]]; then
target_paths+=("${target_path#api/}")
else
target_paths+=("$target_path")
fi
done
pyrefly_args=(
"--summary=none"
"--use-ignore-files=false"
"--disable-project-excludes-heuristics=true"
"--project-excludes=.venv"
"--project-excludes=migrations/"
"--project-excludes=tests/"
)
if [[ -f "$EXCLUDES_FILE" ]]; then
while IFS= read -r exclude; do
[[ -z "$exclude" || "${exclude:0:1}" == "#" ]] && continue
pyrefly_args+=("--project-excludes=$exclude")
done < "$EXCLUDES_FILE"
fi
tmp_output="$(mktemp)"
pyrefly_command=(
uv run --directory api --dev pyrefly check
"${pyrefly_args[@]}"
)
if (( ${#target_paths[@]} > 0 )); then
pyrefly_command+=("${target_paths[@]}")
fi
set +e
"${pyrefly_command[@]}" >"$tmp_output" 2>&1
pyrefly_status=$?
set -e
uv run --directory api python libs/pyrefly_diagnostics.py < "$tmp_output"
rm -f "$tmp_output"
exit "$pyrefly_status"