From d33803333388dc91627af88417fbcad31faa27b4 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 13 Nov 2025 16:26:35 +1100 Subject: [PATCH] Add version info. Add linter --- .forgejo/workflows/lint.yml | 25 +++++++++++++++++++++++++ CHANGELOG.md | 1 + bouquin/locales/en.json | 1 + bouquin/locales/fr.json | 1 + bouquin/main_window.py | 12 ++++++++++++ bouquin/strings.py | 1 + tests/test_main_window.py | 26 ++++++++++++++++++++++++++ 7 files changed, 67 insertions(+) create mode 100644 .forgejo/workflows/lint.yml diff --git a/.forgejo/workflows/lint.yml b/.forgejo/workflows/lint.yml new file mode 100644 index 0000000..c7ad092 --- /dev/null +++ b/.forgejo/workflows/lint.yml @@ -0,0 +1,25 @@ +name: Lint + +on: + push: + +jobs: + test: + runs-on: docker + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install system dependencies + run: | + apt-get update + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + black pyflakes3 + + - name: Run linters + run: | + black bouquin/* + black tests/* + pyflakes3 bouquin/* + pyflakes3 tests/* diff --git a/CHANGELOG.md b/CHANGELOG.md index cde5185..dab732b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Fix a few small matters identified with tests * Make locales dynamically detected from the locales dir rather than hardcoded + * Add version information in the navigation # 0.2.1.8 diff --git a/bouquin/locales/en.json b/bouquin/locales/en.json index f924559..dfae41c 100644 --- a/bouquin/locales/en.json +++ b/bouquin/locales/en.json @@ -59,6 +59,7 @@ "documentation": "Documentation", "couldnt_open": "Couldn't open", "report_a_bug": "Report a bug", + "version": "Version", "navigate": "Navigate", "current": "current", "selected": "selected", diff --git a/bouquin/locales/fr.json b/bouquin/locales/fr.json index 49fde4f..427ce2a 100644 --- a/bouquin/locales/fr.json +++ b/bouquin/locales/fr.json @@ -59,6 +59,7 @@ "documentation": "Documentation", "couldnt_open": "Impossible d’ouvrir", "report_a_bug": "Signaler un bug", + "version": "Version", "navigate": "Naviguer", "current": "actuel", "selected": "sélectionné", diff --git a/bouquin/main_window.py b/bouquin/main_window.py index abaf495..578852f 100644 --- a/bouquin/main_window.py +++ b/bouquin/main_window.py @@ -1,6 +1,7 @@ from __future__ import annotations import datetime +import importlib.metadata import os import sys import re @@ -263,6 +264,12 @@ class MainWindow(QMainWindow): act_bugs.triggered.connect(self._open_bugs) help_menu.addAction(act_bugs) self.addAction(act_bugs) + act_version = QAction(strings._("version"), self) + act_version.setShortcut("Ctrl+V") + act_version.setShortcutContext(Qt.ApplicationShortcut) + act_version.triggered.connect(self._open_version) + help_menu.addAction(act_version) + self.addAction(act_version) # Autosave self._dirty = False @@ -1177,6 +1184,11 @@ class MainWindow(QMainWindow): strings._("couldnt_open") + url.toDisplayString(), ) + def _open_version(self): + version = importlib.metadata.version("bouquin") + version_formatted = f"{APP_NAME} {version}" + QMessageBox.information(self, strings._("version"), version_formatted) + # ----------------- Idle handlers ----------------- # def _apply_idle_minutes(self, minutes: int): minutes = max(0, int(minutes)) diff --git a/bouquin/strings.py b/bouquin/strings.py index 322739c..eff0e18 100644 --- a/bouquin/strings.py +++ b/bouquin/strings.py @@ -14,6 +14,7 @@ _DEFAULT = "en" strings = {} translations = {} + def load_strings(current_locale: str) -> None: global strings, translations translations = {} diff --git a/tests/test_main_window.py b/tests/test_main_window.py index b266ffc..0dabc89 100644 --- a/tests/test_main_window.py +++ b/tests/test_main_window.py @@ -1,4 +1,6 @@ import pytest +import importlib.metadata + from pathlib import Path import bouquin.main_window as mwmod @@ -906,9 +908,33 @@ def test_open_docs_and_bugs_show_warning_on_failure( ) w._open_docs() w._open_bugs() + assert seen["docs"] and seen["bugs"] +def test_open_version(qtbot, tmp_db_cfg, app, monkeypatch): + w = _make_main_window(tmp_db_cfg, app, monkeypatch) + qtbot.addWidget(w) + + called = {"title": None, "text": None} + + def fake_information(parent, title, text, *a, **k): + called["title"] = title + called["text"] = text + # Return value of QMessageBox.information is an int; 0 is fine. + return 0 + + # Patch whichever one you actually use in _open_version + monkeypatch.setattr(QMessageBox, "information", fake_information) + + w._open_version() + + assert called["title"] is not None + assert "version" in called["title"].lower() + version = importlib.metadata.version("bouquin") + assert version in called["text"] + + # ---- Idle/lock/event filter helpers (1176, 1181-1187, 1193-1202, 1231-1233) ----