GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — RustPython/scripts/update_lib/deps.py at main · RustPython/RustPython Expand file tree/ Copy pathdeps.pyMore file actions 1726 lines (1491 loc) · 49.5 KB / Copy pathdeps.pyFile metadata and controls1726 lines (1491 loc) · 49.5 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 """ Dependency resolution for library updates. Handles: - Irregular library paths (e.g., libregrtest at Lib/test/libregrtest/) - Library dependencies (e.g., datetime requires _pydatetime) - Test dependencies (auto-detected from 'from test import ...') """ import ast import difflib import functools import pathlib import shelve import subprocess from update_lib.file_utils import ( _dircmp_is_same, compare_dir_contents, compare_file_contents, compare_paths, construct_lib_path, cpython_to_local_path, read_python_files, resolve_module_path, resolve_test_path, safe_parse_ast, safe_read_text, ) # === Import parsing utilities === class ImportVisitor(ast.NodeVisitor): def __init__(self) -> None: self.__imports = set() @property def test_imports(self) -> set[str]: imports = set() for module in self.__imports: if not module.startswith("test."): continue name = module.removeprefix("test.") if name == "support" or name.startswith("support."): continue imports.add(name) return imports @property def lib_imports(self) -> set[str]: return {module for module in self.__imports if not module.startswith("test.")} def visit_Import(self, node): for alias in node.names: self.__imports.add(alias.name) def visit_ImportFrom(self, node): try: module = node.module except AttributeError: # Ignore `from . import my_internal_module` return if module is None: # Ignore `from . import my_internal_module` return for alias in node.names: # We only care about what we import if it was from the "test" module if module == "test": name = f"{module}.{alias.name}" else: name = module self.__imports.add(name) def visit_Call(self, node) -> None: """ In test files, there's sometimes use of: ```python import test.support from test.support import script_helper script = support.findfile("_test_atexit.py") script_helper.run_test_script(script) ``` This imports "_test_atexit.py" but does not show as an import node. """ func = node.func if not isinstance(func, ast.Attribute): return value = func.value if not isinstance(value, ast.Name): return if (value.id != "support") or (func.attr != "findfile"): return arg = node.args[0] if not isinstance(arg, ast.Constant): return target = arg.value if not target.endswith(".py"): return target = target.removesuffix(".py") self.__imports.add(f"test.{target}") def parse_test_imports(content: str) -> frozenset[str]: """Parse test file content and extract test package dependencies.""" if not (tree := safe_parse_ast(content)): return set() visitor = ImportVisitor() visitor.visit(tree) return visitor.test_imports def parse_lib_imports(content: str) -> frozenset[str]: """Parse library file and extract all imported module names.""" if not (tree := safe_parse_ast(content)): return set() visitor = ImportVisitor() visitor.visit(tree) return visitor.lib_imports # === TODO marker utilities === TODO_MARKER = "TODO: RUSTPYTHON" def filter_rustpython_todo(content: str) -> str: """Remove lines containing RustPython TODO markers.""" lines = content.splitlines(keepends=True) return "".join(line for line in lines if TODO_MARKER not in line) def count_rustpython_todo(content: str) -> int: """Count lines containing RustPython TODO markers.""" return content.count(TODO_MARKER) def count_todo_in_path(path: pathlib.Path) -> int: """Count RustPython TODO markers in a file or directory of .py files.""" if path.is_file(): content = safe_read_text(path) return count_rustpython_todo(content) if content else 0 return sum(count_rustpython_todo(content) for _, content in read_python_files(path)) # === Test utilities === def _get_cpython_test_path(test_name: str, cpython_prefix: str) -> pathlib.Path | None: """Return the CPython test path for a test name, or None if missing.""" cpython_path = resolve_test_path(test_name, cpython_prefix, prefer="dir") return cpython_path if cpython_path.exists() else None def _get_local_test_path( cpython_test_path: pathlib.Path, lib_prefix: str ) -> pathlib.Path: """Return the local Lib/test path matching a CPython test path.""" return pathlib.Path(lib_prefix) / "test" / cpython_test_path.name def is_test_tracked(test_name: str, cpython_prefix: str, lib_prefix: str) -> bool: """Check if a test exists in the local Lib/test.""" cpython_path = _get_cpython_test_path(test_name, cpython_prefix) if cpython_path is None: return True local_path = _get_local_test_path(cpython_path, lib_prefix) return local_path.exists() def is_test_up_to_date(test_name: str, cpython_prefix: str, lib_prefix: str) -> bool: """Check if a test is up-to-date, ignoring RustPython TODO markers.""" cpython_path = _get_cpython_test_path(test_name, cpython_prefix) if cpython_path is None: return True local_path = _get_local_test_path(cpython_path, lib_prefix) if not local_path.exists(): return False if cpython_path.is_file(): return compare_file_contents( cpython_path, local_path, local_filter=filter_rustpython_todo ) return compare_dir_contents( cpython_path, local_path, local_filter=filter_rustpython_todo ) def count_test_todos(test_name: str, lib_prefix: str) -> int: """Count RustPython TODO markers in a test file/directory.""" local_dir = pathlib.Path(lib_prefix) / "test" / test_name local_file = pathlib.Path(lib_prefix) / "test" / f"{test_name}.py" if local_dir.exists(): return count_todo_in_path(local_dir) if local_file.exists(): return count_todo_in_path(local_file) return 0 # === Cross-process cache using shelve === def _get_cpython_version(cpython_prefix: str) -> str: """Get CPython version from git tag for cache namespace.""" try: result = subprocess.run( ["git", "describe", "--tags", "--abbrev=0"], cwd=cpython_prefix, capture_output=True, text=True, ) if result.returncode == 0: return result.stdout.strip() except Exception: pass return "unknown" def _get_cache_path() -> str: """Get cache file path (without extension - shelve adds its own).""" 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).""" if "_test_import_graph_cache" in globals(): globals()["_test_import_graph_cache"].clear() if "_lib_import_graph_cache" in globals(): globals()["_lib_import_graph_cache"].clear() # Manual dependency table for irregular cases # Format: "name" -> {"lib": [...], "test": [...], "data": [...], "hard_deps": [...]} # - lib: override default path (default: name.py or name/) # - hard_deps: additional files to copy alongside the main module DEPENDENCIES = { # regrtest is in Lib/test/libregrtest/, not Lib/libregrtest/ "regrtest": { "lib": ["test/libregrtest"], "test": ["test_regrtest"], "data": ["test/regrtestdata"], }, # Rust-implemented modules (no lib file, only test) "int": { "lib": [], "hard_deps": ["_pylong.py"], "test": [ "test_int.py", "test_long.py", "test_int_literal.py", ], }, "exception": { "lib": [], "test": [ "test_exceptions.py", "test_baseexception.py", "test_except_star.py", "test_exception_group.py", "test_exception_hierarchy.py", "test_exception_variations.py", ], }, "dict": { "lib": [], "test": [ "test_dict.py", "test_dictcomps.py", "test_dictviews.py", "test_userdict.py", "mapping_tests.py", ], }, "list": { "lib": [], "test": [ "test_list.py", "test_listcomps.py", "test_userlist.py", ], }, "__future__": { "test": [ "test___future__.py", "test_future_stmt.py", ], }, "site": { "hard_deps": ["_sitebuiltins.py"], }, "opcode": { "hard_deps": ["_opcode_metadata.py"], "test": [ "test_opcode.py", "test__opcode.py", "test_opcodes.py", ], }, "pickle": { "hard_deps": ["_compat_pickle.py"], "test": [ "picklecommon.py", "test_pickle.py", "test_picklebuffer.py", "test_pickletools.py", "test_xpickle.py", "xpickle_worker.py", ], }, "re": { "test": [ "test_re.py", "re_tests.py", ], }, "weakref": { "hard_deps": ["_weakrefset.py"], "test": [ "test_weakref.py", "test_weakset.py", ], }, "codecs": { "test": [ "test_charmapcodec.py", "test_codeccallbacks.py", "test_codecencodings_cn.py", "test_codecencodings_hk.py", "test_codecencodings_iso2022.py", "test_codecencodings_jp.py", "test_codecencodings_kr.py", "test_codecencodings_tw.py", "test_codecmaps_cn.py", "test_codecmaps_hk.py", "test_codecmaps_jp.py", "test_codecmaps_kr.py", "test_codecmaps_tw.py", "test_codecs.py", "test_multibytecodec.py", "testcodec.py", ], }, # Non-pattern hard_deps (can't be auto-detected) "ast": { "hard_deps": ["_ast_unparse.py"], "test": [ "test_ast.py", "test_unparse.py", "test_type_comments.py", ], }, # Data directories "pydoc": { "hard_deps": ["pydoc_data"], }, "turtle": { "hard_deps": ["turtledemo"], }, "sysconfig": { "hard_deps": ["_aix_support.py", "_osx_support.py"], "test": [ "test_sysconfig.py", "test__osx_support.py", ], }, "tkinter": { "test": [ "test_tkinter", "test_ttk", "test_ttk_textonly.py", "test_tcl.py", "test_idle", ], }, # Test support library (like regrtest) "support": { "lib": ["test/support"], "data": ["test/wheeldata"], "test": [ "test_support.py", "test_script_helper.py", ], }, # test_htmlparser tests html.parser "html": { "hard_deps": ["_markupbase.py"], "test": ["test_html.py", "test_htmlparser.py"], }, "xml": { "test": [ "test_xml_etree.py", "test_xml_etree_c.py", "test_minidom.py", "test_pulldom.py", "test_pyexpat.py", "test_sax.py", "test_xml_dom_minicompat.py", "test_xml_dom_xmlbuilder.py", ], }, "multiprocessing": { "test": [ "test_multiprocessing_fork", "test_multiprocessing_forkserver", "test_multiprocessing_spawn", "test_multiprocessing_main_handling.py", "_test_multiprocessing.py", ], }, "urllib": { "test": [ "test_urllib.py", "test_urllib2.py", "test_urllib2_localnet.py", "test_urllib2net.py", "test_urllibnet.py", "test_urlparse.py", "test_urllib_response.py", "test_robotparser.py", ], }, "collections": { "hard_deps": ["_collections_abc.py"], "test": [ "test_collections.py", "test_deque.py", "test_defaultdict.py", "test_ordered_dict.py", ], }, "http": { "test": [ "test_httplib.py", "test_http_cookiejar.py", "test_http_cookies.py", "test_httpservers.py", ], }, "unicode": { "lib": [], "test": [ "test_unicodedata.py", "test_unicode_file.py", "test_unicode_file_functions.py", "test_unicode_identifiers.py", "test_ucn.py", ], }, "typing": { "test": [ "test_typing.py", "test_type_aliases.py", "test_type_annotations.py", "test_type_params.py", "test_genericalias.py", ], }, "unpack": { "lib": [], "test": [ "test_unpack.py", "test_unpack_ex.py", ], }, "zipimport": { "test": [ "test_zipimport.py", "test_zipimport_support.py", ], }, "time": { "lib": [], "test": [ "test_time.py", "test_strftime.py", ], }, "sys": { "lib": [], "test": [ "test_sys.py", "test_syslog.py", "test_sys_setprofile.py", "test_sys_settrace.py", "test_audit.py", "audit-tests.py", ], }, "str": { "lib": [], "test": [ "test_str.py", "test_fstring.py", "test_string_literals.py", ], }, "thread": { "lib": [], "test": [ "test_thread.py", "test_thread_local_bytecode.py", "test_threadsignals.py", ], }, "threading": { "hard_deps": ["_threading_local.py"], "test": [ "test_threading.py", "test_threadedtempfile.py", "test_threading_local.py", ], }, "class": { "lib": [], "test": [ "test_class.py", "test_genericclass.py", "test_subclassinit.py", ], }, "generator": { "lib": [], "test": [ "test_generators.py", "test_genexps.py", "test_generator_stop.py", "test_yield_from.py", ], }, "descr": { "lib": [], "test": [ "test_descr.py", "test_descrtut.py", ], }, "code": { "test": [ "test_code_module.py", ], }, "contextlib": { "test": [ "test_contextlib.py", "test_contextlib_async.py", ], }, "io": { "hard_deps": ["_pyio.py"], "test": [ "test_io", ], }, "dbm": { "test": [ "test_dbm.py", "test_dbm_dumb.py", "test_dbm_gnu.py", "test_dbm_ndbm.py", "test_dbm_sqlite3.py", ], }, "datetime": { "hard_deps": ["_strptime.py"], "test": [ "test_datetime.py", "test_strptime.py", ], }, "locale": { "test": [ "test_locale.py", "test__locale.py", ], }, "numbers": { "test": [ "test_numbers.py", "test_abstract_numbers.py", ], }, "file": { "lib": [], "test": [ "test_io", ], }, "fcntl": { "lib": [], "test": [ "test_fcntl.py", "test_ioctl.py", ], }, "select": { "lib": [], "test": [ "test_select.py", "test_poll.py", ], }, "xmlrpc": { "test": [ "test_xmlrpc.py", "test_docxmlrpc.py", ], }, "ctypes": { "test": [ "test_ctypes", "test_stable_abi_ctypes.py", ], }, # Grouped tests for modules without custom lib paths "compile": { "lib": [], "test": [ "test_compile.py", "test_compiler_assemble.py", "test_compiler_codegen.py", "test_peepholer.py", ], }, "math": { "lib": [], "test": [ "test_math.py", "test_math_integer.py", "test_math_property.py", ], }, "float": { "lib": [], "test": [ "test_float.py", "test_strtod.py", ], }, "zipfile": { "test": [ "test_zipfile.py", "test_zipfile64.py", ], }, "smtplib": { "test": [ "test_smtplib.py", "test_smtpnet.py", ], }, "profile": { "test": [ "test_profile.py", "test_profiling/test_tracing_profiler.py", ], }, "string": { "test": [ "test_string.py", "test_userstring.py", ], }, "os": { "test": [ "test_os.py", "test_popen.py", ], }, "pyrepl": { "test": [ "test_pyrepl", "test_repl.py", ], }, "concurrent": { "test": [ "test_concurrent_futures", "test_interpreters", "test__interpreters.py", "test__interpchannels.py", "test_crossinterp.py", ], }, "atexit": { "test": [ "test_atexit.py", "_test_atexit.py", ], }, "eintr": { "test": [ "test_eintr.py", "_test_eintr.py", ] }, "curses": { "test": [ "test_curses.py", "curses_tests.py", ], }, "signal": { "test": [ "signalinterproctester.py", "test_signal.py", ] }, } def resolve_hard_dep_parent(name: str, cpython_prefix: str) -> str | None: """Resolve a hard_dep name to its parent module. Only returns a parent if the file is actually tracked: - Explicitly listed in DEPENDENCIES as a hard_dep - Or auto-detected _py{module}.py pattern where the parent module exists Args: name: Module or file name (with or without .py extension) cpython_prefix: CPython directory prefix Returns: Parent module name if found and tracked, None otherwise """ # Normalize: remove .py extension if present if name.endswith(".py"): name = name[:-3] # Check DEPENDENCIES table first (explicit hard_deps) for module_name, dep_info in DEPENDENCIES.items(): hard_deps = dep_info.get("hard_deps", []) for dep in hard_deps: # Normalize dep: remove .py extension dep_normalized = dep[:-3] if dep.endswith(".py") else dep if dep_normalized == name: return module_name # Auto-detect _py{module} or _py_{module} patterns # Only if the parent module actually exists if name.startswith("_py"): # _py_abc -> abc # _pydatetime -> datetime parent = name.removeprefix("_py_").removeprefix("_py") # Verify the parent module exists lib_dir = pathlib.Path(cpython_prefix) / "Lib" parent_file = lib_dir / f"{parent}.py" parent_dir = lib_dir / parent if parent_file.exists() or ( parent_dir.exists() and (parent_dir / "__init__.py").exists() ): return parent return None def resolve_test_to_lib(test_name: str) -> str | None: """Resolve a test name to its library group from DEPENDENCIES. Args: test_name: Test name with or without test_ prefix (e.g., "test_urllib2" or "urllib2") Returns: Library name if test belongs to a group, None otherwise """ # Normalize: add test_ prefix if not present if not test_name.startswith("test_"): test_name = f"test_{test_name}" for lib_name, dep_info in DEPENDENCIES.items(): tests = dep_info.get("test", []) for test_path in tests: # test_path is like "test_urllib2.py" or "test_multiprocessing_fork" path_stem = test_path.removesuffix(".py") if path_stem == test_name: return lib_name return None # Test-specific dependencies (only when auto-detection isn't enough) # - hard_deps: files to migrate (tightly coupled, must be migrated together) # - data: directories to copy without migration TEST_DEPENDENCIES = { # Audio tests "test_winsound": { "data": ["audiodata"], }, "test_wave": { "data": ["audiodata"], }, "audiotests": { "data": ["audiodata"], }, # Archive tests "test_tarfile": { "data": ["archivetestdata"], }, "test_zipfile": { "data": ["archivetestdata"], }, # Config tests "test_configparser": { "data": ["configdata"], }, "test_config": { "data": ["configdata"], }, # Other data directories "test_decimal": { "data": ["decimaltestdata"], }, "test_dtrace": { "data": ["dtracedata"], }, "test_math": { "data": ["mathdata"], }, "test_ssl": { "data": ["certdata"], }, "test_subprocess": { "data": ["subprocessdata"], }, "test_tkinter": { "data": ["tkinterdata"], }, "test_tokenize": { "data": ["tokenizedata"], }, "test_type_annotations": { "data": ["typinganndata"], }, "test_zipimport": { "data": ["zipimport_data"], }, # XML tests share xmltestdata "test_xml_etree": { "data": ["xmltestdata"], }, "test_pulldom": { "data": ["xmltestdata"], }, "test_sax": { "data": ["xmltestdata"], }, "test_minidom": { "data": ["xmltestdata"], }, # Multibytecodec support needs cjkencodings "multibytecodec_support": { "data": ["cjkencodings"], }, # i18n "i18n_helper": { "data": ["translationdata"], }, # wheeldata is used by test_makefile and support "test_makefile": { "data": ["wheeldata"], }, # profilee is used by test_monitoring "test_monitoring": { "hard_deps": ["profilee"], }, } @functools.cache def get_lib_paths(name: str, cpython_prefix: str) -> tuple[pathlib.Path, ...]: """Get all library paths for a module. Args: name: Module name (e.g., "datetime", "libregrtest") cpython_prefix: CPython directory prefix Returns: Tuple of paths to copy """ dep_info = DEPENDENCIES.get(name, {}) # Get main lib path (override or default) if "lib" in dep_info: paths = [construct_lib_path(cpython_prefix, p) for p in dep_info["lib"]] else: # Default: try file first, then directory paths = [resolve_module_path(name, cpython_prefix, prefer="file")] # Add hard_deps from DEPENDENCIES for dep in dep_info.get("hard_deps", []): paths.append(construct_lib_path(cpython_prefix, dep)) # Auto-detect _py{module}.py or _py_{module}.py patterns for pattern in [f"_py{name}.py", f"_py_{name}.py"]: auto_path = construct_lib_path(cpython_prefix, pattern) if auto_path.exists() and auto_path not in paths: paths.append(auto_path) return tuple(paths) def get_all_hard_deps(name: str, cpython_prefix: str) -> list[str]: """Get all hard_deps for a module (explicit + auto-detected). Args: name: Module name (e.g., "decimal", "datetime") cpython_prefix: CPython directory prefix Returns: List of hard_dep names (without .py extension) """ dep_info = DEPENDENCIES.get(name, {}) hard_deps = set() # Explicit hard_deps from DEPENDENCIES for hd in dep_info.get("hard_deps", []): # Remove .py extension if present hard_deps.add(hd[:-3] if hd.endswith(".py") else hd) # Auto-detect _py{module}.py or _py_{module}.py patterns for pattern in [f"_py{name}.py", f"_py_{name}.py"]: auto_path = construct_lib_path(cpython_prefix, pattern) if auto_path.exists(): hard_deps.add(auto_path.stem) return sorted(hard_deps) @functools.cache def get_test_paths(name: str, cpython_prefix: str) -> tuple[pathlib.Path, ...]: """Get all test paths for a module. Args: name: Module name (e.g., "datetime", "libregrtest") cpython_prefix: CPython directory prefix Returns: Tuple of test paths """ if name in DEPENDENCIES and "test" in DEPENDENCIES[name]: return tuple( construct_lib_path(cpython_prefix, f"test/{p}") for p in DEPENDENCIES[name]["test"] ) # Default: try directory first, then file return (resolve_module_path(f"test/test_{name}", cpython_prefix, prefer="dir"),) @functools.cache def get_all_imports(name: str, cpython_prefix: str) -> frozenset[str]: """Get all imports from a library file. Args: name: Module name cpython_prefix: CPython directory prefix Returns: Frozenset of all imported module names """ all_imports = set() for lib_path in get_lib_paths(name, cpython_prefix): if lib_path.exists(): for _, content in read_python_files(lib_path): all_imports.update(parse_lib_imports(content)) # Remove self all_imports.discard(name) return frozenset(all_imports) @functools.cache def get_soft_deps(name: str, cpython_prefix: str) -> frozenset[str]: """Get soft dependencies by parsing imports from library file. Args: name: Module name cpython_prefix: CPython directory prefix |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |