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

Use more comprehensive auto-formatting tools for Python and C #384

Merged
merged 8 commits into from Oct 18, 2019

Conversation

sgallagher
Copy link
Collaborator

These patches switch our tests from running autopep8 to running black instead. This autoformatter includes some niceties as enforcing the same style of quotes everywhere and does a better job of aligning on the column boundaries.

They also add support for using clang-tidy instead of clang-format on systems with at least version 9.0.0 of clang-tidy.

I separated the patches that update all of the syntax from the patch that adds the auto-formatters to make review simpler.

I also noticed that .pyc and .pyo files weren't included in .gitignore while working on this, so there's a patch for that as well.

These patches are built atop #383 because that PR includes some fixes that clang-tidy revealed were needed.

@sgallagher sgallagher changed the title Use more comprehensive auto-formatting tools for Python and C [WIP] Use more comprehensive auto-formatting tools for Python and C Oct 17, 2019
@sgallagher sgallagher force-pushed the formatting branch 2 times, most recently from fa05410 to 0baf148 Compare October 17, 2019 15:26
On Fedora, Podman is better-supported and has support for CGroupsV2.

Fall back to Docker if it is unavailable (such as in the CI
environment).

Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
@@ -55,16 +71,16 @@ function mmd_run_docker_tests {
$SCRIPT_DIR/$MMD_OS/Dockerfile.deps.tmpl > $SCRIPT_DIR/$MMD_OS/Dockerfile.deps.$MMD_RELEASE
sed -e "s/@RELEASE@/$MMD_OS:$MMD_RELEASE/" $SCRIPT_DIR/$MMD_OS/Dockerfile.tmpl > $SCRIPT_DIR/$MMD_OS/Dockerfile-$MMD_RELEASE

sudo docker build \
$MMD_BUILDAH \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on travis failure, is sudo still needed here and below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, sudo is needed for docker but not podman. I'll fix that up. Thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Though that failure is actually different; I was relying on /dev/zero not having the executable flag, but apparently on Ubuntu (where the tests are kicked off), it does... 🤦‍♂️

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, that was wrong. I was just missing a variable. I think I will still try to find a less "clever" way of doing this, though.

Copy link
Collaborator

@mmathesius mmathesius left a comment

Choose a reason for hiding this comment

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

This looks great to me. Just one small doc fixup request.

Now if we can just figure out what valgrind is complaining about. (I suppose re-ordering the includes could cause something odd to happen.)

@@ -109,7 +109,7 @@ modulemd_subdocument_info_get_mdversion (ModulemdSubdocumentInfo *self);
*/
void
modulemd_subdocument_info_set_yaml (ModulemdSubdocumentInfo *self,
const gchar *contents);
const gchar *yaml);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like my feedback on the first version of this PR got lost...

The naming of the second parameter name should be consistent across the gtk-doc, function declaration, and function implementation. Either change @contents to @yaml in the doc above, or vice versa here and in the .c file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, not sure how that happened.

@@ -0,0 +1,4 @@
#!/usr/bin/sh

$1 --version | awk -F 'LLVM version' '{print $2}' - | awk '{print $1}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
$1 --version | awk -F 'LLVM version' '{print $2}' - | awk '{print $1}'
$1 --version | awk '/LLVM version/ {print $NF}' -

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice trick. I'll use that.

updated_stream = modulemd_module_stream_upgrade_to_v2 (
current_stream, &nested_error);
updated_stream =
modulemd_module_stream_upgrade_to_v2 (current_stream);
if (!updated_stream)
{
g_propagate_error (error, g_steal_pointer (&nested_error));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm. Since nested_error was dropped as a parameter to modulemd_module_stream_upgrade_to_v2(), there isn't (and never was) an nested error to propagate here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now if we can just figure out what valgrind is complaining about. (I suppose re-ordering the includes could cause something odd to happen.)

Valgrind is choking on the dup() to fcntl() change. I'm trying to figure out why, but if it takes much longer I may just disable that check.

When run under valgrind, fcntl(fd, F_DUPFD_CLOEXEC) returns -1 and EINVAL. Which according to fcntl(2) means "the kernel does not recognize this value". (Since valgrind overrides fcntl() so it can track resources, it seems like it may be a bug in valgrind itself.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The issue is that the clang-tidy conversion isn't actually safe. It needs to have a third argument, zero. I've fixed that and it seems to work now.

This syntax guarantees that the file descriptor is closed on exec()

Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
https://black.readthedocs.io

Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
@sgallagher sgallagher changed the title [WIP] Use more comprehensive auto-formatting tools for Python and C Use more comprehensive auto-formatting tools for Python and C Oct 17, 2019
@sgallagher
Copy link
Collaborator Author

I think I've finally worked the bugs out of this PR. Hopefully the CI will pass this time...

@sgallagher
Copy link
Collaborator Author

And it looks like CI is passing finally!

Copy link
Collaborator

@mmathesius mmathesius left a comment

Choose a reason for hiding this comment

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

Sorry, I should have noticed the missing third argument to fcntl().

All looks good to me now! Thanks for all that clean-up.

@sgallagher sgallagher merged commit 028aa0b into fedora-modularity:master Oct 18, 2019
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.

None yet

2 participants