/pyuic-pre-commit

A pre-commit hook to run PyQt/PySide's uic tool and ensure generated Python files are up-to-date with their corresponding .ui files.

Primary LanguagePythonMIT LicenseMIT

pyuic-pre-commit

A pre-commit hook to run PyQt/PySide's pyuic tool and ensure generated Python files are up-to-date with their .ui files.

Usage

Add the following to your .pre-commit-config.yaml:

- repo: https://github.com/ukaea/pyuic-pre-commit.git
    rev: v0.1.0  # change to your desired version
    hooks:
      - id: check-ui-files
        args: ['--exe-name', 'pyside6-uic']  # optional

You must have a pyuic tool available and on your path. The default pyuic tool is pyside6-uic, but this can be set using the --exe-name argument shown above. For example, if you're using PyQt5:

        args: ['--exe-name', 'pyuic5']

Assumptions

This hook assumes that each .ui and generated Python file pair are located in the same directory and have a consistent naming pattern. The generated Python file must have the same name as the .ui file with a ui_ prefix.

For example, the following is OK:

module/widget.ui -> module/ui_widget.py

But these examples are not:

module/ui/widget.ui -> module/ui_widget.py
module/widget.ui -> module/widget.py

Note: If you have requirements that are not supported by these assumptions, please let the hook authors know and they can try to help.