Generate QML stub files (.qmltypes) from Python modules (which use PySide6)
Project description
pyside6-qml-stubgen
Generate QML stub files (.qmltypes
) from Python modules (which use PySide6)
Installation
This tool can be installed though PyPI:
pip install pyside6-qml-stubgen
If you want to use a development version, instead clone the repo and then install using pip:
git clone https://github.com/matsjoyce/pyside6-qml-stubgen.git
pip install ./pyside6-qml-stubgen
This tool has been tested on Linux, Windows and MacOS using pip-installed PySide6 (on GitHub Actions), and on Arch Linux using system packages. It does not run with PyQt6, although it should be possible in theory (send a PR if you get it working). And finally, it does not run using Qt 5 (PySide2 or PyQt5), as that version is no longer being developed, and QML in Qt 5 has less features than in Qt 6, making it a less attractive target for this sort of tool.
Simple example
As an example, we'll run this tool on https://github.com/matsjoyce/fantasia2. There are two steps to type checking your QML code when using PySide6. First generate the QML type stubs using this tool:
pyside6-qml-stubgen fantasia2 --out-dir qmltypes --ignore fantasia2/alembic/
This command will generate a folder tree containing .qmltypes
files and qmldir
files matching the runtime structure of QML modules registered by the Python modules.
The second step is to run qmllint
on your QML files using the type stubs:
/usr/lib/qt6/bin/qmllint fantasia2/*.qml -I ./qmltypes
If you change the QML files, you can just rerun qmllint
. If you change the Python interface, you should rerun both commands.
Links to other projects
This tool relies heavily on PySide6, and is inspired by the metaobjectdump.py
tool, although this tool uses a runtime approach instead of static analysis, as that works better on large programs.
Command-line arguments
$ pyside6-qml-stubgen --help
Generate QML stub files (.qmltypes) from Python modules (which use PySide6)
Usage:
pyside6-qml-stubgen <in-dir>... --out-dir=<out-dir> [--ignore=<path>...] [--metatypes-dir=<dir>] [--qmltyperegistrar-path=<path>]
Options:
--ignore=<path> Ignore all Python files that are children of thispath
--metatypes-dir=<dir> Directory of the Qt 6 metatype files for core modules (automatically detected if not provided)
--qmltyperegistrar-path=<path> Path of the qmltyperegistrar tool (automatically detected if not provided)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyside6_qml_stubgen-0.1.0a2.tar.gz
.
File metadata
- Download URL: pyside6_qml_stubgen-0.1.0a2.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70b81c5abb7b79298b36aaf143eb126790fa96fe8b1f060e4e3afd60947591b8 |
|
MD5 | 9d85c7952acb37fc8ef6b950a8e17364 |
|
BLAKE2b-256 | 1a20d92e794cb102148d4371e6e1eba60ef0394d213492746b16beca1f8248b7 |
File details
Details for the file pyside6_qml_stubgen-0.1.0a2-py3-none-any.whl
.
File metadata
- Download URL: pyside6_qml_stubgen-0.1.0a2-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d68aa1422f8d5dc7d80e0ab89753817f324f7e36ded6064dd751bba95f083a41 |
|
MD5 | ccbb4214b329b76254dc472e4f9b8bbf |
|
BLAKE2b-256 | 1ca02304e66c8e3df02fff7d7c2596924d2c6bf9c42c97e6f30b54f2580456ad |