|
4 | 4 | import stat
|
5 | 5 | import urllib
|
6 | 6 | import uuid
|
7 |
| -from pathlib import Path |
8 |
| -from typing import Dict, Iterator, List, Optional, Tuple, cast |
| 7 | +from typing import ( |
| 8 | + Dict, |
| 9 | + ItemsView, |
| 10 | + Iterable, |
| 11 | + Iterator, |
| 12 | + KeysView, |
| 13 | + List, |
| 14 | + Optional, |
| 15 | + Tuple, |
| 16 | + cast, |
| 17 | +) |
9 | 18 |
|
10 | 19 | from mypy_extensions import mypyc_attr
|
11 | 20 | from schema_salad.exceptions import ValidationException
|
@@ -210,21 +219,29 @@ def mapper(self, src: str) -> MapperEnt:
|
210 | 219 | return MapperEnt(p.resolved, p.target + src[i:], p.type, p.staged)
|
211 | 220 | return self._pathmap[src]
|
212 | 221 |
|
213 |
| - def files(self) -> List[str]: |
214 |
| - return list(self._pathmap.keys()) |
| 222 | + def files(self) -> KeysView[str]: |
| 223 | + """Return a dictionary keys view of locations.""" |
| 224 | + return self._pathmap.keys() |
215 | 225 |
|
216 |
| - def items(self) -> List[Tuple[str, MapperEnt]]: |
217 |
| - return list(self._pathmap.items()) |
| 226 | + def items(self) -> ItemsView[str, MapperEnt]: |
| 227 | + """Return a dictionary items view.""" |
| 228 | + return self._pathmap.items() |
218 | 229 |
|
219 |
| - def items_exclude_children(self) -> List[Tuple[str, MapperEnt]]: |
| 230 | + def items_exclude_children(self) -> ItemsView[str, MapperEnt]: |
| 231 | + """Return a dictionary items view minus any entries which are children of other entries.""" |
220 | 232 | newitems = {}
|
221 |
| - keys = [key for key, entry in self.items()] |
| 233 | + |
| 234 | + def parents(path: str) -> Iterable[str]: |
| 235 | + result = path |
| 236 | + while len(result) > 1: |
| 237 | + result = os.path.dirname(result) |
| 238 | + yield result |
| 239 | + |
222 | 240 | for key, entry in self.items():
|
223 |
| - parents = Path(key).parents |
224 |
| - if any([Path(key_) in parents for key_ in keys]): |
| 241 | + if not self.files().isdisjoint(parents(key)): |
225 | 242 | continue
|
226 | 243 | newitems[key] = entry
|
227 |
| - return list(newitems.items()) |
| 244 | + return newitems.items() |
228 | 245 |
|
229 | 246 | def reversemap(
|
230 | 247 | self,
|
|
0 commit comments