Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions scripts/update_lib/cmd_quick.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

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,
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -216,13 +218,20 @@ 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():
paths_to_add.append(str(lib_path))
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
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
58 changes: 58 additions & 0 deletions scripts/update_lib/tests/test_quick.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,64 @@ def test_both_none_returns_false(self):
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."""
Expand Down
Loading