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

Add ClangFormat to pre-commit #8015

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Apr 25, 2024

Follow on from #4493 / #4770.

As reminded by #8011 (comment) we didn't add this to pre-commit/CI at the time. Let's add it now.

Update the others at the same time.

@hugovk hugovk added the Testing label Apr 25, 2024
src/_imagingcms.c Outdated Show resolved Hide resolved
src/_imagingcms.c Outdated Show resolved Hide resolved
src/_imagingcms.c Outdated Show resolved Hide resolved
Comment on lines +50 to +60
#ifdef HAVE_RAQM_SYSTEM
#include <raqm.h>
#else
#include "thirdparty/raqm/raqm.h"
#ifdef HAVE_FRIBIDI_SYSTEM
#include <fribidi.h>
#else
#include "thirdparty/fribidi-shim/fribidi.h"
#include <hb.h>
#endif
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

This change looks technically correct, but also I'm pretty sure the previous indentation was intentional for readability.

Copy link
Member

Choose a reason for hiding this comment

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

There is a clang setting to change this, https://stackoverflow.com/a/66004745, but I don't think the effect of the alternative settings on other files looks good.

@@ -719,7 +727,7 @@ bounding_box_and_anchors(FT_Face face, const char *anchor, int horizontal_dir, G
static PyObject *
font_getsize(FontObject *self, PyObject *args) {
int width, height, x_offset, y_offset;
int load_flags; /* FreeType load_flags parameter */
int load_flags; /* FreeType load_flags parameter */
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we lose the indentation with the other variable comments.

Copy link
Member

Choose a reason for hiding this comment

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

@Yay295
Copy link
Contributor

Yay295 commented Apr 25, 2024

A lot of these changes don't really improve readability, imo.

Comment on lines +730 to 731
int load_flags; /* FreeType load_flags parameter */
int error;
Copy link
Member

@radarhere radarhere Apr 28, 2024

Choose a reason for hiding this comment

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

Suggested change
int load_flags; /* FreeType load_flags parameter */
int error;
int error;
int load_flags; /* FreeType load_flags parameter */

If the indentation is a concern, then this could be a solution - by grouping load_flags with the other commented lines, the indentation is kept.

Copy link
Member Author

@hugovk hugovk Apr 28, 2024

Choose a reason for hiding this comment

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

Or can we now declare on first use, a few lines below?

-    load_flags = FT_LOAD_DEFAULT;
+    /* FreeType load_flags parameter */
+    int load_flags = FT_LOAD_DEFAULT;

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, every variable in this function is declared at the top at the moment, and I think the consistency of that is good.

I'm happy just leaving it as it currently is in this PR.

hugovk and others added 3 commits April 28, 2024 11:11
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@Yay295
Copy link
Contributor

Yay295 commented Apr 28, 2024

Currently in Python when a function declaration is split across multiple lines, the closing parenthesis is on the same level as the def.

Pillow/src/PIL/Image.py

Lines 3484 to 3488 in c250a44

def register_open(
id,
factory: Callable[[IO[bytes], str | bytes], ImageFile.ImageFile],
accept: Callable[[bytes], bool | str] | None = None,
) -> None:

However with this change in C the closing parenthesis is on the same line as the last argument.

https://github.com/hugovk/Pillow/blob/5597f618a3b5cf8e208dded44a2107313c47122d/src/libImaging/BcnDecode.c#L825-L833

static int
decode_bcn(
    Imaging im,
    ImagingCodecState state,
    const UINT8 *src,
    int bytes,
    int N,
    int C,
    char *pixel_format) {

It's the same with function calls as well. It looks like this is changed with AlignAfterOpenBracket: BlockIndent.

@radarhere
Copy link
Member

However with this change in C the closing parenthesis is on the same line as the last argument.

From what I can see, this is the style of C that is already in place. For the example you've cited, here how it is in main.

static int
decode_bcn(
Imaging im, ImagingCodecState state, const UINT8 *src, int bytes, int N, int C, char *pixel_format) {

Here are some other examples.

Pillow/src/_imagingft.c

Lines 250 to 257 in 58a4797

static size_t
text_layout_raqm(
PyObject *string,
FontObject *self,
const char *dir,
PyObject *features,
const char *lang,
GlyphInfo **glyph_info) {

Pillow/src/_imagingcms.c

Lines 404 to 412 in 58a4797

_buildProofTransform(
cmsHPROFILE hInputProfile,
cmsHPROFILE hOutputProfile,
cmsHPROFILE hProofProfile,
char *sInMode,
char *sOutMode,
int iRenderingIntent,
int iProofIntent,
cmsUInt32Number cmsFLAGS) {

Unless I've missed something in looking at the changes here, this PR isn't even moving any closing brackets from a newline onto the same line as the last argument - it's just making the existing style slightly more apparent because it's splitting up some long lines.

I'm not opposed to changing the style for its own sake, I just don't think the current state of this PR affects what you're describing.

@Yay295
Copy link
Contributor

Yay295 commented May 4, 2024

Ah, yeah that does seem to be the case. I didn't find any instances of ) { at the start of a line, other than three if blocks.




I would prefer the other format, but that could be a separate change.

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

Successfully merging this pull request may close these issues.

None yet

4 participants