grantjenks / blue

The slightly less uncompromising Python code formatter.
https://blue.readthedocs.io/
Other
393 stars 21 forks source link

blue is incompatible with flake8 v5 #78

Open RobertCraigie opened 2 years ago

RobertCraigie commented 2 years ago

Flake8 v5 was just released earlier today. Unfortunately this breaks blue as it now crashes with this error:

Traceback (most recent call last):
  File "/tmp/tox/prisma-client-py/lint/lib/python3.9/site-packages/blue/__init__.py", line 397, in <module>
    BaseConfigParser = flake8_config.ConfigParser              # flake8 v4
AttributeError: module 'flake8.options.config' has no attribute 'ConfigParser'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/tox/prisma-client-py/lint/bin/blue", line 5, in <module>
    from blue import main
  File "/tmp/tox/prisma-client-py/lint/lib/python3.9/site-packages/blue/__init__.py", line 399, in <module>
    BaseConfigParser = flake8_config.MergedConfigParser        # flake8 v3
AttributeError: module 'flake8.options.config' has no attribute 'MergedConfigParser'

Constraining the flake8 dependency to v4 fixes the error.

krcb197 commented 2 years ago

I have been able to work around this problem by adding a dependency in setup.py for my project on flake8<=4.0.1, the same workaround can be done in a requirements.txt

warsaw commented 2 years ago

Okay, this does look like a trickier incompatibility to resolve. It looks like flake8 didn't just change the name of the config class, they changed the way they parse the configs. So I think for now, a quick fix is the pin in #79 but we should leave this issue open pending a proper fix.

danigm commented 2 years ago

I think this patch will fix the issue

flake8-v5-compatibility.patch.txt

warsaw commented 2 years ago

I think this patch will fix the issue

Unfortunately, not completely. With this change as well:

modified   setup.py
@@ -37,7 +37,7 @@ setup(
     packages=['blue'],
     tests_require=['tox'],
     cmdclass={'test': Tox},
-    install_requires=['black==22.1.0', 'flake8>=3.8,<5.0.0'],
+    install_requires=['black==22.1.0', 'flake8>=3.8'],
     project_urls={
         'Documentation': 'https://blue.readthedocs.io/en/latest',
         'Source': 'https://github.com/grantjenks/blue.git',

(i.e. remove the flake8 ceiling), I get the following errors:

ctx = <click.core.Context object at 0x10a5d84f0>, param = <Option config>, value = None

    def read_configs(
        ctx: click.Context, param: click.Parameter, value: Optional[str]
    ) -> Optional[str]:
        """Read configs through the config param's callback hook."""
        # Use black's `read_pyproject_toml` for the default
        result = black.read_pyproject_toml(ctx, param, value)
        # Use flake8's config file parsing to load setup.cfg, tox.ini, and .blue
        # The parsing looks both in the project and user directories.
>       finder = flake8_config.ConfigFileFinder('blue')
E       AttributeError: module 'flake8.options.config' has no attribute 'ConfigFileFinder'

/Users/barry/projects/blue/blue/__init__.py:424: AttributeError
sshishov commented 1 year ago

Could we guys fix the issue? The issue is open for half of the year. Flake8 has already v6 btw

xmnlab commented 1 year ago

hey everyone, any plan for supporting flake8 v5 and v6?

sshishov commented 1 year ago

@xmnlab I guess we have to come up with pull request for this to support it. Otherwise the issue will be open for years...

warsaw commented 1 year ago

If you can, I'll review it.

kaweantonio commented 1 year ago

If you can, I'll review it.

Hi, @warsaw, I opened PR #96 to fix this issue. Can you review it?