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

Introduce pre-commit hooks #310

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

Radonirinaunimi
Copy link
Member

@Radonirinaunimi Radonirinaunimi commented Sep 18, 2024

My initial idea was to introduce pre-commit hooks to lint and format the python files, but then I stumbled upon #180 and decided to introduce some minimal hooks for Rust and all the other files.

The configuration is kept to be very minimal in order to only perform the most necessary steps before pushing commits.

Left to do:

  • fixing pineappl_cli/src/plot.py

@Radonirinaunimi Radonirinaunimi added the enhancement New feature or request label Sep 18, 2024
@Radonirinaunimi Radonirinaunimi linked an issue Sep 18, 2024 that may be closed by this pull request
language: system
files: ^pineappl\S*\/.*\.rs$
args: []
- id: check
Copy link
Contributor

Choose a reason for hiding this comment

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

In eko we have cargo clippy but not cargo check - which one is better? will either fmt or clippy run check along the way?

Copy link
Member

Choose a reason for hiding this comment

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

They are different: cargo check is essentially running the compiler, without generating code. cargo clippy is statically analyzing the code (i.e. the equivalent of Pylint).

There is a non-negligible change that cargo clippy is a superset of cargo check, but it's also possible that they only partially overlap. But this you can search for (or even try: run cargo clippy on something that cargo check was flagging, and see if it's complaining - even a missing ; or unmatched {).
The opposite is definitely impossible: cargo clippy may do strictly more, but certainly not strictly less.

Copy link
Member Author

Choose a reason for hiding this comment

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

They are different: cargo check is essentially running the compiler, without generating code. cargo clippy is statically analyzing the code (i.e. the equivalent of Pylint).

Yes, exactly. I did not include clippy before because it is very noisy but there is actually some ways to suppress warnings and only show errors.

Copy link
Member

Choose a reason for hiding this comment

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

Well: that's certainly an option, but another one is just implementing its suggestions :P

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree! I will address this soon #314 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

In MaunaKea I also have clang-format https://github.com/felixhekhorn/MaunaKea/blob/d857a363719a9e6f579f156948b483e4cbde3976/.pre-commit-config.yaml#L13

I also have cpplint but that is maybe not installed by default, unlike clang-format which might be available on most systems ...

Copy link
Contributor

@felixhekhorn felixhekhorn left a comment

Choose a reason for hiding this comment

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

I like it if someone else is doing the trivial stuff for me 🙃

@alecandido
Copy link
Member

I like it if someone else is doing the trivial stuff for me 🙃

If it's trivial, it would take no time to you as well :P

I.e. use the word trivial with a large amount of caution

@Radonirinaunimi
Copy link
Member Author

It seems trivial indeed but I had to fight with python files which do not actually contain "python codes" (which in the end is time-consuming) 😇.

Btw, @cschwan, is there a reason why pineappl_cli/src/plot.py can't just be modified into plot.txt or something?

@felixhekhorn
Copy link
Contributor

Btw, @cschwan, is there a reason why pineappl_cli/src/plot.py can't just be modified into plot.txt or something?

for sure we want the Python syntax highlight, because it is almost a Python file (so I'd prefer the .py).

However, I would much prefer making this a true Python script as discussed in #249 and split the static stuff in a true Python file and then all the dynamic stuff can either be inlined (in Rust) or could then go to a config_plot.py.txt

@cschwan
Copy link
Contributor

cschwan commented Sep 19, 2024

I thought about improving the plot script, but it didn't go anywhere. You're welcome to try to improve it yourself. The only conditions for improving it are:

  1. the only dependencies you can rely on are: numpy, matplotlib and the ones already provided by Python.
  2. everything has to be in one self-contained file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more examples to run on CI Add pre-commit?
4 participants