Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
sync marker
  • Loading branch information
youknowone committed Jan 22, 2026
commit 3b782b8b9f11f2fd0917d65744268c21d56387c9
1 change: 1 addition & 0 deletions scripts/update_lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cache/
7 changes: 3 additions & 4 deletions scripts/update_lib/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import re
import shelve
import subprocess
from collections import deque

from update_lib.io_utils import read_python_files, safe_parse_ast, safe_read_text

Expand All @@ -38,14 +37,13 @@ def _get_cpython_version(cpython_prefix: str = "cpython") -> str:

def _get_cache_path() -> str:
"""Get cache file path (without extension - shelve adds its own)."""
cache_dir = pathlib.Path.home() / ".cache" / "rustpython-update-lib"
cache_dir = pathlib.Path(__file__).parent / ".cache"
cache_dir.mkdir(parents=True, exist_ok=True)
return str(cache_dir / "import_graph_cache")


def clear_import_graph_caches() -> None:
"""Clear in-process import graph caches (for testing)."""
global _test_import_graph_cache, _lib_import_graph_cache
if "_test_import_graph_cache" in globals():
globals()["_test_import_graph_cache"].clear()
if "_lib_import_graph_cache" in globals():
Expand Down Expand Up @@ -328,7 +326,8 @@ def parse_lib_imports(content: str) -> set[str]:
Returns:
Set of imported module names (full paths)
"""
content = _extract_top_level_code(content)
# Note: Don't truncate content here - some stdlib files have imports after
# the first def/class (e.g., _pydecimal.py has `import contextvars` at line 343)
imports = set()

# Match "import foo.bar" at line start
Expand Down
27 changes: 19 additions & 8 deletions scripts/update_lib/show_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def format_deps(
dep_info = DEPENDENCIES.get(name, {})
hard_deps = dep_info.get("hard_deps", [])
if hard_deps:
lines.append(f"hard_deps: {hard_deps}")
lines.append(f"packages: {hard_deps}")

lines.append("soft_deps:")
lines.append("dependencies:")
lines.extend(
format_deps_tree(
cpython_prefix, lib_prefix, max_depth, soft_deps={name}, _visited=_visited
Expand All @@ -197,13 +197,20 @@ def format_deps(

# Show dependent tests as tree (depth 2: module + direct importers + their importers)
tree = find_dependent_tests_tree(name, lib_prefix=lib_prefix, max_depth=2)
lines.extend(_format_dependent_tests_tree(tree))
lines.extend(_format_dependent_tests_tree(tree, cpython_prefix, lib_prefix))

return lines


def _format_dependent_tests_tree(tree: dict, indent: str = "") -> list[str]:
def _format_dependent_tests_tree(
tree: dict,
cpython_prefix: str = "cpython",
lib_prefix: str = "Lib",
indent: str = "",
) -> list[str]:
"""Format dependent tests tree for display."""
from update_lib.deps import is_up_to_date

lines = []
module = tree["module"]
tests = tree["tests"]
Expand All @@ -224,21 +231,25 @@ def count_tests(t: dict) -> int:
return lines
lines.append(f"dependent tests: ({total} tests)")

# Check if module is up-to-date
synced = is_up_to_date(module.split(".")[0], cpython_prefix, lib_prefix)
marker = "[x]" if synced else "[ ]"

# Format this node
if tests:
test_str = " ".join(tests)
if indent == "":
lines.append(f"- {module}: {test_str}")
lines.append(f"- {marker} {module}: {test_str}")
else:
lines.append(f"{indent}- {module}: {test_str}")
lines.append(f"{indent}- {marker} {module}: {test_str}")
elif indent != "" and children:
# Has children but no direct tests
lines.append(f"{indent}- {module}:")
lines.append(f"{indent}- {marker} {module}:")

# Format children
child_indent = indent + " " if indent else " "
for child in children:
lines.extend(_format_dependent_tests_tree(child, child_indent))
lines.extend(_format_dependent_tests_tree(child, cpython_prefix, lib_prefix, child_indent))

return lines

Expand Down