-from gi.repository import Gtk
import os
import subprocess
+from typing import Any
import gi
gi.require_version("Gtk", "4.0")
+from gi.repository import Gtk # nopep8 pylint: disable=wrong-import-position
-def on_edit(_):
+def on_edit(_: Any) -> None:
config_dir = os.path.join(
os.environ.get('XDG_CONFIG_HOME', os.path.expanduser('~/.config')),
'nixpkgs',
os.makedirs(config_dir, exist_ok=True)
config_file = os.path.join(config_dir, 'userPackages.nix')
try:
- with open(config_file, mode="x") as f:
+ with open(config_file, mode="x", encoding='utf-8') as f:
f.write('''final: prev: {
userPackages = final.buildEnv {
name = "userPackages";
subprocess.run(['xdg-open', config_file], check=True)
-def try_exec_terminal(terminal, args):
+def try_exec_terminal(terminal: str, args: list[str]) -> None:
try:
os.execvp(terminal, [terminal] + args)
except FileNotFoundError:
pass
-def on_apply(_):
+def on_apply(_: Any) -> None:
command = ['nix-env', '-riA', 'nixos.userPackages']
command_string = ' '.join(command)
- close_string = ''' && read -p "SUCCESS: Press ENTER to close this window" || read -p "FAILURE: Press ENTER to close this window"'''
+ close_string = (
+ ''' && read -p "SUCCESS: Press ENTER to close this window"''' +
+ ''' || read -p "FAILURE: Press ENTER to close this window"''')
# This should be a simple `xdg-terminal` invocation, but as of 2025,
# xdg-terminal is extremely broken in Gnome:
# * It doesn't cause a terminal window to appear
os.execvp(command[0], command)
-def on_activate(app):
+def on_activate(app: Gtk.Application) -> None:
win = Gtk.ApplicationWindow(application=app)
box = Gtk.Box()
box.set_orientation(Gtk.Orientation.VERTICAL)
win.present()
-def main():
+def main() -> None:
app = Gtk.Application(application_id='net.chkno.nix-env-apps')
app.connect('activate', on_activate)
app.run(None)
-{ pkgs ? import <nixpkgs> { } }:
-pkgs.python3Packages.callPackage ({ buildPythonPackage, gobject-introspection
- , gtk4, lib, pygobject3, wrapGAppsHook4, }:
+{ pkgs ? import <nixpkgs> { }, lint ? false }:
+pkgs.python3Packages.callPackage ({ autopep8, buildPythonPackage
+ , gobject-introspection, gtk4, lib, mypy, pylint, pygobject3, wrapGAppsHook4,
+ }:
buildPythonPackage rec {
pname = "apps";
version = "1.0";
+
src = lib.cleanSource ./.;
- nativeBuildInputs = [ gobject-introspection wrapGAppsHook4 ];
- buildInputs = [ gtk4 ];
+ doCheck = true;
+ checkPhase = "./test.sh";
+ nativeBuildInputs = [ gobject-introspection wrapGAppsHook4 ];
+ nativeCheckInputs = [ mypy ] ++ lib.optionals lint [ autopep8 pylint ];
+ buildInputs = [ gtk4 ];
pythonPath = [ pygobject3 ];
}) { }
--- /dev/null
+#!/usr/bin/env bash
+
+# Copy me to .git/hooks/pre-commit
+
+set -e
+
+cleanup() {
+ if [[ "$D" && -e "$D" ]];then
+ rm -rf "$D"
+ fi
+}
+trap cleanup EXIT
+
+D=$(mktemp -d)
+[[ "$D" && -d "$D" ]]
+
+git checkout-index --prefix="$D/" -a
+pushd "$D"
+
+# So we don't confuse the inner git invocations inside the tests with
+# the outer git invocation that's trying to commit a change.
+unset GIT_AUTHOR_DATE
+unset GIT_AUTHOR_EMAIL
+unset GIT_AUTHOR_NAME
+unset GIT_CONFIG_PARAMETERS
+unset GIT_EXEC_PATH
+unset GIT_INDEX_FILE
+unset GIT_PREFIX
+
+nix-shell --arg lint true --run './test.sh lint'
+
+popd
--- /dev/null
+#!/bin/sh
+
+set -e
+
+find . -name build -prune -o -name dist -prune -o -name '*.py' -print0 |
+ xargs -0 mypy --strict --ignore-missing-imports --no-warn-unused-ignores
+
+if [ "$1" = lint ];then
+
+ find . -name '*.py' -print0 | xargs -0 pylint --reports=n --persistent=n --ignore-imports=y -d fixme,invalid-name,missing-docstring,subprocess-run-check,too-few-public-methods
+
+ formatting_needs_fixing=$(
+ find . -name '*.py' -print0 |
+ xargs -0 -n1 autopep8 --diff -aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ )
+ if [ -n "$formatting_needs_fixing" ];then
+ echo "Formatting needs fixing:"
+ echo "$formatting_needs_fixing"
+ exit 1
+ fi
+
+fi