Skip to content

Commit cf101bc

Browse files
committed
chore: add pre-commit hook and fix release workflow
- Add pre-commit hook for ruff linting - Add 'make install-hooks' target - Fix release.yml: use ref_name, add error handling, fix git refs
1 parent 58eb3f8 commit cf101bc

6 files changed

Lines changed: 88 additions & 37 deletions

File tree

.githooks/pre-commit

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# Pre-commit hook to run linting on staged Python files
3+
4+
echo "Running pre-commit lint checks..."
5+
6+
# Get list of staged Python files
7+
STAGED_PY_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$' || true)
8+
9+
if [ -z "$STAGED_PY_FILES" ]; then
10+
echo "No Python files staged, skipping lint check."
11+
exit 0
12+
fi
13+
14+
echo "Linting staged Python files:"
15+
echo "$STAGED_PY_FILES"
16+
echo ""
17+
18+
# Check if ruff is available
19+
if command -v ruff &> /dev/null; then
20+
RUFF_CMD="ruff"
21+
elif [ -d "venv" ] && [ -f "venv/bin/ruff" ]; then
22+
RUFF_CMD="venv/bin/ruff"
23+
else
24+
echo "Error: ruff not found. Please install it or ensure venv is set up."
25+
exit 1
26+
fi
27+
28+
# Run ruff check on staged files
29+
if ! echo "$STAGED_PY_FILES" | xargs "$RUFF_CMD" check; then
30+
echo ""
31+
echo "❌ Linting failed! Please fix the errors above before committing."
32+
echo " Run 'make lint' for full details."
33+
exit 1
34+
fi
35+
36+
echo ""
37+
echo "✅ Linting passed!"
38+
exit 0

.github/workflows/release.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ jobs:
2727
- name: Generate changelog
2828
id: changelog
2929
run: |
30-
PREV_TAG=$(git describe --tags --abbrev=0 ${{ github.ref }}^ 2>/dev/null || echo "")
30+
set -e
31+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
3132
if [ -z "$PREV_TAG" ]; then
32-
CHANGELOG=$(git log --pretty=format:"- %s" ${{ github.ref }})
33+
CHANGELOG=$(git log --pretty=format:"- %s" ${{ github.ref_name }})
3334
else
34-
CHANGELOG=$(git log --pretty=format:"- %s" $PREV_TAG..${{ github.ref }})
35+
CHANGELOG=$(git log --pretty=format:"- %s" $PREV_TAG..${{ github.ref_name }})
3536
fi
3637
CHANGELOG=$(echo "$CHANGELOG" | grep -vE "^(chore|ci|docs):" || echo "- Initial release")
3738
echo "changelog<<EOF" >> $GITHUB_OUTPUT
@@ -71,6 +72,7 @@ jobs:
7172
7273
- name: Build
7374
run: |
75+
set -e
7476
python3 -m venv --system-site-packages venv
7577
. venv/bin/activate
7678
pip install -U pip Nuitka==2.6.9 ordered-set==4.1.0 zstandard==0.23.0
@@ -100,6 +102,7 @@ jobs:
100102

101103
- name: Install AppImage tools
102104
run: |
105+
set -e
103106
sudo apt-get update
104107
sudo apt-get install -y \
105108
libfuse2 wget patchelf desktop-file-utils
@@ -111,6 +114,7 @@ jobs:
111114
112115
- name: Prepare AppDir
113116
run: |
117+
set -e
114118
mkdir -p AppDir/usr/bin
115119
mv dist/clipse-gui-v${{ needs.generate-changelog.outputs.version }}-linux-x86_64 \
116120
AppDir/usr/bin/clipse-gui
@@ -136,6 +140,7 @@ jobs:
136140
137141
- name: Build AppImage
138142
run: |
143+
set -e
139144
export ARCH=x86_64
140145
./linuxdeploy-x86_64.AppImage \
141146
--appdir AppDir \
@@ -163,9 +168,11 @@ jobs:
163168

164169
- name: Build in ARM64 container
165170
run: |
171+
set -e
166172
docker run --rm --platform linux/arm64 \
167173
-v ${{ github.workspace }}:/workspace \
168174
-w /workspace arm64v8/ubuntu:22.04 bash -c "
175+
set -e
169176
apt-get update &&
170177
apt-get install -y python3 python3-pip python3-venv python3-dev \
171178
python3-gi python3-gi-cairo gir1.2-gtk-3.0 \
@@ -207,8 +214,9 @@ jobs:
207214

208215
- name: Build
209216
run: |
210-
pip install pyinstaller pillow
211-
pyinstaller --onefile \
217+
set -e
218+
python -m pip install pyinstaller pillow
219+
python -m PyInstaller --onefile \
212220
--name clipse-gui-v${{ needs.generate-changelog.outputs.version }}-macos-${{ matrix.arch }} \
213221
--hidden-import=gi \
214222
--collect-all gi \
@@ -236,7 +244,7 @@ jobs:
236244

237245
- uses: softprops/action-gh-release@v2
238246
with:
239-
tag_name: ${{ github.ref }}
247+
tag_name: ${{ github.ref_name }}
240248
name: "Release v${{ needs.generate-changelog.outputs.version }}"
241249
body: ${{ needs.generate-changelog.outputs.release_body }}
242250
files: |

Makefile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ NUITKA_OPTS := \
3939

4040
help:
4141
@echo "Available targets:"
42-
@echo " run - Run the Clipse GUI from source"
43-
@echo " lint - Run linting and type checking"
44-
@echo " nuitka - Build a standalone binary using Nuitka"
45-
@echo " install - Install built binary and assets system-wide"
46-
@echo " uninstall - Uninstall the application"
47-
@echo " clean - Clean build and temp files"
48-
@echo " bump - Interactively bump version (major/minor/patch)"
42+
@echo " run - Run the Clipse GUI from source"
43+
@echo " lint - Run linting and type checking"
44+
@echo " install-hooks - Install git pre-commit hook for linting"
45+
@echo " nuitka - Build a standalone binary using Nuitka"
46+
@echo " install - Install built binary and assets system-wide"
47+
@echo " uninstall - Uninstall the application"
48+
@echo " clean - Clean build and temp files"
49+
@echo " bump - Interactively bump version (major/minor/patch)"
4950

5051
run:
5152
@echo "Running Clipse GUI..."
@@ -134,3 +135,9 @@ bump:
134135
@echo "Bumping version..."
135136
@$(PYTHON) bump_version.py
136137

138+
install-hooks:
139+
@echo "Installing git hooks..."
140+
@cp .githooks/pre-commit .git/hooks/pre-commit
141+
@chmod +x .git/hooks/pre-commit
142+
@echo "Pre-commit hook installed successfully!"
143+

clipse_gui/controller.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
show_help_window,
3333
show_preview_window,
3434
show_settings_window,
35-
create_pin_icon,
3635
animate_pin_shake,
3736
)
3837
from .ui_builder import build_main_window_content

clipse_gui/tray_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _setup_status_icon(self):
7474
self.status_icon.connect("activate", self._on_tray_activate)
7575
self.status_icon.connect("popup-menu", self._on_tray_popup_menu)
7676
self.status_icon.set_visible(False)
77-
except Exception as e:
77+
except Exception:
7878
self.status_icon = None
7979

8080
def _create_basic_menu(self):
@@ -109,7 +109,7 @@ def _update_menu_with_items(self):
109109
and hasattr(self.application.controller, "data_manager")
110110
):
111111
items = self.application.controller.data_manager.load_history()
112-
except:
112+
except Exception:
113113
pass
114114

115115
recent_items = items[:5] if items else []
@@ -171,7 +171,7 @@ def _add_item_to_menu(self, item, index):
171171
)
172172
menu_item.show()
173173
self.menu.append(menu_item)
174-
except:
174+
except Exception:
175175
pass
176176

177177
def _copy_item_to_clipboard(self, item):
@@ -187,7 +187,7 @@ def _copy_item_to_clipboard(self, item):
187187
controller.copy_image_to_clipboard(file_path)
188188
else:
189189
controller.copy_text_to_clipboard(value)
190-
except:
190+
except Exception:
191191
pass
192192

193193
def _on_tray_activate(self, status_icon):

clipse_gui/ui_components.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
import os
22
import json
33
import logging
4-
from io import BytesIO
54
from gi.repository import Gtk, Gdk, Pango, GdkPixbuf, GLib
65

76
from .utils import format_date
7+
from .constants import (
8+
LIST_ITEM_IMAGE_WIDTH,
9+
LIST_ITEM_IMAGE_HEIGHT,
10+
DEFAULT_PREVIEW_TEXT_WIDTH,
11+
DEFAULT_PREVIEW_TEXT_HEIGHT,
12+
DEFAULT_PREVIEW_IMG_WIDTH,
13+
DEFAULT_PREVIEW_IMG_HEIGHT,
14+
DEFAULT_HELP_WIDTH,
15+
DEFAULT_HELP_HEIGHT,
16+
PROTECT_PINNED_ITEMS,
17+
COMPACT_MODE,
18+
HOVER_TO_SELECT,
19+
ENTER_TO_PASTE,
20+
MINIMIZE_TO_TRAY,
21+
config,
22+
)
23+
24+
log = logging.getLogger(__name__)
825

926
# SVG icon data for pushpin (rotated 25 degrees to the right for a natural look)
1027
PIN_SVG_BASE = """<?xml version="1.0" encoding="UTF-8"?>
@@ -77,24 +94,6 @@ def apply_wiggle(index):
7794

7895
apply_wiggle(0)
7996

80-
log = logging.getLogger(__name__)
81-
from .constants import (
82-
LIST_ITEM_IMAGE_WIDTH,
83-
LIST_ITEM_IMAGE_HEIGHT,
84-
DEFAULT_PREVIEW_TEXT_WIDTH,
85-
DEFAULT_PREVIEW_TEXT_HEIGHT,
86-
DEFAULT_PREVIEW_IMG_WIDTH,
87-
DEFAULT_PREVIEW_IMG_HEIGHT,
88-
DEFAULT_HELP_WIDTH,
89-
DEFAULT_HELP_HEIGHT,
90-
PROTECT_PINNED_ITEMS,
91-
COMPACT_MODE,
92-
HOVER_TO_SELECT,
93-
ENTER_TO_PASTE,
94-
MINIMIZE_TO_TRAY,
95-
config,
96-
)
97-
9897

9998
def create_list_row_widget(
10099
item_info,

0 commit comments

Comments
 (0)