primer: Add --no-diff
option (#2187)
- Allow runs with no code diff output - This is handy for reducing output to see which file is erroring Test: - Edit config for 'channels' to expect no changes and run with `--no-diff` and see no diff output
This commit is contained in:
parent
a669b64091
commit
a18c7bc099
@ -5,6 +5,7 @@
|
|||||||
#### _Black_
|
#### _Black_
|
||||||
|
|
||||||
- Set `--pyi` mode if `--stdin-filename` ends in `.pyi` (#2169)
|
- Set `--pyi` mode if `--stdin-filename` ends in `.pyi` (#2169)
|
||||||
|
- Add `--no-diff` to black-primer to suppress formatting changes (#2187)
|
||||||
|
|
||||||
### 21.4b2
|
### 21.4b2
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ async def async_main(
|
|||||||
debug: bool,
|
debug: bool,
|
||||||
keep: bool,
|
keep: bool,
|
||||||
long_checkouts: bool,
|
long_checkouts: bool,
|
||||||
|
no_diff: bool,
|
||||||
rebase: bool,
|
rebase: bool,
|
||||||
workdir: str,
|
workdir: str,
|
||||||
workers: int,
|
workers: int,
|
||||||
@ -54,7 +55,13 @@ async def async_main(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
ret_val = await lib.process_queue(
|
ret_val = await lib.process_queue(
|
||||||
config, work_path, workers, keep, long_checkouts, rebase
|
config,
|
||||||
|
work_path,
|
||||||
|
workers,
|
||||||
|
keep,
|
||||||
|
long_checkouts,
|
||||||
|
rebase,
|
||||||
|
no_diff,
|
||||||
)
|
)
|
||||||
return int(ret_val)
|
return int(ret_val)
|
||||||
finally:
|
finally:
|
||||||
@ -95,6 +102,12 @@ async def async_main(
|
|||||||
show_default=True,
|
show_default=True,
|
||||||
help="Pull big projects to test",
|
help="Pull big projects to test",
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--no-diff",
|
||||||
|
is_flag=True,
|
||||||
|
show_default=True,
|
||||||
|
help="Disable showing source file changes in black output",
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"-R",
|
"-R",
|
||||||
"--rebase",
|
"--rebase",
|
||||||
|
@ -112,13 +112,20 @@ def analyze_results(project_count: int, results: Results) -> int:
|
|||||||
|
|
||||||
|
|
||||||
async def black_run(
|
async def black_run(
|
||||||
repo_path: Path, project_config: Dict[str, Any], results: Results
|
repo_path: Path,
|
||||||
|
project_config: Dict[str, Any],
|
||||||
|
results: Results,
|
||||||
|
no_diff: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Run Black and record failures"""
|
"""Run Black and record failures"""
|
||||||
cmd = [str(which(BLACK_BINARY))]
|
cmd = [str(which(BLACK_BINARY))]
|
||||||
if "cli_arguments" in project_config and project_config["cli_arguments"]:
|
if "cli_arguments" in project_config and project_config["cli_arguments"]:
|
||||||
cmd.extend(*project_config["cli_arguments"])
|
cmd.extend(*project_config["cli_arguments"])
|
||||||
cmd.extend(["--check", "--diff", "."])
|
cmd.append("--check")
|
||||||
|
if no_diff:
|
||||||
|
cmd.append(".")
|
||||||
|
else:
|
||||||
|
cmd.extend(["--diff", "."])
|
||||||
|
|
||||||
with TemporaryDirectory() as tmp_path:
|
with TemporaryDirectory() as tmp_path:
|
||||||
# Prevent reading top-level user configs by manipulating envionment variables
|
# Prevent reading top-level user configs by manipulating envionment variables
|
||||||
@ -246,6 +253,7 @@ async def project_runner(
|
|||||||
long_checkouts: bool = False,
|
long_checkouts: bool = False,
|
||||||
rebase: bool = False,
|
rebase: bool = False,
|
||||||
keep: bool = False,
|
keep: bool = False,
|
||||||
|
no_diff: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Check out project and run Black on it + record result"""
|
"""Check out project and run Black on it + record result"""
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
@ -284,7 +292,7 @@ async def project_runner(
|
|||||||
repo_path = await git_checkout_or_rebase(work_path, project_config, rebase)
|
repo_path = await git_checkout_or_rebase(work_path, project_config, rebase)
|
||||||
if not repo_path:
|
if not repo_path:
|
||||||
continue
|
continue
|
||||||
await black_run(repo_path, project_config, results)
|
await black_run(repo_path, project_config, results, no_diff)
|
||||||
|
|
||||||
if not keep:
|
if not keep:
|
||||||
LOG.debug(f"Removing {repo_path}")
|
LOG.debug(f"Removing {repo_path}")
|
||||||
@ -303,6 +311,7 @@ async def process_queue(
|
|||||||
keep: bool = False,
|
keep: bool = False,
|
||||||
long_checkouts: bool = False,
|
long_checkouts: bool = False,
|
||||||
rebase: bool = False,
|
rebase: bool = False,
|
||||||
|
no_diff: bool = False,
|
||||||
) -> int:
|
) -> int:
|
||||||
"""
|
"""
|
||||||
Process the queue with X workers and evaluate results
|
Process the queue with X workers and evaluate results
|
||||||
@ -330,7 +339,15 @@ async def process_queue(
|
|||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
*[
|
*[
|
||||||
project_runner(
|
project_runner(
|
||||||
i, config, queue, work_path, results, long_checkouts, rebase, keep
|
i,
|
||||||
|
config,
|
||||||
|
queue,
|
||||||
|
work_path,
|
||||||
|
results,
|
||||||
|
long_checkouts,
|
||||||
|
rebase,
|
||||||
|
keep,
|
||||||
|
no_diff,
|
||||||
)
|
)
|
||||||
for i in range(workers)
|
for i in range(workers)
|
||||||
]
|
]
|
||||||
|
@ -198,6 +198,7 @@ def test_async_main(self) -> None:
|
|||||||
"rebase": False,
|
"rebase": False,
|
||||||
"workdir": str(work_dir),
|
"workdir": str(work_dir),
|
||||||
"workers": 69,
|
"workers": 69,
|
||||||
|
"no_diff": False,
|
||||||
}
|
}
|
||||||
with patch("black_primer.cli.lib.process_queue", return_zero):
|
with patch("black_primer.cli.lib.process_queue", return_zero):
|
||||||
return_val = loop.run_until_complete(cli.async_main(**args))
|
return_val = loop.run_until_complete(cli.async_main(**args))
|
||||||
|
Loading…
Reference in New Issue
Block a user