#!/usr/bin/env bash # Lint and format Python files with `ruff`. # # This will format files in the working directory by default, or you # can supply one or more paths for it to check. set -o errexit set -o nounset # Work out which directory to run in: # # * if no argument is specified, use the current working directory # * if one or more directories are specified, use those # # TODO: What if somebody passes a custom directory and `--fix`? if (( $# == 0 )) then ROOT="$(pwd)" elif [[ "$#" = "1" && "$1" = "--fix" ]] then ROOT="$(pwd)" else ROOT="$@" fi # Work out which instance of ruff to use # # If we're in a virtualenv which has ruff installed, we use the locally # installed copy. # # If not, we use the `ruff` from my ~/repos/scripts virtualenv. if which ruff >/dev/null then RUFF="$(which ruff)" else RUFF=~/repos/scripts/.venv/bin/ruff fi print_info "-> ruff format" bash -c "$RUFF format $ROOT" echo "" print_info "-> ruff check --fix" bash -c "$RUFF check $ROOT --fix"