-
Notifications
You must be signed in to change notification settings - Fork 35
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
Add C++ code Formatting #420
base: main
Are you sure you want to change the base?
Conversation
…luded within fortran source code
At the last Enzo-E call, it was suggested that I try to format everything and check if it works.
|
pre-commit.ci run EDIT: For posterity, this comment was used to trigger the new pre-commit.ci continutous integration (this was necessary since I introduced precommit.ci after this PR was created and I didn't want to push a new commit) |
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
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.
Why is this file included in this PR at all? it doesn't seem necessary to do it. Is the goal to demonstrate how the formatting tools work, is it some unrelated cleanup work, or was it included by accident?
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.
(@bwoshea I'm guessing this is one of the "I have reformatted a small subset of existing files" mentioned in the PR description.)
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.
Same question as for EnzoComputeCoolingTime.cpp - why is this file included in the PR? (Also, to be clear, I don't see anything wrong with the changes in either of these files, I'm just not clear on why they're included.)
3. the "pre-commit" `git hook <https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks>__`. | ||
This is one of multiple different "hooks" offered by git. | ||
The pre-commit software is named after this hook because it was originally designed to be used with this hook. | ||
While developers are free to use the pre-commit software with the pre-commit hook, that is **NOT** (and is not discussed on this page) |
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.
This is confusing. "that is NOT" what?
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.
this is NOT recommended
(I'll fix that)
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.
Maybe swap the "not recommended" and "recommended" items so the recommended one is first?
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.
This is fixed
I replaced
While developers are free to use the pre-commit software with the pre-commit hook, that is NOT (and is not discussed on this page)"
with
We do NOT generally recommend using the pre-commit software with the pre-commit hook.
@jobordner (I think I effectively addressed your comment here)
As an aside: I don't really care whether people are configuring git's hooks to trigger pre-commit hooks, but I think that is a personal choice after they understand the choice (if people don't understand what they are "signing up for", they will be surprised)
|
||
To run the checks locally, we encourage you need to install the pre-commit software. | ||
This software is written in python and can be installed with ``pip``. | ||
The `installation instructions <https://pre-commit.com/#installation>`__ also mention an alternative approach where you can run download and run pre-commit without fully installing it (as a "zipapp"). |
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.
Are there any known conflicts with the requirements for pre-commit and those of other things Enzo-E developers are likely to use, like yt? (I don't know if that's something that has to be explicitly stated unless there's something that is likely to trip up a lot of developers.)
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 have no idea. I imagine the answer is "no" since yt also uses pre-commit
|
||
* files that are formatted this way will generally have far fewer merge conflicts. | ||
|
||
* Sometimes, you may need to disable clang-format to disable formatting for individual pieces of code. |
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.
Can you comment on why somebody might want to disable clang-format?
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 think I'm just going to remove that bullet. Off the top of my head, I don't really have a good reason.
I'm sure there are good reasons, but there's no need to invite it
* Sometimes, you may need to disable clang-format to disable formatting for individual pieces of code. | ||
You can do that with a pair of special comments, `described here <https://releases.llvm.org/18.1.8/tools/clang/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code>`__. | ||
|
||
* Unless you have a very good reason, [#f1]_ **all** newly introduced C/C++ files will be formatted by ``clang-format``. |
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.
Maybe add something to the effect of "adherence to the formatting guidelines enforced by clang-format is a requirement for acceptance of pull requests, and deviation from that will require you to explicitly justify why your code is not adhering to that format."
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 like this a lot! Here's the replacement text:
Adherence to the formatting guidelines enforced by
clang-format
is a requirement for acceptance of pull requests, and deviation from that will require you to explicitly justify why your code is not adhering to that format. [#f1]_ We have temporarily disabled clang-format from applying to most older files (listed in.clang-format-ignore
), that existed before we adopted clang-format in order to minimize merge conflicts (we plan to enableclang-format
for these files in the future)... [#f1] A scenario where it might be reasonable to disable
clang-format
is for a source code file generated by external tools like flex/bison.
|
||
* Unless you have a very good reason, [#f1]_ **all** newly introduced C/C++ files will be formatted by ``clang-format``. | ||
With that said, we have temporarily disabled clang-format from applying to most older files (listed in ``.clang-format-ignore``, that existed before we adopted clang-format in order to minimize merge conflicts (we plan to enable ``clang-format`` for these files in the future). | ||
We plan to enable formatting on these files in the future. |
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.
This line (148) is redundant with the previous sentence.
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.
Removed!
@mabruzzo I looked at all of the files in this PR and things look just fine. However (as I commented at the top of a couple of the files) it's not clear to me why the files in |
Those files are indeed an example of a formatted version of the code. |
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.
Approving given that @mabruzzo answered my question about the chemistry code. @jobordner needs to look at this next!
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.
Overall looks good, thanks for working on this!
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.
(@bwoshea I'm guessing this is one of the "I have reformatted a small subset of existing files" mentioned in the PR description.)
Pull request summary
This PR adds a support for using
clang-format
with Enzo-E.I have added extensive documentation.
Detailed Description
This is something we spoken at length about in the past and there is consensus enforcing standard formatting for C/C++ code would be beneficial.
I feel like this is something we could delay indefinitely. So I made 2 particular choices to make this easier to merge:
Relationship with
pre-commit
The main challenge of using
clang-format
is that it is not forward/backward compatible (picking an established style should mitigate some of these issues). - In other words, you need to apply a consistent version of clang-format everywhere.SOLUTION: To address this challenge, this PR configures the
pre-commit
software andpre-commit.ci
continuous integration service (introduced in #419) to invokeclang-format
.I implemented a similar solution in Cholla and it works well.
This is a major change or addition (that needs 2 reviewers): unknown
Depends on #419
PR Checklist