Documentation
How it works
src/lupa.py is a single-file Gtk.Application with the application id
com.dcotecnologia.Lupa. GTK registers that id on the session D-Bus, so a second
run of the command does not start a new process: it triggers activate in the running
one, which toggles the window. That is why one global shortcut can both open and close it.
The window is built once and hidden/shown afterwards, which keeps opening instant.
Search pipeline
Typing is debounced by 80 ms, then refresh() builds a list of Result objects
(title, subtitle, icon, action) in this order:
- Calculator (
calc): the text is parsed withastand evaluated by a whitelist evaluator. Only numbers,+ - * / % // **, unary signs,pi,eand the one-argument math functions are allowed; exponents above 1000 are rejected. Nothing is passed toeval. - Applications (
search_apps):Gio.AppInfo.get_all(), skipping hidden entries. Ranked: name prefix, name substring, then generic name or keywords. Max 8. - Files (
search_files):plocate -i -blimited to 40 hits, filtered to paths under$HOMEwithout hidden components, first 5 shown. Needs 3+ characters. - Web (
WEBconstant): always the last row.
Selecting a row runs its action after hiding the window.
Configuration
There is no config file; edit the constants at the top of src/lupa.py and rerun
./install.sh:
| Constant | Meaning |
|---|---|
WEB |
Search URL prefix (default Google; try https://duckduckgo.com/?q=) |
MAX_ROWS |
Max application rows |
CSS |
Colors, radius, font sizes |
The install script
install.sh is POSIX sh, so it works piped from the web (curl ... | sh) and from a checkout.
- Where the files come from. Next to
src/lupa.py(a checkout) it installs that file. Anywhere else it readsreleases/latest(orreleases/tags/vX.Y.Zwith--version) from the GitHub API, downloadslupa-X.Y.Z.tar.gz, and checks its sha256 against the digest GitHub publishes for the asset, or against theSHA256SUMSfile of the release. No checksum means no install. Plainhttpis accepted only for localhost, for the tests. - Install and update are the same command. It copies the script to
~/.local/bin/lupa(or--prefix) and says whether it installed, updated, or found the same file already there. - Shortcut. On Cinnamon it registers a custom keybinding named
lupathroughgsettings(org.cinnamon.desktop.keybindings) and removes<Super>spacefromwm switch-input-source, because Cinnamon binds it to layout switching by default.--no-shortcutskips this. - Dependencies. It checks that
/usr/bin/python3can import GTK 3 and warns whenplocateis missing.
uninstall.sh reverses all of it and resets that key to its default.
tests/test_install_script.py runs the script against a fake GitHub API on localhost.
Troubleshooting
| Symptom | Fix |
|---|---|
| Shortcut does nothing | Run the command in a terminal to see errors. Check no other app grabs Super+Space. Re-login or cinnamon --replace &. |
No module named 'gi' |
Install python3-gi gir1.2-gtk-3.0. The launcher must use /usr/bin/python3, not a virtualenv. |
| No file results | Install plocate, run sudo updatedb. Only files under $HOME are shown. |
| Opaque, boxy window | No compositor / RGBA visual; the launcher still works. |
| Window does not take focus | Press the shortcut again; some X11 setups restrict focus stealing. |
| Can’t switch keyboard layout anymore | Set another combo in Settings → Keyboard → Layouts, or run ./uninstall.sh. |
Limitations
Linux with X11 is the tested target. GTK3 on Wayland does not allow global placement or guaranteed focus. The global shortcut is only automated for Cinnamon.
Development
/usr/bin/python3 src/lupa.py # run from the checkout
/usr/bin/python3 -I -c "import importlib.util as u; s=u.spec_from_file_location('sp','src/lupa.py'); m=u.module_from_spec(s); s.loader.exec_module(m); print(m.calc('2*(3+4)'))"
The second command exercises the pure logic (calculator, search) without opening a window.
Tests and linting
The project uses uv. PyGObject comes from the system, so the
virtual environment must see the system packages; make sync does that.
make sync # venv with system site packages + dev dependencies
make test # pytest, 100% coverage required
make lint # pre-commit on all files (ruff, yamllint, gitleaks, actionlint, ...)
The window class (Launcher) needs a display and is excluded from coverage; check it by
hand by running src/lupa.py. Everything it calls is unit tested.
Install the git hook once with uv run pre-commit install.
Releases
Commits follow Conventional Commits. To release:
- Move the
[Unreleased]notes ofCHANGELOG.mdunder a new## [X.Y.Z] - dateheading and bumpversioninpyproject.toml(thenuv lock). - Merge to
main, then push the tag:git tag vX.Y.Z && git push origin vX.Y.Z.
The Release workflow runs the tests, checks that the tag matches pyproject.toml, validates
the changelog, and publishes a GitHub release with the changelog section as its notes, a
source tarball and its SHA256SUMS. A tag with a dash (v0.2.0-rc1) is a pre-release.