-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pre-commit: Always run qmlformat and require to skip the hook if needed
- Loading branch information
Showing
2 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |