All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
Also, sort cached file output to be (more) deterministic.
py36=py36, pyi=pyi, skip_string_normalization=skip_string_normalization
)
report = Report(check=check, quiet=quiet, verbose=verbose)
py36=py36, pyi=pyi, skip_string_normalization=skip_string_normalization
)
report = Report(check=check, quiet=quiet, verbose=verbose)
- sources: List[Path] = []
+ sources: Set[Path] = set()
try:
include_regex = re.compile(include)
except re.error:
try:
include_regex = re.compile(include)
except re.error:
for s in src:
p = Path(s)
if p.is_dir():
for s in src:
p = Path(s)
if p.is_dir():
gen_python_files_in_dir(p, root, include_regex, exclude_regex, report)
)
elif p.is_file() or s == "-":
# if a file was explicitly given, we don't care about its extension
gen_python_files_in_dir(p, root, include_regex, exclude_regex, report)
)
elif p.is_file() or s == "-":
# if a file was explicitly given, we don't care about its extension
else:
err(f"invalid path: {s}")
if len(sources) == 0:
else:
err(f"invalid path: {s}")
if len(sources) == 0:
elif len(sources) == 1:
reformat_one(
elif len(sources) == 1:
reformat_one(
line_length=line_length,
fast=fast,
write_back=write_back,
line_length=line_length,
fast=fast,
write_back=write_back,
async def schedule_formatting(
async def schedule_formatting(
line_length: int,
fast: bool,
write_back: WriteBack,
line_length: int,
fast: bool,
write_back: WriteBack,
if write_back != WriteBack.DIFF:
cache = read_cache(line_length, mode)
sources, cached = filter_cached(cache, sources)
if write_back != WriteBack.DIFF:
cache = read_cache(line_length, mode)
sources, cached = filter_cached(cache, sources)
+ for src in sorted(cached):
report.done(src, Changed.CACHED)
cancelled = []
formatted = []
report.done(src, Changed.CACHED)
cancelled = []
formatted = []
return stat.st_mtime, stat.st_size
return stat.st_mtime, stat.st_size
-def filter_cached(
- cache: Cache, sources: Iterable[Path]
-) -> Tuple[List[Path], List[Path]]:
- """Split a list of paths into two.
+def filter_cached(cache: Cache, sources: Iterable[Path]) -> Tuple[Set[Path], Set[Path]]:
+ """Split an iterable of paths in `sources` into two sets.
- The first list contains paths of files that modified on disk or are not in the
- cache. The other list contains paths to non-modified files.
+ The first contains paths of files that modified on disk or are not in the
+ cache. The other contains paths to non-modified files.
+ todo, done = set(), set()
for src in sources:
src = src.resolve()
if cache.get(src) != get_cache_info(src):
for src in sources:
src = src.resolve()
if cache.get(src) != get_cache_info(src):
return todo, done
def write_cache(
return todo, done
def write_cache(
- cache: Cache, sources: List[Path], line_length: int, mode: FileMode
+ cache: Cache, sources: Iterable[Path], line_length: int, mode: FileMode
) -> None:
"""Update the cache file."""
cache_file = get_cache_file(line_length, mode)
) -> None:
"""Update the cache file."""
cache_file = get_cache_file(line_length, mode)
cached_but_changed.touch()
cache = {cached: black.get_cache_info(cached), cached_but_changed: (0.0, 0)}
todo, done = black.filter_cached(
cached_but_changed.touch()
cache = {cached: black.get_cache_info(cached), cached_but_changed: (0.0, 0)}
todo, done = black.filter_cached(
- cache, [uncached, cached, cached_but_changed]
+ cache, {uncached, cached, cached_but_changed}
- self.assertEqual(todo, [uncached, cached_but_changed])
- self.assertEqual(done, [cached])
+ self.assertEqual(todo, {uncached, cached_but_changed})
+ self.assertEqual(done, {cached})
def test_write_cache_creates_directory_if_needed(self) -> None:
mode = black.FileMode.AUTO_DETECT
def test_write_cache_creates_directory_if_needed(self) -> None:
mode = black.FileMode.AUTO_DETECT