@@ -258,7 +258,7 @@ def get_line_prefix(pre_lines: list, curr_line: str, col: int, qs: bool = True)
258
258
259
259
260
260
def resolve_globs (glob_path : str , root_path : str = None ) -> list [str ]:
261
- """Resolve glob patterns
261
+ """Resolve paths (absolute and relative) and glob patterns
262
262
263
263
Parameters
264
264
----------
@@ -277,16 +277,14 @@ def resolve_globs(glob_path: str, root_path: str = None) -> list[str]:
277
277
Expanded glob patterns with absolute paths.
278
278
Absolute paths are used to resolve any potential ambiguity
279
279
"""
280
- # Path.glob returns a generator, we then cast the Path obj to a str
281
- # alternatively use p.as_posix()
282
- if root_path :
283
- return [ str ( p ) for p in Path ( root_path ). resolve (). glob ( glob_path )]
284
- # Attempt to extract the root and glob pattern from the glob_path
285
- # This is substantially less robust that then above
280
+ # Resolve absolute paths i.e. not in our root_path
281
+ if os . path . isabs ( glob_path ) or not root_path :
282
+ p = Path ( glob_path ). resolve ()
283
+ root = p . root
284
+ rel = str ( p . relative_to ( root )) # contains glob pattern
285
+ return [ str ( p . resolve ()) for p in Path ( root ). glob ( rel )]
286
286
else :
287
- p = Path (glob_path ).expanduser ()
288
- parts = p .parts [p .is_absolute () :]
289
- return [str (i ) for i in Path (p .root ).resolve ().glob (str (Path (* parts )))]
287
+ return [str (p .resolve ()) for p in Path (root_path ).resolve ().glob (glob_path )]
290
288
291
289
292
290
def only_dirs (paths : list [str ], err_msg : list = []) -> list [str ]:
0 commit comments