ray-project / ray

Ray is an AI compute engine. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads.
https://ray.io
Apache License 2.0
34.21k stars 5.81k forks source link

[Epic][CI] Upgrade flake8 to version 7.1.1 #47991

Open MortalHappiness opened 1 month ago

MortalHappiness commented 1 month ago

What happened + What you expected to happen

While running the pre-commit hook of flake8, the following error occurs if Python version is 3.12. It's because the version of flake8 is too old.

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

Traceback (most recent call last):
  File "/home/mortalhappiness/.cache/pre-commit/repo785be_6i/py_env-python3.12/bin/flake8", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/mortalhappiness/.cache/pre-commit/repo785be_6i/py_env-python3.12/lib/python3.12/site-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "/home/mortalhappiness/.cache/pre-commit/repo785be_6i/py_env-python3.12/lib/python3.12/site-packages/flake8/main/application.py", line 363, in run
    self._run(argv)
  File "/home/mortalhappiness/.cache/pre-commit/repo785be_6i/py_env-python3.12/lib/python3.12/site-packages/flake8/main/application.py", line 350, in _run
    self.initialize(argv)
  File "/home/mortalhappiness/.cache/pre-commit/repo785be_6i/py_env-python3.12/lib/python3.12/site-packages/flake8/main/application.py", line 330, in initialize
    self.find_plugins(config_finder)
  File "/home/mortalhappiness/.cache/pre-commit/repo785be_6i/py_env-python3.12/lib/python3.12/site-packages/flake8/main/application.py", line 153, in find_plugins
    self.check_plugins = plugin_manager.Checkers(local_plugins.extension)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mortalhappiness/.cache/pre-commit/repo785be_6i/py_env-python3.12/lib/python3.12/site-packages/flake8/plugins/manager.py", line 356, in __init__
    self.manager = PluginManager(
                   ^^^^^^^^^^^^^^
  File "/home/mortalhappiness/.cache/pre-commit/repo785be_6i/py_env-python3.12/lib/python3.12/site-packages/flake8/plugins/manager.py", line 238, in __init__
    self._load_entrypoint_plugins()
  File "/home/mortalhappiness/.cache/pre-commit/repo785be_6i/py_env-python3.12/lib/python3.12/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'

Versions / Dependencies

Python 3.12

Reproduction script

If python version is 3.9 -> no error

If python version is 3.12 -> has error

Upgrade the following packages to the newest version solves this issue:

Issue Severity

Low: It annoys or frustrates me.

flake8 upgrade subtasks tracking:

Thanks for @CheyuWu 's comment here https://github.com/ray-project/ray/issues/48022#issuecomment-2414051046

pycodestyle

pyflakes

flake8-bugbear

https://github.com/PyCQA/flake8-bugbear

flake8-comprehensions

https://github.com/adamchainz/flake8-comprehensions

CI upgrade

Cleanup

Notes for contributors

CheyuWu commented 1 month ago

@MortalHappiness I'd like to help with this!

jjyao commented 4 weeks ago

@MortalHappiness we should explore replacing flake8 with https://github.com/astral-sh/ruff if we want to do the upgrade.

MortalHappiness commented 4 weeks ago

@jjyao Do you mean to replace flake8 completely with ruff?

jjyao commented 4 weeks ago

Yes. Reasoning is that ruff is drop-in replacement for flake8 so upgrading flake8 and switching to ruff should require the similar amount of efforts.