MCPcopy
hub / github.com/pallets/werkzeug / _find_common_roots

Function _find_common_roots

src/werkzeug/_reloader.py:143–166  ·  view source on GitHub ↗
(paths: t.Iterable[str])

Source from the content-addressed store, hash-verified

141
142
143def _find_common_roots(paths: t.Iterable[str]) -> t.Iterable[str]:
144 root: dict[str, dict[str, t.Any]] = {}
145
146 for chunks in sorted((PurePath(x).parts for x in paths), key=len, reverse=True):
147 node = root
148
149 for chunk in chunks:
150 node = node.setdefault(chunk, {})
151
152 node.clear()
153
154 rv = set()
155
156 def _walk(node: t.Mapping[str, dict[str, t.Any]], path: tuple[str, ...]) -> None:
157 for prefix, child in node.items():
158 _walk(child, path + (prefix,))
159
160 # If there are no more nodes, and a path has been accumulated, add it.
161 # Path may be empty if the "" entry is in sys.path.
162 if not node and path:
163 rv.add(os.path.join(*path))
164
165 _walk(root, ())
166 return rv
167
168
169def _get_args_for_reloading() -> list[str]:

Callers 1

_find_watchdog_pathsFunction · 0.85

Calls 3

_walkFunction · 0.85
setdefaultMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected