Skip to main content

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>] [--force-rebuild] [--file-relative-path=<div>]

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)
    --force-rebuild                     Rebuild the stubs from scratch instead of doing a partial update
    --file-relative-path=<div>          Make all paths in generated type files relative to this path
                                            (useful for if the generated stubs need to be used on different systems)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyside6_qml_stubgen-0.1.0a6.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

pyside6_qml_stubgen-0.1.0a6-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file pyside6_qml_stubgen-0.1.0a6.tar.gz.

File metadata

  • Download URL: pyside6_qml_stubgen-0.1.0a6.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pyside6_qml_stubgen-0.1.0a6.tar.gz
Algorithm Hash digest
SHA256 8b028c68c1da5654eb9edfc3778f039316d4dcce2ea313ebcba562e1c258160d
MD5 506c4c332f9d581780e7d65dc0ceaba7
BLAKE2b-256 b70d8229c639339f37890af64b2c1ae28e567bbd1f0545b5b5a4c5281cb4cba1

See more details on using hashes here.

File details

Details for the file pyside6_qml_stubgen-0.1.0a6-py3-none-any.whl.

File metadata

File hashes

Hashes for pyside6_qml_stubgen-0.1.0a6-py3-none-any.whl
Algorithm Hash digest
SHA256 5d11f5f1f579cd5cd15145aba997fbe32392697d44e513967a7c8e2e84d98080
MD5 01c167deaa1192118d4c92a044cf9482
BLAKE2b-256 2a5b8738490f9ac21b1ca7aacabe9e08c5f5dec9f2d6b620b945dc3150fcdfc4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page