Skip to content

Feat/pre commit #1616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 12, 2025
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: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: local
hooks:
- id: black
name: "Run black"
language: system
entry: "./.pre-commit-scripts.sh black gateway client"
pass_filenames: false
- id: lint
name: "Run lint"
language: system
entry: "./.pre-commit-scripts.sh lint gateway client"
pass_filenames: false
66 changes: 66 additions & 0 deletions .pre-commit-scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

set -e

cd "$(dirname "$0")"

activate_venv() {
local found_venv=$(find . -maxdepth 3 -name "activate")

if [ -n "$found_venv" ]; then
local venv_path=$(dirname "$(dirname "$found_venv")")
local venv_folder=$(basename "$venv_path")
source "$found_venv"
else
echo "❌ No virtual environment found"
exit 1
fi
}

run_black() {
local dir="$1"
echo "➡️ Running black in $dir..."
cd "$dir"
activate_venv
tox -eblack
cd - > /dev/null
}

run_lint() {
local dir="$1"
echo "➡️ Running lint in $dir..."
cd "$dir"
activate_venv
tox -elint
cd - > /dev/null
}

main() {
local command="$1"
shift

if [ $# -eq 0 ]; then
echo "Please provide at least one directory"
exit 1
fi

case "$command" in
black)
for dir in "$@"; do
run_black "$dir"
done
;;
lint)
for dir in "$@"; do
run_lint "$dir"
done
;;
*)
echo "Unknown command: $command"
echo "Usage: $0 {black|lint} <dir1> [dir2] [...]"
exit 1
;;
esac
}

main "$@"
Loading