Broken toml import
Closed this issue · 5 comments
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:
psf/black@7e1acb7
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:
- Add a requirement for
toml
torequirements.txt
. - Switch from using
toml
to usingtomli
.- You would also want to update
requirements.txt
to useblack
versions that depend upontomli
. - You would also need to update references to
toml.decoder.TomlDecodeError
totomli.decoder.TOMLDecodeError
. (Note the case change.)
- You would also want to update
- Catch import errors of
toml
and importtomli
instead, aliased totoml
.- You would also need an import alias for the aforementioned case change in
TomlDecodeError
.
- You would also need an import alias for the aforementioned case change in
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).
Thank you!
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).