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 setup.cfg to configure flake8, instead of in the ci code #930

Merged

Conversation

SubaruArai
Copy link
Contributor

@SubaruArai SubaruArai commented Aug 17, 2023

This makes flake8's configuration more discoverable and easier to use with other tools (IDE, etc.).

Regression: it seems that "max-complexity" wasn't properly enforced, now a lot of code is detected as too complex. (warn if > 10, max is 25)
We may need to adjust the value.

Complexity adjusted to 26 to satisfy the current code's needs.

This makes flake8's configuration more discoverable and easier to
use with other tools (IDE, etc.).

Regression: it seems that "max-complexity" wasn't properly enforced,
now a lot of code is detected as too complex. (warn if > 10, max is 25)
We may need to adjust the value.
@SubaruArai
Copy link
Contributor Author

@cottsay What do you say? There are dozens of functions flagged as "too complex"(C901).

I suggest changing max-complexity to 25 or 30.

@SubaruArai
Copy link
Contributor Author

SubaruArai commented Aug 17, 2023

We might as well revert #912 if this fixes those problems on macos. It might be related to complexity not being properly checked, due to using the old API.

SubaruArai added 2 commits August 17, 2023 14:00
Inline comments are not allowed in flake8>=6.0
Because it doesn't have a stable public API.
@SubaruArai
Copy link
Contributor Author

Just FYI, bumping flake8 to 6.1.0 added these errors:

  • E721: do not compare types, for exact checks use is / is not, for instance checks use isinstance()
  • E231: missing whitespace after ','

Personally, I think both are valid and should be fixed in a separate PR.

@SubaruArai SubaruArai changed the title Use setup.cfg to configure flake8 **has regression** Use setup.cfg to configure flake8, instead of in the ci code **has regression** Feb 18, 2024
@cottsay
Copy link
Member

cottsay commented Apr 9, 2024

If we're not enforcing the rule right now, the first move is to set a backstop at a higher level and get it merged before things get worse.

We can clean up the complexity and reduce the limit in a future change.

@SubaruArai
Copy link
Contributor Author

@cottsay by backstop, do you mean changing the complexity in this pr from 10 to around (whatever smallest that works)?

@cottsay
Copy link
Member

cottsay commented Apr 10, 2024

do you mean changing the complexity in this pr from 10 to around (whatever smallest that works)?

Yes

@SubaruArai
Copy link
Contributor Author

@cottsay Done, it's ready to be merged!

@SubaruArai SubaruArai changed the title Use setup.cfg to configure flake8, instead of in the ci code **has regression** Use setup.cfg to configure flake8, instead of in the ci code Apr 10, 2024
Copy link
Member

@cottsay cottsay left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this. Only major concern is that we'd like to continue to support Python 2 until the next release.

Out of curiosity, why wasn't max_complexity enforced before? Underscore vs hyphen?

test/test_flake8.py Outdated Show resolved Hide resolved
test/test_flake8.py Outdated Show resolved Hide resolved
test/test_flake8.py Outdated Show resolved Hide resolved
Co-authored-by: Scott K Logan <logans@cottsay.net>
@SubaruArai
Copy link
Contributor Author

Out of curiosity, why wasn't max_complexity enforced before? Underscore vs hyphen?

Looks like the legacy API accepted complexity when running check_file(). Maybe this was the reason?

Copy link
Member

@cottsay cottsay 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 a deviation from how we've been doing flake8 tests in the rest of ROS, but the upstream churn has been breaking us constantly and I don't see any reason not to take this route everywhere else, too.

That said, I'd like to hear from other ros-infrastructure maintainers if they see any drawbacks with the process invocation approach taken here.

@nuclearsandwich
Copy link
Contributor

That said, I'd like to hear from other ros-infrastructure maintainers if they see any drawbacks with the process invocation approach taken here.

I tested locally with both passing and non-passing result and in both cases the flake8 output was properly set.

This might even make it easier for me to add some local overrides (i.e. I have a .direnv folder in the repository that also needs to be excluded but haven't just caved and made it part of the file's default).

@cottsay cottsay merged commit 14878e3 into ros-infrastructure:master Apr 17, 2024
15 checks passed
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