Skip to content

Commit 6a3643c

Browse files
authored
Improve deps output (#6874)
* Improve deps output: [x]/[ ] sync status, TODO counts - Replace ambiguous [+] with [x] (synced) / [ ] (not synced) - Add (TODO: n) suffix for test files with expectedFailure/skip markers * Refactor update_lib: extract shared utilities
1 parent 93b26bf commit 6a3643c

17 files changed

+528
-572
lines changed

scripts/update_lib/__main__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,39 +63,39 @@ def main(argv: list[str] | None = None) -> int:
6363
args, remaining = parser.parse_known_args(argv)
6464

6565
if args.command == "quick":
66-
from update_lib.quick import main as quick_main
66+
from update_lib.cmd_quick import main as quick_main
6767

6868
return quick_main(remaining)
6969

7070
if args.command == "copy-lib":
71-
from update_lib.copy_lib import main as copy_lib_main
71+
from update_lib.cmd_copy_lib import main as copy_lib_main
7272

7373
return copy_lib_main(remaining)
7474

7575
if args.command == "migrate":
76-
from update_lib.migrate import main as migrate_main
76+
from update_lib.cmd_migrate import main as migrate_main
7777

7878
return migrate_main(remaining)
7979

8080
if args.command == "patches":
81-
from update_lib.patches import main as patches_main
81+
from update_lib.cmd_patches import main as patches_main
8282

8383
return patches_main(remaining)
8484

8585
if args.command == "auto-mark":
86-
from update_lib.auto_mark import main as auto_mark_main
86+
from update_lib.cmd_auto_mark import main as cmd_auto_mark_main
8787

88-
return auto_mark_main(remaining)
88+
return cmd_auto_mark_main(remaining)
8989

9090
if args.command == "deps":
91-
from update_lib.show_deps import main as show_deps_main
91+
from update_lib.cmd_deps import main as cmd_deps_main
9292

93-
return show_deps_main(remaining)
93+
return cmd_deps_main(remaining)
9494

9595
if args.command == "todo":
96-
from update_lib.show_todo import main as show_todo_main
96+
from update_lib.cmd_todo import main as cmd_todo_main
9797

98-
return show_todo_main(remaining)
98+
return cmd_todo_main(remaining)
9999

100100
return 0
101101

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
sys.path.insert(0, str(pathlib.Path(__file__).parent.parent))
2020

2121
from update_lib import COMMENT, PatchSpec, UtMethod, apply_patches
22-
from update_lib.path import test_name_from_path
22+
from update_lib.file_utils import get_test_module_name
2323

2424

2525
class TestRunError(Exception):
@@ -455,7 +455,7 @@ def extract_test_methods(contents: str) -> set[tuple[str, str]]:
455455
Returns:
456456
Set of (class_name, method_name) tuples
457457
"""
458-
from update_lib.io_utils import safe_parse_ast
458+
from update_lib.file_utils import safe_parse_ast
459459
from update_lib.patch_spec import iter_tests
460460

461461
tree = safe_parse_ast(contents)
@@ -490,7 +490,7 @@ def auto_mark_file(
490490
if not test_path.exists():
491491
raise FileNotFoundError(f"File not found: {test_path}")
492492

493-
test_name = test_name_from_path(test_path)
493+
test_name = get_test_module_name(test_path)
494494
if verbose:
495495
print(f"Running test: {test_name}")
496496

@@ -587,7 +587,7 @@ def auto_mark_directory(
587587
if not test_dir.is_dir():
588588
raise ValueError(f"Not a directory: {test_dir}")
589589

590-
test_name = test_name_from_path(test_dir)
590+
test_name = get_test_module_name(test_dir)
591591
if verbose:
592592
print(f"Running test: {test_name}")
593593

@@ -610,7 +610,7 @@ def auto_mark_directory(
610610

611611
for test_file in test_files:
612612
# Get module prefix for this file (e.g., "test_inspect.test_inspect")
613-
module_prefix = test_name_from_path(test_file)
613+
module_prefix = get_test_module_name(test_file)
614614
# For __init__.py, the test path doesn't include "__init__"
615615
if module_prefix.endswith(".__init__"):
616616
module_prefix = module_prefix[:-9] # Remove ".__init__"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def copy_lib(
6060
verbose: Print progress messages
6161
"""
6262
from update_lib.deps import get_lib_paths
63-
from update_lib.path import parse_lib_path
63+
from update_lib.file_utils import parse_lib_path
6464

6565
# Extract module name and cpython prefix from path
6666
path_str = str(src_path).replace("\\", "/")
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,12 @@ def format_deps(
189189
"""
190190
from update_lib.deps import (
191191
DEPENDENCIES,
192+
count_test_todos,
192193
find_dependent_tests_tree,
193194
get_lib_paths,
194195
get_test_paths,
196+
is_path_synced,
197+
is_test_up_to_date,
195198
resolve_hard_dep_parent,
196199
)
197200

@@ -216,13 +219,20 @@ def format_deps(
216219
lib_paths = get_lib_paths(name, cpython_prefix)
217220
existing_lib_paths = [p for p in lib_paths if p.exists()]
218221
for p in existing_lib_paths:
219-
lines.append(f"[+] lib: {p}")
222+
synced = is_path_synced(p, cpython_prefix, lib_prefix)
223+
marker = "[x]" if synced else "[ ]"
224+
lines.append(f"{marker} lib: {p}")
220225

221226
# test paths (only show existing)
222227
test_paths = get_test_paths(name, cpython_prefix)
223228
existing_test_paths = [p for p in test_paths if p.exists()]
224229
for p in existing_test_paths:
225-
lines.append(f"[+] test: {p}")
230+
test_name = p.stem if p.is_file() else p.name
231+
synced = is_test_up_to_date(test_name, cpython_prefix, lib_prefix)
232+
marker = "[x]" if synced else "[ ]"
233+
todo_count = count_test_todos(test_name, lib_prefix)
234+
todo_suffix = f" (TODO: {todo_count})" if todo_count > 0 else ""
235+
lines.append(f"{marker} test: {p}{todo_suffix}")
226236

227237
# If no lib or test paths exist, module doesn't exist
228238
if not existing_lib_paths and not existing_test_paths:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
sys.path.insert(0, str(pathlib.Path(__file__).parent.parent))
1919

20-
from update_lib.path import parse_lib_path
20+
from update_lib.file_utils import parse_lib_path
2121

2222

2323
def patch_single_content(
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@
3232
sys.path.insert(0, str(pathlib.Path(__file__).parent.parent))
3333

3434
from update_lib.deps import get_test_paths
35-
from update_lib.io_utils import safe_read_text
36-
from update_lib.path import (
35+
from update_lib.file_utils import (
3736
construct_lib_path,
37+
get_cpython_dir,
3838
get_module_name,
3939
get_test_files,
4040
is_lib_path,
4141
is_test_path,
4242
lib_to_test_path,
4343
parse_lib_path,
4444
resolve_module_path,
45+
safe_read_text,
4546
)
4647

4748

@@ -55,7 +56,7 @@ def collect_original_methods(
5556
- For file: set of (class_name, method_name) or None if file doesn't exist
5657
- For directory: dict mapping file path to set of methods, or None if dir doesn't exist
5758
"""
58-
from update_lib.auto_mark import extract_test_methods
59+
from update_lib.cmd_auto_mark import extract_test_methods
5960

6061
if not lib_path.exists():
6162
return None
@@ -91,8 +92,8 @@ def quick(
9192
verbose: Print progress messages
9293
skip_build: Skip cargo build, use pre-built binary
9394
"""
94-
from update_lib.auto_mark import auto_mark_directory, auto_mark_file
95-
from update_lib.migrate import patch_directory, patch_file
95+
from update_lib.cmd_auto_mark import auto_mark_directory, auto_mark_file
96+
from update_lib.cmd_migrate import patch_directory, patch_file
9697

9798
# Determine lib_path and whether to migrate
9899
if is_lib_path(src_path):
@@ -174,22 +175,6 @@ def quick(
174175
print(f"Removed expectedFailure from {num_removed} tests")
175176

176177

177-
def get_cpython_dir(src_path: pathlib.Path) -> pathlib.Path:
178-
"""Extract cpython directory from source path.
179-
180-
Example:
181-
cpython/Lib/dataclasses.py -> cpython
182-
/some/path/cpython/Lib/foo.py -> /some/path/cpython
183-
"""
184-
path_str = str(src_path).replace("\\", "/")
185-
lib_marker = "/Lib/"
186-
if lib_marker in path_str:
187-
idx = path_str.index(lib_marker)
188-
return pathlib.Path(path_str[:idx])
189-
# Shortcut case: assume "cpython"
190-
return pathlib.Path("cpython")
191-
192-
193178
def get_cpython_version(cpython_dir: pathlib.Path) -> str:
194179
"""Get CPython version from git tag."""
195180
import subprocess
@@ -384,7 +369,7 @@ def main(argv: list[str] | None = None) -> int:
384369
lib_file_path = parse_lib_path(src_path)
385370

386371
if args.copy:
387-
from update_lib.copy_lib import copy_lib
372+
from update_lib.cmd_copy_lib import copy_lib
388373

389374
copy_lib(src_path)
390375

@@ -449,7 +434,7 @@ def main(argv: list[str] | None = None) -> int:
449434
return 1
450435
except Exception as e:
451436
# Handle TestRunError with a clean message
452-
from update_lib.auto_mark import TestRunError
437+
from update_lib.cmd_auto_mark import TestRunError
453438

454439
if isinstance(e, TestRunError):
455440
print(f"Error: {e}", file=sys.stderr)

0 commit comments

Comments
 (0)