MCPcopy Index your code
hub / github.com/pytest-dev/pytest / FilesCompleter

Class FilesCompleter

testing/test_argcomplete.py:39–69  ·  view source on GitHub ↗

File completer class, optionally takes a list of allowed extensions.

Source from the content-addressed store, hash-verified

37
38
39class FilesCompleter:
40 """File completer class, optionally takes a list of allowed extensions."""
41
42 def __init__(self, allowednames=(), directories=True):
43 # Fix if someone passes in a string instead of a list
44 if type(allowednames) is str:
45 allowednames = [allowednames]
46
47 self.allowednames = [x.lstrip("*").lstrip(".") for x in allowednames]
48 self.directories = directories
49
50 def __call__(self, prefix, **kwargs):
51 completion = []
52 if self.allowednames:
53 if self.directories:
54 files = _wrapcall(["bash", "-c", f"compgen -A directory -- '{prefix}'"])
55 completion += [f + "/" for f in files]
56 for x in self.allowednames:
57 completion += _wrapcall(
58 ["bash", "-c", f"compgen -A file -X '!*.{x}' -- '{prefix}'"]
59 )
60 else:
61 completion += _wrapcall(["bash", "-c", f"compgen -A file -- '{prefix}'"])
62
63 anticomp = _wrapcall(["bash", "-c", f"compgen -A directory -- '{prefix}'"])
64
65 completion = list(set(completion) - set(anticomp))
66
67 if self.directories:
68 completion += [f + "/" for f in anticomp]
69 return completion
70
71
72class TestArgComplete:

Callers 2

Calls

no outgoing calls

Tested by 2

Used in the wild real call sites across dependent graphs

searching dependent graphs…