MCPcopy Create free account
hub / github.com/pytest-dev/pytest / FastFilesCompleter

Class FastFilesCompleter

src/_pytest/_argcomplete.py:73–98  ·  view source on GitHub ↗

Fast file completer class.

Source from the content-addressed store, hash-verified

71
72
73class FastFilesCompleter:
74 """Fast file completer class."""
75
76 def __init__(self, directories: bool = True) -> None:
77 self.directories = directories
78
79 def __call__(self, prefix: str, **kwargs: Any) -> List[str]:
80 # Only called on non option completions.
81 if os.path.sep in prefix[1:]:
82 prefix_dir = len(os.path.dirname(prefix) + os.path.sep)
83 else:
84 prefix_dir = 0
85 completion = []
86 globbed = []
87 if "*" not in prefix and "?" not in prefix:
88 # We are on unix, otherwise no bash.
89 if not prefix or prefix[-1] == os.path.sep:
90 globbed.extend(glob(prefix + ".*"))
91 prefix += "*"
92 globbed.extend(glob(prefix))
93 for x in sorted(globbed):
94 if os.path.isdir(x):
95 x += "/"
96 # Append stripping the prefix (like bash, not like compgen).
97 completion.append(x[prefix_dir:])
98 return completion
99
100
101if os.environ.get("_ARGCOMPLETE"):

Callers 3

_argcomplete.pyFile · 0.85

Calls

no outgoing calls

Tested by 2