From f8fa4ed78fecbfef9ab2e5c28f9d991ffb13896f Mon Sep 17 00:00:00 2001 From: dankrzeminski32 Date: Thu, 15 Feb 2024 10:43:26 -0600 Subject: [PATCH 01/10] lists reformats with check and quiet --- src/black/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index f82b9fec5b7..e79de23bd51 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -709,7 +709,11 @@ def main( # noqa: C901 workers=workers, ) - if verbose or not quiet: + if ( + verbose + or not quiet + or (report.change_count > 0 and write_back is WriteBack.CHECK and code is None) + ): if code is None and (verbose or report.change_count or report.failure_count): out() out(error_msg if report.return_code else "All done! ✨ 🍰 ✨") From b2b448fd8af0d3a1c62f359c236dcbde985abf68 Mon Sep 17 00:00:00 2001 From: dankrzeminski32 Date: Thu, 15 Feb 2024 12:23:08 -0600 Subject: [PATCH 02/10] test case --- tests/test_black.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_black.py b/tests/test_black.py index 41f87cd16f8..29c6f196a43 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -706,6 +706,13 @@ def err(msg: str, **kwargs: Any) -> None: " files would fail to reformat.", ) + def test_quiet_check_with_potential_reformats(self) -> None: + p = THIS_DIR / "data" / "cases" / "collections.py" + error_msg = "\nOh no! 💥 💔 💥\n1 file would be reformatted.\n" + args = [str(p), "--check", "--quiet"] + result = CliRunner().invoke(black.main, args) + self.compare_results(result, error_msg, 1) + def test_report_normal(self) -> None: report = black.Report() out_lines = [] From 2ac51f421eabecb7c2413d98b9f43d0d29554c85 Mon Sep 17 00:00:00 2001 From: dankrzeminski32 Date: Thu, 15 Feb 2024 12:37:30 -0600 Subject: [PATCH 03/10] add to changes.md --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index bcf6eb44fdb..d9ee4750427 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -32,6 +32,8 @@ ### Output +- print reformat info when black is called with --quiet and --check and potential +adjustments are found (#4236) ### _Blackd_ From deea63dd5b708e78d17ad0f0e1ed24eb92b6db39 Mon Sep 17 00:00:00 2001 From: dankrzeminski32 Date: Thu, 15 Feb 2024 13:05:05 -0600 Subject: [PATCH 04/10] doc adjustment --- docs/usage_and_configuration/the_basics.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/usage_and_configuration/the_basics.md b/docs/usage_and_configuration/the_basics.md index ea7a2dae5ce..4f8a7ef796f 100644 --- a/docs/usage_and_configuration/the_basics.md +++ b/docs/usage_and_configuration/the_basics.md @@ -183,6 +183,8 @@ Don't write the files back, just return the status. _Black_ will exit with: - code 1 if some files would be reformatted; or - code 123 if there was an internal error +If used in combination with `--quiet` then only the exit code will be returned. + ```console $ black test.py --check All done! ✨ 🍰 ✨ From f2c9607c0868d3a121433af49f0956634a62bf8a Mon Sep 17 00:00:00 2001 From: dankrzeminski32 Date: Thu, 15 Feb 2024 13:05:21 -0600 Subject: [PATCH 05/10] revert changes --- src/black/__init__.py | 6 +----- tests/test_black.py | 32 +++++++++++++++----------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index e79de23bd51..f82b9fec5b7 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -709,11 +709,7 @@ def main( # noqa: C901 workers=workers, ) - if ( - verbose - or not quiet - or (report.change_count > 0 and write_back is WriteBack.CHECK and code is None) - ): + if verbose or not quiet: if code is None and (verbose or report.change_count or report.failure_count): out() out(error_msg if report.return_code else "All done! ✨ 🍰 ✨") diff --git a/tests/test_black.py b/tests/test_black.py index 29c6f196a43..68ac90fdca3 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -483,9 +483,11 @@ def _mocked_calls() -> bool: return _mocked_calls - with patch("pathlib.Path.iterdir", return_value=target_contents), patch( - "pathlib.Path.resolve", return_value=target_abspath - ), patch("pathlib.Path.is_dir", side_effect=mock_n_calls([True])): + with ( + patch("pathlib.Path.iterdir", return_value=target_contents), + patch("pathlib.Path.resolve", return_value=target_abspath), + patch("pathlib.Path.is_dir", side_effect=mock_n_calls([True])), + ): # Note that the root folder (project_root) isn't the folder # named "root" (aka working_directory) report = MagicMock(verbose=True) @@ -706,13 +708,6 @@ def err(msg: str, **kwargs: Any) -> None: " files would fail to reformat.", ) - def test_quiet_check_with_potential_reformats(self) -> None: - p = THIS_DIR / "data" / "cases" / "collections.py" - error_msg = "\nOh no! 💥 💔 💥\n1 file would be reformatted.\n" - args = [str(p), "--check", "--quiet"] - result = CliRunner().invoke(black.main, args) - self.compare_results(result, error_msg, 1) - def test_report_normal(self) -> None: report = black.Report() out_lines = [] @@ -2139,8 +2134,9 @@ def test_cache_single_file_already_cached(self) -> None: @event_loop() def test_cache_multiple_files(self) -> None: mode = DEFAULT_MODE - with cache_dir() as workspace, patch( - "concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor + with ( + cache_dir() as workspace, + patch("concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor), ): one = (workspace / "one.py").resolve() one.write_text("print('hello')", encoding="utf-8") @@ -2162,9 +2158,10 @@ def test_no_cache_when_writeback_diff(self, color: bool) -> None: with cache_dir() as workspace: src = (workspace / "test.py").resolve() src.write_text("print('hello')", encoding="utf-8") - with patch.object(black.Cache, "read") as read_cache, patch.object( - black.Cache, "write" - ) as write_cache: + with ( + patch.object(black.Cache, "read") as read_cache, + patch.object(black.Cache, "write") as write_cache, + ): cmd = [str(src), "--diff"] if color: cmd.append("--color") @@ -2293,8 +2290,9 @@ def test_write_cache_creates_directory_if_needed(self) -> None: @event_loop() def test_failed_formatting_does_not_get_cached(self) -> None: mode = DEFAULT_MODE - with cache_dir() as workspace, patch( - "concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor + with ( + cache_dir() as workspace, + patch("concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor), ): failing = (workspace / "failing.py").resolve() failing.write_text("not actually python", encoding="utf-8") From 128a8a7525c8602f997842f19e2f24e5bb1e3cfc Mon Sep 17 00:00:00 2001 From: dankrzeminski32 Date: Thu, 15 Feb 2024 13:06:29 -0600 Subject: [PATCH 06/10] update changes.md --- CHANGES.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d9ee4750427..e0281b52838 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -32,8 +32,6 @@ ### Output -- print reformat info when black is called with --quiet and --check and potential -adjustments are found (#4236) ### _Blackd_ @@ -46,6 +44,7 @@ adjustments are found (#4236) ### Documentation +- Note what happens when --check is called with --quiet (#4236) From 006a74c0bc8a639382073cff0f6c96d5e867bdcc Mon Sep 17 00:00:00 2001 From: dankrzeminski32 Date: Thu, 15 Feb 2024 13:08:39 -0600 Subject: [PATCH 07/10] undo formatting --- tests/test_black.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/tests/test_black.py b/tests/test_black.py index 68ac90fdca3..41f87cd16f8 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -483,11 +483,9 @@ def _mocked_calls() -> bool: return _mocked_calls - with ( - patch("pathlib.Path.iterdir", return_value=target_contents), - patch("pathlib.Path.resolve", return_value=target_abspath), - patch("pathlib.Path.is_dir", side_effect=mock_n_calls([True])), - ): + with patch("pathlib.Path.iterdir", return_value=target_contents), patch( + "pathlib.Path.resolve", return_value=target_abspath + ), patch("pathlib.Path.is_dir", side_effect=mock_n_calls([True])): # Note that the root folder (project_root) isn't the folder # named "root" (aka working_directory) report = MagicMock(verbose=True) @@ -2134,9 +2132,8 @@ def test_cache_single_file_already_cached(self) -> None: @event_loop() def test_cache_multiple_files(self) -> None: mode = DEFAULT_MODE - with ( - cache_dir() as workspace, - patch("concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor), + with cache_dir() as workspace, patch( + "concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor ): one = (workspace / "one.py").resolve() one.write_text("print('hello')", encoding="utf-8") @@ -2158,10 +2155,9 @@ def test_no_cache_when_writeback_diff(self, color: bool) -> None: with cache_dir() as workspace: src = (workspace / "test.py").resolve() src.write_text("print('hello')", encoding="utf-8") - with ( - patch.object(black.Cache, "read") as read_cache, - patch.object(black.Cache, "write") as write_cache, - ): + with patch.object(black.Cache, "read") as read_cache, patch.object( + black.Cache, "write" + ) as write_cache: cmd = [str(src), "--diff"] if color: cmd.append("--color") @@ -2290,9 +2286,8 @@ def test_write_cache_creates_directory_if_needed(self) -> None: @event_loop() def test_failed_formatting_does_not_get_cached(self) -> None: mode = DEFAULT_MODE - with ( - cache_dir() as workspace, - patch("concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor), + with cache_dir() as workspace, patch( + "concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor ): failing = (workspace / "failing.py").resolve() failing.write_text("not actually python", encoding="utf-8") From c277cde3f83679eb6a96eb451d190b03c44d5bad Mon Sep 17 00:00:00 2001 From: Daniel Krzeminski Date: Thu, 15 Feb 2024 13:09:14 -0600 Subject: [PATCH 08/10] Update docs/usage_and_configuration/the_basics.md Co-authored-by: Jelle Zijlstra --- docs/usage_and_configuration/the_basics.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/usage_and_configuration/the_basics.md b/docs/usage_and_configuration/the_basics.md index 4f8a7ef796f..bcb44b403a2 100644 --- a/docs/usage_and_configuration/the_basics.md +++ b/docs/usage_and_configuration/the_basics.md @@ -183,7 +183,8 @@ Don't write the files back, just return the status. _Black_ will exit with: - code 1 if some files would be reformatted; or - code 123 if there was an internal error -If used in combination with `--quiet` then only the exit code will be returned. +If used in combination with `--quiet` then only the exit code will be returned, +unless there was an internal error. ```console $ black test.py --check From 81fa917592adbd81432860f44edbe23d9a605469 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 15 Feb 2024 19:09:37 +0000 Subject: [PATCH 09/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/usage_and_configuration/the_basics.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/usage_and_configuration/the_basics.md b/docs/usage_and_configuration/the_basics.md index bcb44b403a2..7aa8a644bea 100644 --- a/docs/usage_and_configuration/the_basics.md +++ b/docs/usage_and_configuration/the_basics.md @@ -183,8 +183,8 @@ Don't write the files back, just return the status. _Black_ will exit with: - code 1 if some files would be reformatted; or - code 123 if there was an internal error -If used in combination with `--quiet` then only the exit code will be returned, -unless there was an internal error. +If used in combination with `--quiet` then only the exit code will be returned, unless +there was an internal error. ```console $ black test.py --check From cdd2b24c8829bcda591ca2c901c0b0fa2844cf19 Mon Sep 17 00:00:00 2001 From: Daniel Krzeminski Date: Thu, 15 Feb 2024 13:20:54 -0600 Subject: [PATCH 10/10] Update CHANGES.md Co-authored-by: Jelle Zijlstra --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index e0281b52838..cd83cbdb640 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -44,7 +44,7 @@ ### Documentation -- Note what happens when --check is called with --quiet (#4236) +- Note what happens when `--check` is used with `--quiet` (#4236)