Return true if the given ModuleSpec can be used to import the given module path.
(module_spec: ModuleSpec | None, module_path: Path)
| 727 | |
| 728 | |
| 729 | def spec_matches_module_path(module_spec: ModuleSpec | None, module_path: Path) -> bool: |
| 730 | """Return true if the given ModuleSpec can be used to import the given module path.""" |
| 731 | if module_spec is None: |
| 732 | return False |
| 733 | |
| 734 | if module_spec.origin: |
| 735 | return Path(module_spec.origin) == module_path |
| 736 | |
| 737 | # Compare the path with the `module_spec.submodule_Search_Locations` in case |
| 738 | # the module is part of a namespace package. |
| 739 | # https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec.submodule_search_locations |
| 740 | if module_spec.submodule_search_locations: # can be None. |
| 741 | for path in module_spec.submodule_search_locations: |
| 742 | if Path(path) == module_path: |
| 743 | return True |
| 744 | |
| 745 | return False |
| 746 | |
| 747 | |
| 748 | # Implement a special _is_same function on Windows which returns True if the two filenames |
no outgoing calls