Pre-commit flake8 failures

What's up with the flake8 failures currently on the OctoPrint repository?

(OctoPrint) ryan@linda:~/git/OctoPrint{maintenance}$ pre-commit run --hook-stage manual --all-files
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
check for case conflicts.................................................Passed
check json...............................................................Passed
check yaml...............................................................Passed
check toml...............................................................Passed
check for merge conflicts................................................Passed
fix python encoding pragma...............................................Passed
pyupgrade................................................................Passed
OctoPrint codemod: batch.................................................Passed
isort....................................................................Passed
black....................................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

src/octoprint/schema/config/temperature.py:2:104: B950 line too long (103 > 90 characters)
src/octoprint/printer/profile.py:45:118: B950 line too long (117 > 90 characters)
src/octoprint/printer/profile.py:85:109: B950 line too long (108 > 90 characters)
[...]
src/octoprint/server/views.py:1454:1: C901 '_process_template_configs' is too complex (12)
src/octoprint/server/views.py:1484:110: B950 line too long (109 > 90 characters)
src/octoprint/server/views.py:1504:1: C901 '_process_template_config' is too complex (16)

prettier.................................................................Passed
eslint...................................................................Passed
codespell................................................................Passed

The complexity errors are because I have max-complexity = 10 in my ~/.config/flake8 (it sucks that flake8 doesn't have a "ignore user config" option), but the max-line-length is specifically adhering to setup.cfg:

[flake8]
max-line-length = 90
extend-ignore = E203, E231, E265, E266, E402, E501, E731
select = B,C,E,F,W,T4,B9
exclude =
    src/octoprint/vendor

And there are MANY files in the codebase with lengths greater than 90.

Perhaps also related, the GH Actions PR pre-commit job appears broken in a different respect, for example:

flake8...................................................................Failed
- hook id: flake8
- exit code: 1

Traceback (most recent call last):
  File "/home/runner/.cache/pre-commit/repos7xx2qfz/py_env-python3.7/bin/flake8", line 8, in <module>
    sys.exit(main())
  File "/home/runner/.cache/pre-commit/repos7xx2qfz/py_env-python3.7/lib/python3.7/site-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "/home/runner/.cache/pre-commit/repos7xx2qfz/py_env-python3.7/lib/python3.7/site-packages/flake8/main/application.py", line 363, in run
    self._run(argv)
  File "/home/runner/.cache/pre-commit/repos7xx2qfz/py_env-python3.7/lib/python3.7/site-packages/flake8/main/application.py", line 350, in _run
    self.initialize(argv)
  File "/home/runner/.cache/pre-commit/repos7xx2qfz/py_env-python3.7/lib/python3.7/site-packages/flake8/main/application.py", line 330, in initialize
    self.find_plugins(config_finder)
  File "/home/runner/.cache/pre-commit/repos7xx2qfz/py_env-python3.7/lib/python3.7/site-packages/flake8/main/application.py", line 153, in find_plugins
    self.check_plugins = plugin_manager.Checkers(local_plugins.extension)
  File "/home/runner/.cache/pre-commit/repos7xx2qfz/py_env-python3.7/lib/python3.7/site-packages/flake8/plugins/manager.py", line 357, in __init__
    self.namespace, local_plugins=local_plugins
  File "/home/runner/.cache/pre-commit/repos7xx2qfz/py_env-python3.7/lib/python3.7/site-packages/flake8/plugins/manager.py", line 238, in __init__
    self._load_entrypoint_plugins()
  File "/home/runner/.cache/pre-commit/repos7xx2qfz/py_env-python3.7/lib/python3.7/site-packages/flake8/plugins/manager.py", line 254, in _load_entrypoint_plugins
    eps = importlib_metadata.entry_points().get(self.namespace, ())
AttributeError: 'EntryPoints' object has no attribute 'get'

I just want to make sure I'm not missing something. Are we just in the middle of a black reformat and the code hasn't been chopped to 90 yet, or something similar?

With the 1st flake8 issues you've noted, I'll try and reproduce them on my install but the most recent builds on GitHub have either succeeded or the below error occurred, so it could be some slight environmental difference.

With the second actual code error, it was a breaking change in importlib-metadata that was to blame there - it should be fixed with 8e9c09a I believe. That commit doesn't automatically make its way to maintenance, but it should be merged (or cherry-picked) there at some point soon.

Don't let pre-commit failures prevent you from contributing - if it fails, I believe there's a way to skip checks (can't remember exactly off the top of my head) so you can commit & it can be fixed later.

Okay, thanks for the info; I've figured out what the first problem is. If the user has ~/.config/flake8 at all, it completely takes precedence over setup.cfg, which isn't great for reproducibility. That is to say, it's not like setup.cfg entries override ~/.config/flake8 or vice versa, setup.cfg is just completely ignored.

I've opened PR #4665 to explicitly use setup.cfg for the flake8 check.

1 Like