peterjc / flake8-black

flake8 plugin to run black for checking Python coding style
MIT License
165 stars 10 forks source link

Broken toml import #32

Closed chris-bradley closed 2 years ago

chris-bradley commented 3 years ago

Since Black 21.7b0, released earlier today, flake8-black breaks on an import error when used with a freshly installed environment. The issue is due to the following commit: https://github.com/psf/black/pull/2301/commits/7e1acb74eb9e1a7e989cac4ed9242ae2950430cb Since flake8-black imports toml without depending directly on it, freshly built environments fail with the following error:

Traceback (most recent call last):
  File "/home/circleci/.venv/lib/python3.6/site-packages/flake8/plugins/manager.py", line 157, in load_plugin
    self._load()
  File "/home/circleci/.venv/lib/python3.6/site-packages/flake8/plugins/manager.py", line 134, in _load
    self._plugin = self.entry_point.load()
  File "/home/circleci/.venv/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 178, in load
    module = import_module(match.group('module'))
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/circleci/.venv/lib/python3.6/site-packages/flake8_black.py", line 11, in <module>
    import toml
ModuleNotFoundError: No module named 'toml'

There are a few options to fix this:

peterjc commented 3 years ago

Thank you for reporting this. I'm leaning to adding toml as an explicit dependency as a short term low risk fix.

Sigh. They had to release it on a Friday didn't they? There will probably be other bug reports in the ecosystem not seen until Monday morning (and then a fresh batch as more people try the new black on Monday).

chris-bradley commented 3 years ago

Thank you!

peterjc commented 3 years ago

Touch wood v0.2.2 fixes this for you, but I don't want to make any more dramatic changes prior to addressing the broken continuous integration (#34).

brianhelba commented 3 years ago

@peterjc I don't see how https://github.com/peterjc/flake8-black/commit/65c9d577557fe397b0ebe8f41cf041a423789fcb fixes this issue, since only requirements.txt is changed.

You'll need to update install_requires in setup.py in order to give setuptools adequate metadata to fetch the dependency when installing with pip.

peterjc commented 3 years ago

You’re right :(

Didn’t have time to test it fully after dinner.