Simplify caching logic.
This commit is contained in:
parent
b7e216f554
commit
1dbe77cd91
29
black.py
29
black.py
@ -399,14 +399,9 @@ def reformat_one(
|
|||||||
mode=mode,
|
mode=mode,
|
||||||
):
|
):
|
||||||
changed = Changed.YES
|
changed = Changed.YES
|
||||||
if write_back is WriteBack.YES:
|
if (write_back is WriteBack.YES and changed is not Changed.CACHED) or (
|
||||||
should_write = changed is not Changed.CACHED
|
write_back is WriteBack.CHECK and changed is Changed.NO
|
||||||
elif write_back is WriteBack.CHECK:
|
):
|
||||||
should_write = changed is Changed.NO
|
|
||||||
else:
|
|
||||||
should_write = False
|
|
||||||
|
|
||||||
if should_write:
|
|
||||||
write_cache(cache, [src], line_length, mode)
|
write_cache(cache, [src], line_length, mode)
|
||||||
report.done(src, changed)
|
report.done(src, changed)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
@ -437,7 +432,7 @@ async def schedule_formatting(
|
|||||||
for src in sorted(cached):
|
for src in sorted(cached):
|
||||||
report.done(src, Changed.CACHED)
|
report.done(src, Changed.CACHED)
|
||||||
cancelled = []
|
cancelled = []
|
||||||
formatted = []
|
sources_to_cache = []
|
||||||
if sources:
|
if sources:
|
||||||
lock = None
|
lock = None
|
||||||
if write_back == WriteBack.DIFF:
|
if write_back == WriteBack.DIFF:
|
||||||
@ -475,17 +470,17 @@ async def schedule_formatting(
|
|||||||
report.failed(src, str(task.exception()))
|
report.failed(src, str(task.exception()))
|
||||||
else:
|
else:
|
||||||
changed = Changed.YES if task.result() else Changed.NO
|
changed = Changed.YES if task.result() else Changed.NO
|
||||||
# In normal mode, write all files to the cache.
|
# If the file was written back or was successfully checked as
|
||||||
if write_back is WriteBack.YES:
|
# well-formatted, store this information in the cache.
|
||||||
formatted.append(src)
|
if write_back is WriteBack.YES or (
|
||||||
# In check mode, write only unchanged files to the cache.
|
write_back is WriteBack.CHECK and changed is Changed.NO
|
||||||
elif write_back is WriteBack.CHECK and changed is Changed.NO:
|
):
|
||||||
formatted.append(src)
|
sources_to_cache.append(src)
|
||||||
report.done(src, changed)
|
report.done(src, changed)
|
||||||
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 in (WriteBack.YES, WriteBack.CHECK) and formatted:
|
if sources_to_cache:
|
||||||
write_cache(cache, formatted, line_length, mode)
|
write_cache(cache, sources_to_cache, line_length, mode)
|
||||||
|
|
||||||
|
|
||||||
def format_file_in_place(
|
def format_file_in_place(
|
||||||
|
Loading…
Reference in New Issue
Block a user