From 68ebb61f7bd332fc7698176afb2128d53fc36c55 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Mon, 2 Feb 2026 00:47:29 +0900 Subject: [PATCH] fix: Include hard_deps in git commit (#6940) Bug: update_lib quick ast was not committing _ast_unparse.py because git_commit() only added lib_path and test_paths, but not hard_deps. Fixed by: - Add hard_deps parameter to git_commit() - Collect hard_deps from DEPENDENCIES in main() - Add hard_deps to paths_to_add in git_commit() --- scripts/update_lib/cmd_quick.py | 25 ++++++++++- scripts/update_lib/tests/test_quick.py | 58 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/scripts/update_lib/cmd_quick.py b/scripts/update_lib/cmd_quick.py index 939ad50b7..a56d8f57d 100644 --- a/scripts/update_lib/cmd_quick.py +++ b/scripts/update_lib/cmd_quick.py @@ -31,7 +31,7 @@ import sys sys.path.insert(0, str(pathlib.Path(__file__).parent.parent)) -from update_lib.deps import get_test_paths +from update_lib.deps import DEPENDENCIES, get_test_paths from update_lib.file_utils import ( construct_lib_path, get_cpython_dir, @@ -194,6 +194,7 @@ def git_commit( lib_path: pathlib.Path | None, test_paths: list[pathlib.Path] | pathlib.Path | None, cpython_dir: pathlib.Path, + hard_deps: list[pathlib.Path] | None = None, verbose: bool = True, ) -> bool: """Commit changes with CPython author. @@ -203,6 +204,7 @@ def git_commit( lib_path: Path to library file/directory (or None) test_paths: Path(s) to test file/directory (or None) cpython_dir: Path to cpython directory + hard_deps: Path(s) to hard dependency files (or None) verbose: Print progress messages Returns: @@ -216,6 +218,10 @@ def git_commit( elif isinstance(test_paths, pathlib.Path): test_paths = [test_paths] + # Normalize hard_deps to list + if hard_deps is None: + hard_deps = [] + # Stage changes paths_to_add = [] if lib_path and lib_path.exists(): @@ -223,6 +229,9 @@ def git_commit( for test_path in test_paths: if test_path and test_path.exists(): paths_to_add.append(str(test_path)) + for dep_path in hard_deps: + if dep_path and dep_path.exists(): + paths_to_add.append(str(dep_path)) if not paths_to_add: return False @@ -362,6 +371,7 @@ def main(argv: list[str] | None = None) -> int: # Track library path for commit lib_file_path = None test_path = None + hard_deps_for_commit = [] # If it's a library path (not test path), do copy_lib first if not is_test_path(src_path): @@ -384,6 +394,13 @@ def main(argv: list[str] | None = None) -> int: if default_test.exists(): test_src_paths = (default_test,) + # Collect hard dependencies for commit + lib_deps = DEPENDENCIES.get(module_name, {}) + for dep_name in lib_deps.get("hard_deps", []): + dep_lib_path = construct_lib_path("Lib", dep_name) + if dep_lib_path.exists(): + hard_deps_for_commit.append(dep_lib_path) + # Process all test paths test_paths_for_commit = [] for test_src in test_src_paths: @@ -422,7 +439,11 @@ def main(argv: list[str] | None = None) -> int: if args.commit: cpython_dir = get_cpython_dir(original_src) git_commit( - get_module_name(original_src), lib_file_path, test_paths, cpython_dir + get_module_name(original_src), + lib_file_path, + test_paths, + cpython_dir, + hard_deps=hard_deps_for_commit, ) return 0 diff --git a/scripts/update_lib/tests/test_quick.py b/scripts/update_lib/tests/test_quick.py index b5354436e..f0262eebd 100644 --- a/scripts/update_lib/tests/test_quick.py +++ b/scripts/update_lib/tests/test_quick.py @@ -199,6 +199,64 @@ class TestGitCommit(unittest.TestCase): result = git_commit("test", None, None, pathlib.Path("cpython"), verbose=False) self.assertFalse(result) + @patch("subprocess.run") + @patch("update_lib.cmd_quick.get_cpython_version") + def test_hard_deps_are_added(self, mock_version, mock_run): + """Test that hard_deps are included in git commit.""" + mock_version.return_value = "v3.14.0" + mock_run.return_value.returncode = 1 # Has changes + + with tempfile.TemporaryDirectory() as tmpdir: + lib_file = pathlib.Path(tmpdir) / "lib.py" + lib_file.write_text("# lib") + test_file = pathlib.Path(tmpdir) / "test.py" + test_file.write_text("# test") + dep_file = pathlib.Path(tmpdir) / "_dep.py" + dep_file.write_text("# dep") + + git_commit( + "test", + lib_file, + test_file, + pathlib.Path("cpython"), + hard_deps=[dep_file], + verbose=False, + ) + + # Check git add was called with all three files + add_call = mock_run.call_args_list[0] + add_args = add_call[0][0] + self.assertIn(str(lib_file), add_args) + self.assertIn(str(test_file), add_args) + self.assertIn(str(dep_file), add_args) + + @patch("subprocess.run") + @patch("update_lib.cmd_quick.get_cpython_version") + def test_nonexistent_hard_deps_not_added(self, mock_version, mock_run): + """Test that nonexistent hard_deps don't cause errors.""" + mock_version.return_value = "v3.14.0" + mock_run.return_value.returncode = 1 # Has changes + + with tempfile.TemporaryDirectory() as tmpdir: + lib_file = pathlib.Path(tmpdir) / "lib.py" + lib_file.write_text("# lib") + nonexistent_dep = pathlib.Path(tmpdir) / "nonexistent.py" + + git_commit( + "test", + lib_file, + None, + pathlib.Path("cpython"), + hard_deps=[nonexistent_dep], + verbose=False, + ) + + # Check git add was called with only lib_file + add_call = mock_run.call_args_list[0] + add_args = add_call[0][0] + self.assertIn(str(lib_file), add_args) + self.assertNotIn(str(nonexistent_dep), add_args) + class TestQuickTestRunFailure(unittest.TestCase): """Tests for quick() behavior when test run fails."""