Report progress on multiple files incrementally
This commit is contained in:
parent
b4cee97c99
commit
96e68f0341
@ -609,6 +609,8 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
|
|||||||
* typing stub files (`.pyi`) are now formatted in a style that is consistent
|
* typing stub files (`.pyi`) are now formatted in a style that is consistent
|
||||||
with PEP 484 (#207, #210)
|
with PEP 484 (#207, #210)
|
||||||
|
|
||||||
|
* progress when reformatting many files is now reported incrementally
|
||||||
|
|
||||||
* fixed trailers (content with brackets) being unnecessarily exploded
|
* fixed trailers (content with brackets) being unnecessarily exploded
|
||||||
into their own lines after a dedented closing bracket (#119)
|
into their own lines after a dedented closing bracket (#119)
|
||||||
|
|
||||||
|
39
black.py
39
black.py
@ -282,32 +282,29 @@ async def schedule_formatting(
|
|||||||
manager = Manager()
|
manager = Manager()
|
||||||
lock = manager.Lock()
|
lock = manager.Lock()
|
||||||
tasks = {
|
tasks = {
|
||||||
src: loop.run_in_executor(
|
loop.run_in_executor(
|
||||||
executor, format_file_in_place, src, line_length, fast, write_back, lock
|
executor, format_file_in_place, src, line_length, fast, write_back, lock
|
||||||
)
|
): src
|
||||||
for src in sources
|
for src in sorted(sources)
|
||||||
}
|
}
|
||||||
_task_values = list(tasks.values())
|
pending: Iterable[asyncio.Task] = tasks.keys()
|
||||||
try:
|
try:
|
||||||
loop.add_signal_handler(signal.SIGINT, cancel, _task_values)
|
loop.add_signal_handler(signal.SIGINT, cancel, pending)
|
||||||
loop.add_signal_handler(signal.SIGTERM, cancel, _task_values)
|
loop.add_signal_handler(signal.SIGTERM, cancel, pending)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
# There are no good alternatives for these on Windows
|
# There are no good alternatives for these on Windows
|
||||||
pass
|
pass
|
||||||
await asyncio.wait(_task_values)
|
while pending:
|
||||||
for src, task in tasks.items():
|
done, _ = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED)
|
||||||
if not task.done():
|
for task in done:
|
||||||
report.failed(src, "timed out, cancelling")
|
src = tasks.pop(task)
|
||||||
task.cancel()
|
if task.cancelled():
|
||||||
cancelled.append(task)
|
cancelled.append(task)
|
||||||
elif task.cancelled():
|
elif task.exception():
|
||||||
cancelled.append(task)
|
report.failed(src, str(task.exception()))
|
||||||
elif task.exception():
|
else:
|
||||||
report.failed(src, str(task.exception()))
|
formatted.append(src)
|
||||||
else:
|
report.done(src, Changed.YES if task.result() else Changed.NO)
|
||||||
formatted.append(src)
|
|
||||||
report.done(src, Changed.YES if task.result() else Changed.NO)
|
|
||||||
|
|
||||||
if cancelled:
|
if cancelled:
|
||||||
await asyncio.gather(*cancelled, loop=loop, return_exceptions=True)
|
await asyncio.gather(*cancelled, loop=loop, return_exceptions=True)
|
||||||
if write_back == WriteBack.YES and formatted:
|
if write_back == WriteBack.YES and formatted:
|
||||||
@ -2833,7 +2830,7 @@ def diff(a: str, b: str, a_name: str, b_name: str) -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def cancel(tasks: List[asyncio.Task]) -> None:
|
def cancel(tasks: Iterable[asyncio.Task]) -> None:
|
||||||
"""asyncio signal handler that cancels all `tasks` and reports to stderr."""
|
"""asyncio signal handler that cancels all `tasks` and reports to stderr."""
|
||||||
err("Aborted!")
|
err("Aborted!")
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
|
Loading…
Reference in New Issue
Block a user