Find paths for the stat reloader to watch. Returns imported module files, Python files under non-system paths. Extra files and Python files under extra directories can also be scanned. System paths have to be excluded for efficiency. Non-system paths, such as a project root or ``sys
(
extra_files: set[str], exclude_patterns: set[str]
)
| 66 | |
| 67 | |
| 68 | def _find_stat_paths( |
| 69 | extra_files: set[str], exclude_patterns: set[str] |
| 70 | ) -> t.Iterable[str]: |
| 71 | """Find paths for the stat reloader to watch. Returns imported |
| 72 | module files, Python files under non-system paths. Extra files and |
| 73 | Python files under extra directories can also be scanned. |
| 74 | |
| 75 | System paths have to be excluded for efficiency. Non-system paths, |
| 76 | such as a project root or ``sys.path.insert``, should be the paths |
| 77 | of interest to the user anyway. |
| 78 | """ |
| 79 | paths = set() |
| 80 | |
| 81 | for path in chain(list(sys.path), extra_files): |
| 82 | path = os.path.abspath(path) |
| 83 | |
| 84 | if os.path.isfile(path): |
| 85 | # zip file on sys.path, or extra file |
| 86 | paths.add(path) |
| 87 | continue |
| 88 | |
| 89 | parent_has_py = {os.path.dirname(path): True} |
| 90 | |
| 91 | for root, dirs, files in os.walk(path): |
| 92 | if ( |
| 93 | root.startswith(_stat_ignore_scan) |
| 94 | or os.path.basename(root) in _ignore_common_dirs |
| 95 | ): |
| 96 | dirs.clear() |
| 97 | continue |
| 98 | |
| 99 | has_py = False |
| 100 | |
| 101 | for name in files: |
| 102 | if name.endswith((".py", ".pyc")): |
| 103 | has_py = True |
| 104 | paths.add(os.path.join(root, name)) |
| 105 | |
| 106 | # Optimization: stop scanning a directory if neither it nor |
| 107 | # its parent contained Python files. |
| 108 | if not (has_py or parent_has_py[os.path.dirname(root)]): |
| 109 | dirs.clear() |
| 110 | continue |
| 111 | |
| 112 | parent_has_py[root] = has_py |
| 113 | |
| 114 | paths.update(_iter_module_paths()) |
| 115 | _remove_by_pattern(paths, exclude_patterns) |
| 116 | return paths |
| 117 | |
| 118 | |
| 119 | def _find_watchdog_paths( |
no test coverage detected