Skip to content

Commit

Permalink
Merge pull request #3923 from Holzhaus/qmlformat-by-default
Browse files Browse the repository at this point in the history
pre-commit: Use qmlformat by default
  • Loading branch information
daschuer committed May 30, 2021
2 parents f4ce320 + afea7ce commit 27d2029
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,16 @@ jobs:
# on Pull Requests!).
env:
SKIP: end-of-file-fixer,trailing-whitespace,clang-format,eslint,no-commit-to-branch
with:
# Enable extra hooks that require special system dependencies that we
# cannot expect to be installed on all contributor's systems.
extra_args: --hook-stage manual --all-files

- name: "Detect code style issues (pull_request)"
uses: pre-commit/action@v2.0.0
if: github.event_name == 'pull_request'
env:
SKIP: no-commit-to-branch
with:
# Enable extra hooks that require special system dependencies that are
# available in our custom docker container, but cannot be expected to
# be installed on all contributor's systems.
#
# HEAD is the not yet integrated PR merge commit +refs/pull/xxxx/merge
# HEAD^1 is the PR target branch and HEAD^2 is the HEAD of the source branch
extra_args: --hook-stage manual --from-ref HEAD^1 --to-ref HEAD
extra_args: --from-ref HEAD^1 --to-ref HEAD

- name: "Generate patch file"
if: failure()
Expand Down
7 changes: 1 addition & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,11 @@ repos:
- manual
- id: qmlformat
name: qmlformat
entry: qmlformat -i
entry: tools/qmlformat.py
pass_filenames: true
require_serial: true
language: system
types: [text]
files: ^.*\.qml$
# Not enabled in commit stage by default, because qmlformat requires Qt
# 5.15 to be installed
stages:
- manual
- id: qmllint
name: qmllint
entry: qmllint
Expand Down
37 changes: 37 additions & 0 deletions tools/qmlformat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
"""
Small qmlformat wrapper that warns the user if the tool is not installed.
"""
import argparse
import shutil
import subprocess
import pathlib
import sys

QMLFORMAT_MISSING_MESSAGE = """
qmlformat is not installed. It is included in Qt 5.15 and later. If that Qt
version is not available on your system, please use the SKIP environment
variable when committing:
$ SKIP=qmlformat git commit
"""


def main(argv=None):
qmlformat_executable = shutil.which("qmlformat")
if not qmlformat_executable:
print(QMLFORMAT_MISSING_MESSAGE.strip(), file=sys.stderr)
return 1

parser = argparse.ArgumentParser()
parser.add_argument("file", nargs="+", type=pathlib.Path)
args = parser.parse_args(argv)

for filename in args.file:
subprocess.call((qmlformat_executable, "-i", filename))

return 0


if __name__ == "__main__":
sys.exit(main())

0 comments on commit 27d2029

Please sign in to comment.