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
20 changes: 10 additions & 10 deletions scripts/update_lib/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,39 @@ def main(argv: list[str] | None = None) -> int:
args, remaining = parser.parse_known_args(argv)

if args.command == "quick":
from update_lib.quick import main as quick_main
from update_lib.cmd_quick import main as quick_main

return quick_main(remaining)

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

return copy_lib_main(remaining)

if args.command == "migrate":
from update_lib.migrate import main as migrate_main
from update_lib.cmd_migrate import main as migrate_main

return migrate_main(remaining)

if args.command == "patches":
from update_lib.patches import main as patches_main
from update_lib.cmd_patches import main as patches_main

return patches_main(remaining)

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

return auto_mark_main(remaining)
return cmd_auto_mark_main(remaining)

if args.command == "deps":
from update_lib.show_deps import main as show_deps_main
from update_lib.cmd_deps import main as cmd_deps_main

return show_deps_main(remaining)
return cmd_deps_main(remaining)

if args.command == "todo":
from update_lib.show_todo import main as show_todo_main
from update_lib.cmd_todo import main as cmd_todo_main

return show_todo_main(remaining)
return cmd_todo_main(remaining)

return 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
sys.path.insert(0, str(pathlib.Path(__file__).parent.parent))

from update_lib import COMMENT, PatchSpec, UtMethod, apply_patches
from update_lib.path import test_name_from_path
from update_lib.file_utils import get_test_module_name


class TestRunError(Exception):
Expand Down Expand Up @@ -455,7 +455,7 @@ def extract_test_methods(contents: str) -> set[tuple[str, str]]:
Returns:
Set of (class_name, method_name) tuples
"""
from update_lib.io_utils import safe_parse_ast
from update_lib.file_utils import safe_parse_ast
from update_lib.patch_spec import iter_tests

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

test_name = test_name_from_path(test_path)
test_name = get_test_module_name(test_path)
if verbose:
print(f"Running test: {test_name}")

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

test_name = test_name_from_path(test_dir)
test_name = get_test_module_name(test_dir)
if verbose:
print(f"Running test: {test_name}")

Expand All @@ -610,7 +610,7 @@ def auto_mark_directory(

for test_file in test_files:
# Get module prefix for this file (e.g., "test_inspect.test_inspect")
module_prefix = test_name_from_path(test_file)
module_prefix = get_test_module_name(test_file)
# For __init__.py, the test path doesn't include "__init__"
if module_prefix.endswith(".__init__"):
module_prefix = module_prefix[:-9] # Remove ".__init__"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def copy_lib(
verbose: Print progress messages
"""
from update_lib.deps import get_lib_paths
from update_lib.path import parse_lib_path
from update_lib.file_utils import parse_lib_path

# Extract module name and cpython prefix from path
path_str = str(src_path).replace("\\", "/")
Expand Down
14 changes: 12 additions & 2 deletions scripts/update_lib/show_deps.py → scripts/update_lib/cmd_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,12 @@ def format_deps(
"""
from update_lib.deps import (
DEPENDENCIES,
count_test_todos,
find_dependent_tests_tree,
get_lib_paths,
get_test_paths,
is_path_synced,
is_test_up_to_date,
resolve_hard_dep_parent,
)

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

# test paths (only show existing)
test_paths = get_test_paths(name, cpython_prefix)
existing_test_paths = [p for p in test_paths if p.exists()]
for p in existing_test_paths:
lines.append(f"[+] test: {p}")
test_name = p.stem if p.is_file() else p.name
synced = is_test_up_to_date(test_name, cpython_prefix, lib_prefix)
marker = "[x]" if synced else "[ ]"
todo_count = count_test_todos(test_name, lib_prefix)
todo_suffix = f" (TODO: {todo_count})" if todo_count > 0 else ""
lines.append(f"{marker} test: {p}{todo_suffix}")

# If no lib or test paths exist, module doesn't exist
if not existing_lib_paths and not existing_test_paths:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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

from update_lib.path import parse_lib_path
from update_lib.file_utils import parse_lib_path


def patch_single_content(
Expand Down
File renamed without changes.
31 changes: 8 additions & 23 deletions scripts/update_lib/quick.py → scripts/update_lib/cmd_quick.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@
sys.path.insert(0, str(pathlib.Path(__file__).parent.parent))

from update_lib.deps import get_test_paths
from update_lib.io_utils import safe_read_text
from update_lib.path import (
from update_lib.file_utils import (
construct_lib_path,
get_cpython_dir,
get_module_name,
get_test_files,
is_lib_path,
is_test_path,
lib_to_test_path,
parse_lib_path,
resolve_module_path,
safe_read_text,
)


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

if not lib_path.exists():
return None
Expand Down Expand Up @@ -91,8 +92,8 @@ def quick(
verbose: Print progress messages
skip_build: Skip cargo build, use pre-built binary
"""
from update_lib.auto_mark import auto_mark_directory, auto_mark_file
from update_lib.migrate import patch_directory, patch_file
from update_lib.cmd_auto_mark import auto_mark_directory, auto_mark_file
from update_lib.cmd_migrate import patch_directory, patch_file

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


def get_cpython_dir(src_path: pathlib.Path) -> pathlib.Path:
"""Extract cpython directory from source path.

Example:
cpython/Lib/dataclasses.py -> cpython
/some/path/cpython/Lib/foo.py -> /some/path/cpython
"""
path_str = str(src_path).replace("\\", "/")
lib_marker = "/Lib/"
if lib_marker in path_str:
idx = path_str.index(lib_marker)
return pathlib.Path(path_str[:idx])
# Shortcut case: assume "cpython"
return pathlib.Path("cpython")


def get_cpython_version(cpython_dir: pathlib.Path) -> str:
"""Get CPython version from git tag."""
import subprocess
Expand Down Expand Up @@ -384,7 +369,7 @@ def main(argv: list[str] | None = None) -> int:
lib_file_path = parse_lib_path(src_path)

if args.copy:
from update_lib.copy_lib import copy_lib
from update_lib.cmd_copy_lib import copy_lib

copy_lib(src_path)

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

if isinstance(e, TestRunError):
print(f"Error: {e}", file=sys.stderr)
Expand Down
Loading