Skip to content

Autoformat Python and C code #57

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Xeratec
Copy link
Member

@Xeratec Xeratec commented May 12, 2025

Summary

This PR adds support for automatically formatting C and Python code using standardized formatting tools. This helps ensure consistency and maintainability across the codebase.

Added

  • Autoformatting support for:
    • C code (via clang-format)
    • Python code (via black)
  • Configuration files for clang-format and black
  • Enable formatting check in CI
  • make format target in Makefile

Changed

  • (If applicable) Adjusted existing code to conform with new formatting rules

Notes

  • Make sure to run the formatter on your code before committing with make format

@Xeratec Xeratec requested a review from phsauter May 12, 2025 07:58
@Xeratec Xeratec self-assigned this May 12, 2025
@Xeratec
Copy link
Member Author

Xeratec commented May 12, 2025

@phsauter In case you do not like formatting the C headers, we can wrap the defines in // clang-format off and // clang-format on comments.

@Xeratec Xeratec force-pushed the pr/autoformat branch 4 times, most recently from 75f3ed4 to e79e579 Compare May 12, 2025 08:33
@phsauter
Copy link
Collaborator

It looks like black is not installed in the tools container by default but pycodestyle is.

How strong is your preference for black or does it have some needed feature pycodestyle doesn't have?

And as a nitpick, I would rather have:

AlignConsecutiveMacros: true

In .clang-format, I think it looks nicer.

@phsauter phsauter added the documentation Improvements or additions to documentation label Jun 18, 2025
@Xeratec
Copy link
Member Author

Xeratec commented Jul 2, 2025

It looks like black is not installed in the tools container by default but pycodestyle is.

How strong is your preference for black or does it have some needed feature pycodestyle doesn't have?

And as a nitpick, I would rather have:

AlignConsecutiveMacros: true

In .clang-format, I think it looks nicer.

Sure, I can add AlignConsecutiveMacros: true. I could also switch to pycodestyle however this does not support automatic formatting. I will thus switch to flake8 which is a wrapper around pycodestyle which also supports automatic fixing.

@Xeratec
Copy link
Member Author

Xeratec commented Jul 2, 2025

It looks like black is not installed in the tools container by default but pycodestyle is.
How strong is your preference for black or does it have some needed feature pycodestyle doesn't have?
And as a nitpick, I would rather have:

AlignConsecutiveMacros: true

In .clang-format, I think it looks nicer.

Sure, I can add AlignConsecutiveMacros: true. I could also switch to pycodestyle however this does not support automatic formatting. I will thus switch to flake8 which is a wrapper around pycodestyle which also supports automatic fixing.

Actually, I just realized that flake8 does also not support autoformatting. How hard would it be to include black in the next version of the tool container?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants