Howdy! Sorry you're having trouble. To expedite your experience,
provide some basics for me:
Operating system: Windows 10 64bit
Python version: Python 3.7.0 (32Bit)
Black version: 18.6b4
Does also happen on master: Yes
When running black for directory it fails without any error when formatting.
As far as I can tell it happens here:
black.py@445
tasks = {
loop.run_in_executor(
executor,
format_file_in_place,
src,
line_length,
fast,
write_back,
mode,
lock,
): src
for src in sorted(sources)
}
So I'm not sure if it's an bug in black or somewhere deeper. Or it might just be a feature of running 32bit python3 on windows 64bit.
It doesn't happen when using py3.7 64bit. Nor on py3.6 64bit. When I have a moment I'll test it on py3.6 32bit.
Interesting, some related tests indeed fail on a 32bit 3.7.0, but not 3.6.5. I'll look into this.
Sounds like an issue with asyncio.
Just confirming this issue here too. The traceback I see for it is...
Traceback (most recent call last):
File "/home/travis/virtualenv/python3.7-dev/bin/black", line 11, in <module>
sys.exit(main())
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/black.py", line 372, in main
executor=executor,
File "/opt/python/3.7-dev/lib/python3.7/asyncio/base_events.py", line 495, in run_until_complete
return future.result()
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/black.py", line 486, in schedule_formatting
src = tasks.pop(task)
KeyError: <Task finished coro=<BaseEventLoop.run_in_executor() done, defined at /opt/python/3.7-dev/lib/python3.7/asyncio/base_events.py:653> result=False>
This is not specifically a windows issue. Eg. Same issue replicates running on travis/linux here: https://travis-ci.org/encode/starlette/jobs/439045800
But it is limited to 3.7.
Reproduced minimally here: https://github.com/tomchristie/testblack/pull/1
foo/__init__.py
foo/a.py
print(1)
foo/b.py
print(2)
Running on 3.6
$ black foo --check
All done! ✨ 🍰 ✨
3 files would be left unchanged.
The command "black foo --check" exited with 0.
Running on 3.7
$ black foo --check
Traceback (most recent call last):
File "/home/travis/virtualenv/python3.7-dev/bin/black", line 11, in <module>
sys.exit(main())
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/black.py", line 372, in main
executor=executor,
File "/opt/python/3.7-dev/lib/python3.7/asyncio/base_events.py", line 495, in run_until_complete
return future.result()
File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/black.py", line 486, in schedule_formatting
src = tasks.pop(task)
KeyError: <Task finished coro=<BaseEventLoop.run_in_executor() done, defined at /opt/python/3.7-dev/lib/python3.7/asyncio/base_events.py:653> result=False>
The command "black foo --check" exited with 1.
Could we get the issue retitled as "Black is not formatting code on Python 3.7 on some platform configurations", since it's not windows specfic? (The above is Ubuntu, 64 bit)
@tomchristie Done. Thank you :)
Note that the issue does not reproduce on xenial builds: https://github.com/tomchristie/testblack-xenial/pull/1
Most helpful comment
This is not specifically a windows issue. Eg. Same issue replicates running on travis/linux here: https://travis-ci.org/encode/starlette/jobs/439045800