-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pre-commit: Use qmlformat by default #3923
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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()) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we return exit code 1 so that the user is prompted to either install qmlformat or skip the hook manually.
We could also return exit code 0. Thdi would be even more convenient, but then the hook shows up as "passed" and the user has no way of knowing if qmlformat actually ran or not. This is an issue, especially on CI. Therefore, I prefer the "skip manually" approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can imagine that it can leads to extra hassle when resolving conflicts, because it does not run on diffs only.
So I would prefer exit code 0 version, since it will be visible in our CI anyway.
That follows the approach that the whole pre-commit is optional anyway. Compared to that. this is one only a side issue, where we should not annoy a contributor that has just decided to install pre-commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot be sure about that. It will display as
passed
on CI in any case, even if your CI image does not actually have qmlformat.I think the extra hassle is manageable. Just run this once:
And don't forget remove it after upgrading to Qt 5.15 ;-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ok. Ready to merge IMHO.
Just an idea, considering that we should not forget this .profile value.
How about use:
qmake --version
To exit 0 if qmlformat cannot be installed.