Skip to content

STY: clang-format repo #5

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Apr 26, 2025
Merged

STY: clang-format repo #5

merged 4 commits into from
Apr 26, 2025

Conversation

lucascolley
Copy link
Member

@lucascolley
Copy link
Member Author

@steppi I know there are more important things for you to prioritise, but it would be great if you could check whether any of the formatting configuration looks unacceptably bad here. I think that even getting a non-ideal configuration merged is a big step up from having none at all, as that will allow us to enforce it in CI and make all future formatting automatic.

@lucascolley
Copy link
Member Author

the diff is scarily large just due to amos.h, specfun.h, and faddeeva.h using different indentation to the rest of the codebase

.clang-format Outdated
ColumnLimit: 120
InsertNewlineAtEOF: true
AlignAfterOpenBracket: BlockIndent
IncludeBlocks: Preserve
AllowShortFunctionsOnASingleLine: None
Copy link
Collaborator

@steppi steppi Apr 25, 2025

Choose a reason for hiding this comment

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

I seem to remember that @izaid deliberately chose a style where short functions could be on a single line. Is there a reason we are changing this now? It mostly effects wrappers like those appearing in config.h.

Copy link
Member Author

Choose a reason for hiding this comment

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

If I remember correctly, this came from discussions with @fancidev on the superseded PR to SciPy. It was a while ago, though, so not sure

Copy link
Member Author

@lucascolley lucascolley Apr 25, 2025

Choose a reason for hiding this comment

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

you can take a look at it without adding this option now

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. From here, scipy/scipy#21640 (comment), it looks like @fancidev only wanted to avoid having short functions automatically converted to one line, but didn't want existing one line wrappers to become split across multiple lines. That's good, it seems everyone is actually in agreement about not including AllowShortFunctionsOnASingleLine: None. I didn't want to change something that @izaid had explicitly chosen during a period of time where he doesn't have time to participate in discussions.

Comment on lines +104 to +107
int acai(std::complex<double>, double, int, int, int, std::complex<double> *, double, double, double, double);
int
acon(std::complex<double>, double, int, int, int, std::complex<double> *, double, double, double, double, double);
int asyi(std::complex<double>, double, int, int, std::complex<double> *, double, double, double, double);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems a little noisy that clang-format will sometimes put the return type on the previous line and sometimes on the same line, in order to keep from exceeding the max column width. I think we should just pick one style and be consistent. Can you see how it looks after setting BreakAfterReturnType in .clang-format to None?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh, that didn't work though. There's still a mix.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, None is deprecated, and now it does something called Automatic that sometimes does and sometimes doesn't break depending on a penalty calculation. I don't want to fight clang-format so let's just take out BreakAfterReturnType.

@lucascolley
Copy link
Member Author

if you would like to test other config options locally, you can do so with pixi run format

@steppi
Copy link
Collaborator

steppi commented Apr 26, 2025

I made a final update to the clang-format config, cleaned up history with an interactive rebase, and added a commit to add the clang-format commit to .git-blame-ignore-revs main...steppi:xsf:format.
If everything is in order, I plan to force push to this branch and merge this.

@steppi steppi marked this pull request as ready for review April 26, 2025 00:33
Copy link
Collaborator

@steppi steppi left a comment

Choose a reason for hiding this comment

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

I think it's good enough. Let's ship it.

@steppi steppi merged commit 4efe236 into scipy:main Apr 26, 2025
2 of 3 checks passed
@lucascolley lucascolley deleted the format branch April 26, 2025 06:08
@lucascolley
Copy link
Member Author

thanks Albert! Now lets get the submodule PR in before cherry-picking becomes a nightmare 😅

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants