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 autoformatting to the PgBouncer source code #892

Merged
merged 8 commits into from
Aug 16, 2023

Conversation

JelteF
Copy link
Member

@JelteF JelteF commented Jul 14, 2023

This uses uncrustify with a config that matches the code style of the repo as
close as I was able to configure it.

Codestyle is always an easy thing to disagree on, but I think overall this
improves the styling. It also keeps the fairly small.

I also considered using pgindent, but that requires a typedefs.list which is a
pain to create. The current codestyle of PgBouncer also doesn't match the one
from Postgres at all, so it would cause many uninteresting changes.

@JelteF JelteF requested a review from eulerto July 14, 2023 16:14
src/sbuf.c Outdated Show resolved Hide resolved
@JelteF JelteF force-pushed the auto-formatting branch 2 times, most recently from 6df4dba to 7020445 Compare July 18, 2023 10:02
Copy link
Member

@eulerto eulerto left a comment

Choose a reason for hiding this comment

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

It is not a complete review because it is easy to bikeshed on topics like this.

include/bouncer.h Outdated Show resolved Hide resolved
include/bouncer.h Show resolved Hide resolved
include/util.h Outdated Show resolved Hide resolved
src/dnslookup.c Outdated Show resolved Hide resolved
src/pam.c Outdated Show resolved Hide resolved
src/janitor.c Show resolved Hide resolved
Copy link
Member

@petere petere left a comment

Choose a reason for hiding this comment

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

This is very impressive. I'm happy to proceed with this tool. I left a few small comments on the formatting itself. The source code and build system integration needs a bit more consideration.

src/janitor.c Show resolved Hide resolved
src/main.c Outdated Show resolved Hide resolved
src/objects.c Outdated Show resolved Hide resolved
include/bouncer.h Outdated Show resolved Hide resolved
.gitmodules Outdated
@@ -4,3 +4,6 @@
[submodule "uthash"]
path = uthash
url = https://github.com/troydhanson/uthash.git
[submodule "uncrustify"]
Copy link
Member

Choose a reason for hiding this comment

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

I would rather have fewer submodules than more. But apart from that, pulling this in this way would include it in the distributed source tarballs, which isn't good. Also, it's GPL. So we should really keep it at arm's length. Better just install it as a normal build dependency.

Copy link
Member Author

Choose a reason for hiding this comment

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

The main problem with installing a system uncrustify version through apt/yum/brew is that it is important that everyone uses the exact same version. A newer version might have a formatting bug fixed and result in slightly different formatting. So a submodule seemed like a reasonable way to ensure a consistent version. (for black this is less of an issue, because we can just say we should use the latest version, which is very easy to install using pip)

But apart from that, pulling this in this way would include it in the distributed source tarballs, which isn't good.

You mean the ones created by make dist? Since it's not in the EXTRA_DIST list they won't be included there. Also github doesn't seem to include submodule contents in the source tarballs it generates.

Also, it's GPL. So we should really keep it at arm's length. Better just install it as a normal build dependency.

Since we're not linking against it (only executing the built binary) I personally don't see much of an issue with it.

To resolve concerns though, I now pushed a version where we get the tarball from github and compile the uncrustify binary in a temporary directory.

Copy link
Member

Choose a reason for hiding this comment

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

We can just say, we use uncrustify version x.y.z, and everyone just has to get that one.

I hate git submodules and I don't want more git submodules. :)

Copy link
Member Author

@JelteF JelteF Aug 16, 2023

Choose a reason for hiding this comment

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

Did you see I updated the the PR to remove the submodule and have the make target fetch and compile the uncrustify version from sources in a temporary directory? Is that okay? Or would you rather I remove the install steps from the Makefile completely and instead move them to a CONTRIBUTING.md and have people run them manually?

@@ -177,3 +177,21 @@ htmls:

doc/pgbouncer.1 doc/pgbouncer.5:
$(MAKE) -C doc $(@F)

indent-check: uncrustify/build/uncrustify
flake8
Copy link
Member

Choose a reason for hiding this comment

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

Seems like flake8 isn't really related to indenting.

.cirrus.yml Outdated
@@ -260,14 +260,14 @@ task:
type: text/plain

task:
name: Python check
name: Formatting check
Copy link
Member

Choose a reason for hiding this comment

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

I would like to keep the Python style check separate from the formatting checks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Did you mean Python and C separate? and/or did you mean separating flake8 (which does not format automatically) from isort & black?

Copy link
Member Author

Choose a reason for hiding this comment

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

I split stuff up a bit more. Is this what you had in mind?

pyproject.toml Outdated
@@ -19,9 +19,21 @@ timeout = 30
# versions is a small price to pay to not have to worry about that.
asyncio_mode = 'auto'

# Make test discovery quicker
norecursedirs = [
'*.egg',
Copy link
Member

Choose a reason for hiding this comment

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

unrelated to this patch?

Copy link
Member Author

Choose a reason for hiding this comment

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

uncrustify directory had a python file that caused some issues with this I think

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't want uncrustify's stuff in pgbouncer's tree. We have enough crap in there, we don't need to import someone else's crap too and then keep track of that as versions change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah fair enough, I had already updated the PR to have a make target to compile it in a temporary directory. But I forgot to remove these changes. I did that now. And I created a separate PR to update the excludes for the already existing submodules: #924

uncrustify.cfg Show resolved Hide resolved
Makefile Outdated
flake8
black --check .
isort --check .
uncrustify/build/uncrustify -c uncrustify.cfg --check include/*.h src/*.c -L WARN
Copy link
Member

Choose a reason for hiding this comment

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

Also, it would be good to make separate targets for C code and Python code. Most people will only deal with the C code, so it would be annoying to make them download black and isort, or manually copy the uncrustify command.

@JelteF JelteF force-pushed the auto-formatting branch 2 times, most recently from a8da877 to b7c522d Compare August 10, 2023 16:36
@JelteF JelteF requested a review from petere August 10, 2023 21:23
@JelteF
Copy link
Member Author

JelteF commented Aug 10, 2023

@petere I think I addressed all feedback.

Copy link
Member

@petere petere left a comment

Choose a reason for hiding this comment

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

Ok by me.

Please check if the changes in .flake8 and pyproject.toml are still required.

@petere
Copy link
Member

petere commented Aug 16, 2023

Please check if the changes in .flake8 and pyproject.toml are still required.

It seems this was done. :)

@JelteF
Copy link
Member Author

JelteF commented Aug 16, 2023

Ok by me.

Just to be clear, you're happy with the current method of installing uncrustify? (i.e. Makefile that fetches and compiles tarball in a temp directory, and puts the final binary in the root of the repo)

@petere
Copy link
Member

petere commented Aug 16, 2023

Ok by me.

Just to be clear, you're happy with the current method of installing uncrustify? (i.e. Makefile that fetches and compiles tarball in a temp directory, and puts the final binary in the root of the repo)

Let's say I'm "content". :)

@JelteF JelteF merged commit 314f255 into pgbouncer:master Aug 16, 2023
@JelteF JelteF deleted the auto-formatting branch August 16, 2023 13:01
JelteF added a commit to JelteF/pgbouncer that referenced this pull request Aug 16, 2023
This was missed in pgbouncer#892, because these new lines were added after the
last rebase of that PR (and they did not cause a merge conflict).
@JelteF JelteF mentioned this pull request Aug 16, 2023
JelteF added a commit that referenced this pull request Aug 16, 2023
This was missed in #892, because these new lines were added after the
last rebase of that PR (and they did not cause a merge conflict).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants