diff --git a/.gitignore b/.gitignore index cc5fd82c..0950d03e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ install .venv __pycache__ *.pyc +*.egg-info # IDEs / editors .idea diff --git a/python-aux/README.md b/python-aux/README.md new file mode 100644 index 00000000..7b2d780c --- /dev/null +++ b/python-aux/README.md @@ -0,0 +1,31 @@ +# Python Development Support Files + +This directory contains support files for developing Python demos: + +- `requirements.txt`: + Requirements for development. Contains dependency for `ruff` (linter & formatter), `mypy` (type checker) + and `workbench-typestubs` (typestubs for the `workbench` module). All of these are also installed + in the `re.sonny.Workbench.Devel` Flatpak (TODO: not true yet, see below.) +- `mypy.ini`: + Rules for `mypy` used for all demos. +- `workbench-typestubs`: + Python package containing typestubs for the `workbench` package which is available to demos and + implements the Workbench API. + +## Run type checks. + +```sh +cd python-aux +pip3 install -r requirements.txt +cd .. +# Check single file: +mypy --config-file python-aux/mypy.ini src/Welcome/main.py +# Check all: +mypy --config-file python-aux/mypy.ini src +``` + +## TODO + +TODO: All requirements should be in the Devel Flatpak, but unsure how the +typestub itself could be added there...? We might need to put that in an extra repo and add it +as a module to the Devel Flatpak. Ruff is already in there. diff --git a/python-aux/mypy.ini b/python-aux/mypy.ini new file mode 100644 index 00000000..a47f0f90 --- /dev/null +++ b/python-aux/mypy.ini @@ -0,0 +1,5 @@ +[mypy] +warn_unused_configs = True +explicit_package_bases = True +namespace_packages = True +check_untyped_defs = True diff --git a/python-aux/requirements.txt b/python-aux/requirements.txt new file mode 100644 index 00000000..9eda497e --- /dev/null +++ b/python-aux/requirements.txt @@ -0,0 +1,4 @@ +./workbench-typestubs +ruff>=0.3.0 +pygobject-stubs>=2.11.0 --config-settings=config=Gtk4,Gdk4,GtkSource5 +mypy>=1.9.0 diff --git a/python-aux/workbench-typestubs/MANIFEST.in b/python-aux/workbench-typestubs/MANIFEST.in new file mode 100644 index 00000000..49adbf0c --- /dev/null +++ b/python-aux/workbench-typestubs/MANIFEST.in @@ -0,0 +1,2 @@ +include workbench/py.typed +recursive-include workbench *.pyi diff --git a/python-aux/workbench-typestubs/pyproject.toml b/python-aux/workbench-typestubs/pyproject.toml new file mode 100644 index 00000000..d2f5d48d --- /dev/null +++ b/python-aux/workbench-typestubs/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "workbench-typestubs" +version = "46.0.0" diff --git a/python-aux/workbench-typestubs/workbench/__init__.pyi b/python-aux/workbench-typestubs/workbench/__init__.pyi new file mode 100644 index 00000000..d95e2873 --- /dev/null +++ b/python-aux/workbench-typestubs/workbench/__init__.pyi @@ -0,0 +1,7 @@ +from gi.repository import Gtk, Gio + +window: Gtk.Window +builder: Gtk.Builder + +def resolve(path: str) -> Gio.File: + ... diff --git a/python-aux/workbench-typestubs/workbench/py.typed b/python-aux/workbench-typestubs/workbench/py.typed new file mode 100644 index 00000000..e69de29b diff --git a/src/Welcome/main.py b/src/Welcome/main.py index 9b95a029..de0a792f 100644 --- a/src/Welcome/main.py +++ b/src/Welcome/main.py @@ -1,3 +1,5 @@ +from typing import cast + import gi gi.require_version("Gtk", "4.0") @@ -19,7 +21,7 @@ def dialog_response(dialog, response): dialog.close() -subtitle_box: Gtk.Box = workbench.builder.get_object("subtitle") +subtitle_box = cast(Gtk.Box, workbench.builder.get_object("subtitle")) button = Gtk.Button(label="Press me", margin_top=6, css_classes=["suggested-action"]) button.connect("clicked", greet)