Skip to content
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: Add hooks for qmllint and qmlformat #3915

Merged
merged 3 commits into from
May 26, 2021

Conversation

Holzhaus
Copy link
Member

@Holzhaus Holzhaus commented May 26, 2021

This adds the qmllint and qmlformat hooks to ensure our QML files are up to par.

Unfortunately, qmlformat is only part of Qt 5.15 and later. Therefore, we cannot expect our contributors to have it installed. Since it's a binary dependencies (i.e. not a python/npm package), we also can't provide convenient automatic installation.

Therefore, the qmlformat hook is restricted to the manual hook stage. This means that it's not run automatically when committing, only when you run:

$ pre-commit run qmlformat --hook-stage manual --all-files

Not great and easy to forget, but we can let our pre-commit CI workflow assist us in noticing issues during PR review. However, this requires that our CI has Qt 5.15 available, which isn't the case with the current ubuntu-latest image.

Hence, I wrote a small Dockerfile based on Arch Linux and uploaded the image to DockerHub, so that we can use it in our pre-commit workflow.

TL;DR: With this PR, QML formatting issues can be detected early on CI without requiring all contributors to install Qt 5.15 or later.

@poelzi
Copy link
Contributor

poelzi commented May 26, 2021

What shall I say, that is why nix is superiour and does not require such hacks....

@Holzhaus
Copy link
Member Author

What shall I say, that is why nix is superiour and does not require such hacks....

We cannot force our contributors to use a particular OS (= one with a non-outdated Qt version), or set up nix or docker, or build Qt5 themselves locally.

I have no problems on my machine, as I use Qt 5.15 for quite some time from my distros official repos. The whole "hack" has only been added for people on outdated distros.

@uklotzde
Copy link
Contributor

What shall I say, that is why nix is superiour and does not require such hacks....

Please stay on topic. We don't need to fuel the Linux distro wars. Let's just work together to keep Mixxx platform-independent. Thank you.

@uklotzde
Copy link
Contributor

Shall we add the corresponding Dockerfile to our repo, e.g. in tools/ci? The purpose of this Dockerfile and how it is supposed to be used could be added as a comment, everything self-contained.

@poelzi
Copy link
Contributor

poelzi commented May 26, 2021

Please stay on topic. We don't need to fuel the Linux distro wars. Let's just work together to keep Mixxx platform-independent. Thank you.

nix is not a linux distribution, nix is a package manager that does things correct, is not invasive and actually collects it's garbage.
NixOS is a distribution based on nix. I have collegues that use MacOS, some use ubuntu, I use NixOS. We all work with the same nix expressions to build, develop and test with CI.

I made a technical comment because I think this is wrong. Now we have to maintain even more distribution specific stuff, regullarly build docker containers, push those etc, who takes care about that, are those containers CI built ?
Those are the points you complained about...

@Holzhaus
Copy link
Member Author

Now we have to maintain even more distribution specific stuff, regullarly build docker containers, push those etc, who takes care about that, are those containers CI built ?

We don't have to rebuild them unless we want to use a more recent Qt/clang-format version.
The container shouldn't magically break or something.

It's fine that you're passionate about nix, but do you really suggest to required setting up nix in order to contribute to Mixxx? Because I don't see another way to get around this if we don't want this "hack".

@Holzhaus
Copy link
Member Author

Comments added.

@Holzhaus Holzhaus requested a review from uklotzde May 26, 2021 21:04
Copy link
Contributor

@uklotzde uklotzde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! LGTM

@uklotzde uklotzde merged commit fa721b1 into mixxxdj:main May 26, 2021
types: [text]
files: ^.*\.qml$
# Not enabled in commit stage by default, because qmlformat requires Qt
# 5.15 to be installed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just add a wrapper script that calls qmlformat if it exists or print a message "qmlformat is not installed, skipping qmlformat".
I will never remember running this with manual arguments

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will notice when it runs on CI at least. I thought about that as well, but thr problem is that the hook will always pass in that case, and you don't really know it it actually passed or if the tool was just not found.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative would be to not make any special workarounds. The hook will only run if you changed QML files anyway. If you really want to change QML files with qml format installed just skip the hook with SKIP=qmlformat git commit

That would also be an option. @poelzi @uklotzde what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants