[MERGED] Pre-commit hooks

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
agren
Posts: 40
Joined: Sat Apr 20, 2019 7:37 am

Re: Pre-commit hooks

Post by agren »

chennes wrote: Wed Mar 29, 2023 1:39 pm I had thought that by using a pip-installed version we could all use the latest, but the important thing is that especially for clang-format we have to pick a version, and then make our .clang-format file work with that version. For Black it's much less important because Black doesn't really have any options (that's its whole point).
I believe it is still important enough that everyone uses the same Black major version. There are almost no options, but the formatting rules might change between 21.x, 22.x, 23.x and so on.
Imagine a scenario where one pull request contain one line of behavior change. But 100 lines of code formatting changes.
It would also make compliance checks possible in the CI, if that's something that is planned.

Quote from the Black stability policy:
If code has been formatted with Black, it will remain unchanged when formatted with the same options using any other release in the same calendar year.
...
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Pre-commit hooks

Post by chennes »

I have proposed that we use Black 22 and clang-format 15 in the actual YAML file (technically 22.10.0 and 15.0.7).
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Pre-commit hooks

Post by wmayer »

Once the maintainers prepare their modules then issue #5578 should be done, too.
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Pre-commit hooks

Post by chennes »

Black only normalizes line endings on a per-file basis. Do you want to add a hook to force Unix endings?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Pre-commit hooks

Post by wmayer »

Well, many lint warnings are about that.
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Pre-commit hooks

Post by chennes »

I'm happy to add it. If you can think of other formatting things want added right away let me know. I was thinking in the long-term it would be nice to write our own hook that checks the license of FCStd files that are getting committed.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: [MERGED] Pre-commit hooks

Post by chennes »

OK, I merged the PR with our pre-commit configuration file. It's now up to individual developers to enable it. Instructions are available in our new Developer's Handbook: https://github.com/FreeCAD/DevelopersHa ... evelopment
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [MERGED] Pre-commit hooks

Post by openBrain »

chennes wrote: Mon Apr 03, 2023 6:20 pm OK, I merged the PR with our pre-commit configuration file. It's now up to individual developers to enable it. Instructions are available in our new Developer's Handbook: https://github.com/FreeCAD/DevelopersHa ... evelopment
Do you think that on Debian/Ubuntu, it works as well to install with `apt install pre-commit` ?
Generally better use the package manager than pip. :)
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: [MERGED] Pre-commit hooks

Post by chennes »

Yes, most likely. The pre-commit docs themselves say to use pip so I was really just copying that. Feel free to submit a PR 8-) .
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: [MERGED] Pre-commit hooks

Post by bernd »

black on FEM Python code viewtopic.php?t=77747
Post Reply