Skip to content

Commit 68ebb61

Browse files
authored
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()
1 parent d907922 commit 68ebb61

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

scripts/update_lib/cmd_quick.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
sys.path.insert(0, str(pathlib.Path(__file__).parent.parent))
3333

34-
from update_lib.deps import get_test_paths
34+
from update_lib.deps import DEPENDENCIES, get_test_paths
3535
from update_lib.file_utils import (
3636
construct_lib_path,
3737
get_cpython_dir,
@@ -194,6 +194,7 @@ def git_commit(
194194
lib_path: pathlib.Path | None,
195195
test_paths: list[pathlib.Path] | pathlib.Path | None,
196196
cpython_dir: pathlib.Path,
197+
hard_deps: list[pathlib.Path] | None = None,
197198
verbose: bool = True,
198199
) -> bool:
199200
"""Commit changes with CPython author.
@@ -203,6 +204,7 @@ def git_commit(
203204
lib_path: Path to library file/directory (or None)
204205
test_paths: Path(s) to test file/directory (or None)
205206
cpython_dir: Path to cpython directory
207+
hard_deps: Path(s) to hard dependency files (or None)
206208
verbose: Print progress messages
207209
208210
Returns:
@@ -216,13 +218,20 @@ def git_commit(
216218
elif isinstance(test_paths, pathlib.Path):
217219
test_paths = [test_paths]
218220

221+
# Normalize hard_deps to list
222+
if hard_deps is None:
223+
hard_deps = []
224+
219225
# Stage changes
220226
paths_to_add = []
221227
if lib_path and lib_path.exists():
222228
paths_to_add.append(str(lib_path))
223229
for test_path in test_paths:
224230
if test_path and test_path.exists():
225231
paths_to_add.append(str(test_path))
232+
for dep_path in hard_deps:
233+
if dep_path and dep_path.exists():
234+
paths_to_add.append(str(dep_path))
226235

227236
if not paths_to_add:
228237
return False
@@ -362,6 +371,7 @@ def main(argv: list[str] | None = None) -> int:
362371
# Track library path for commit
363372
lib_file_path = None
364373
test_path = None
374+
hard_deps_for_commit = []
365375

366376
# If it's a library path (not test path), do copy_lib first
367377
if not is_test_path(src_path):
@@ -384,6 +394,13 @@ def main(argv: list[str] | None = None) -> int:
384394
if default_test.exists():
385395
test_src_paths = (default_test,)
386396

397+
# Collect hard dependencies for commit
398+
lib_deps = DEPENDENCIES.get(module_name, {})
399+
for dep_name in lib_deps.get("hard_deps", []):
400+
dep_lib_path = construct_lib_path("Lib", dep_name)
401+
if dep_lib_path.exists():
402+
hard_deps_for_commit.append(dep_lib_path)
403+
387404
# Process all test paths
388405
test_paths_for_commit = []
389406
for test_src in test_src_paths:
@@ -422,7 +439,11 @@ def main(argv: list[str] | None = None) -> int:
422439
if args.commit:
423440
cpython_dir = get_cpython_dir(original_src)
424441
git_commit(
425-
get_module_name(original_src), lib_file_path, test_paths, cpython_dir
442+
get_module_name(original_src),
443+
lib_file_path,
444+
test_paths,
445+
cpython_dir,
446+
hard_deps=hard_deps_for_commit,
426447
)
427448

428449
return 0

scripts/update_lib/tests/test_quick.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,64 @@ def test_both_none_returns_false(self):
199199
result = git_commit("test", None, None, pathlib.Path("cpython"), verbose=False)
200200
self.assertFalse(result)
201201

202+
@patch("subprocess.run")
203+
@patch("update_lib.cmd_quick.get_cpython_version")
204+
def test_hard_deps_are_added(self, mock_version, mock_run):
205+
"""Test that hard_deps are included in git commit."""
206+
mock_version.return_value = "v3.14.0"
207+
mock_run.return_value.returncode = 1 # Has changes
208+
209+
with tempfile.TemporaryDirectory() as tmpdir:
210+
lib_file = pathlib.Path(tmpdir) / "lib.py"
211+
lib_file.write_text("# lib")
212+
test_file = pathlib.Path(tmpdir) / "test.py"
213+
test_file.write_text("# test")
214+
dep_file = pathlib.Path(tmpdir) / "_dep.py"
215+
dep_file.write_text("# dep")
216+
217+
git_commit(
218+
"test",
219+
lib_file,
220+
test_file,
221+
pathlib.Path("cpython"),
222+
hard_deps=[dep_file],
223+
verbose=False,
224+
)
225+
226+
# Check git add was called with all three files
227+
add_call = mock_run.call_args_list[0]
228+
add_args = add_call[0][0]
229+
self.assertIn(str(lib_file), add_args)
230+
self.assertIn(str(test_file), add_args)
231+
self.assertIn(str(dep_file), add_args)
232+
233+
@patch("subprocess.run")
234+
@patch("update_lib.cmd_quick.get_cpython_version")
235+
def test_nonexistent_hard_deps_not_added(self, mock_version, mock_run):
236+
"""Test that nonexistent hard_deps don't cause errors."""
237+
mock_version.return_value = "v3.14.0"
238+
mock_run.return_value.returncode = 1 # Has changes
239+
240+
with tempfile.TemporaryDirectory() as tmpdir:
241+
lib_file = pathlib.Path(tmpdir) / "lib.py"
242+
lib_file.write_text("# lib")
243+
nonexistent_dep = pathlib.Path(tmpdir) / "nonexistent.py"
244+
245+
git_commit(
246+
"test",
247+
lib_file,
248+
None,
249+
pathlib.Path("cpython"),
250+
hard_deps=[nonexistent_dep],
251+
verbose=False,
252+
)
253+
254+
# Check git add was called with only lib_file
255+
add_call = mock_run.call_args_list[0]
256+
add_args = add_call[0][0]
257+
self.assertIn(str(lib_file), add_args)
258+
self.assertNotIn(str(nonexistent_dep), add_args)
259+
202260

203261
class TestQuickTestRunFailure(unittest.TestCase):
204262
"""Tests for quick() behavior when test run fails."""

0 commit comments

Comments
 (0)