Skip to content

Commit 8a2bcde

Browse files
author
Elias Werner
committed
add pre-commit hooks, fix formatting
1 parent 0a69bae commit 8a2bcde

4 files changed

Lines changed: 54 additions & 3 deletions

File tree

.githooks/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
For project contributors:
2+
3+
Feel free to use this pre-commit hooks in your local setups.
4+
5+
It does the same as the workflows that run on github:
6+
- format the files with black
7+
- linting the files with flake8
8+
- run the tests
9+
10+
Just copy the file into your `.git/hooks/` directory or set it up via a `.pre-commit-config.yaml` file.

.githooks/pre-commit

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Git pre-commit hook to run code quality checks
4+
# This hook runs black, flake8, and pytest before allowing commits
5+
6+
set -e
7+
8+
# 1. Run black with line length 79
9+
echo "Running black formatting check..."
10+
if ! black -l 79 .; then
11+
echo "❌ Black formatting failed. Please fix formatting issues."
12+
exit 1
13+
fi
14+
echo "✅ Black formatting passed"
15+
16+
# 2. Run flake8 on jumper_extension directory
17+
echo "Running flake8 linting..."
18+
if ! flake8 --extend-ignore=E203 src; then
19+
echo "❌ Flake8 linting failed. Please fix linting issues."
20+
exit 1
21+
fi
22+
echo "✅ Flake8 linting passed"
23+
24+
25+
# 3. Run pytest with coverage
26+
echo "Running tests..."
27+
if ! python -m unittest tests.test_userpersistence; then
28+
echo "❌ Tests failed. Please fix failing tests Maybe you need to install the recent version of ther kernel via pip install . && python -m scorepjupyter.install."
29+
exit 1
30+
fi
31+
32+
if ! python -m unittest tests.test_kernel; then
33+
echo "❌ Tests failed. Please fix failing tests."
34+
exit 1
35+
fi
36+
37+
echo "✅ All tests passed"
38+
39+
echo "🎉 All pre-commit checks passed! Proceeding with commit."

src/scorep_jupyter/kernel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,8 @@ async def do_execute(
903903
if shutil.which("vampir") is None:
904904
self.log_error(KernelErrorCode.VAMPIR_NOT_FOUND)
905905
else:
906-
self.cell_output("Vampir will be launched after next instrumented execution.")
906+
self.cell_output("Vampir will be launched after next "
907+
"instrumented execution.")
907908
return self.standard_reply()
908909
elif code.startswith("%%disable_vampir_launch"):
909910
self.launch_vampir_requested = False

src/scorep_jupyter/kernel_messages.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ class KernelErrorCode(Enum):
4444
"(looked in: {scorep_folder})"
4545
),
4646
KernelErrorCode.VAMPIR_NOT_FOUND: (
47-
'Vampir binary not found in PATH. Add it to PATH to enable automatic launch'
48-
' (e.g. in ~/.bashrc: export PATH="/path/to/vampir/bin:$PATH"'
47+
'Vampir binary not found in PATH. Add it to PATH to enable '
48+
'automatic launch'
49+
' (e.g. in ~/.bashrc: export PATH="/path/to/vampir/bin:$PATH"'
4950
),
5051

5152
KernelErrorCode.VAMPIR_LAUNCH_FAILED: (

0 commit comments

Comments
 (0)