Skip to content

Commit f51c5e6

Browse files
committed
Implement a non-configurable skiplist for import completion (fixes #845)
1 parent 4ede389 commit f51c5e6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

bpython/importcompletion.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
current_from_import_import,
3333
)
3434

35+
import fnmatch
3536
import os
3637
import sys
3738
import warnings
@@ -51,6 +52,9 @@
5152
# List of stored paths to compare against so that real paths are not repeated
5253
# handles symlinks not mount points
5354
paths = set()
55+
# Patterns to skip
56+
# TODO: This skiplist should be configurable.
57+
skiplist = (".git", ".config", ".local", ".share", "node_modules")
5458
fully_loaded = False
5559

5660

@@ -140,6 +144,10 @@ def find_modules(path):
140144
if not os.path.isdir(path):
141145
# Perhaps a zip file
142146
return
147+
basepath = os.path.basename(path)
148+
if any(fnmatch.fnmatch(basepath, entry) for entry in skiplist):
149+
# Path is on skiplist
150+
return
143151

144152
try:
145153
filenames = os.listdir(path)
@@ -150,7 +158,10 @@ def find_modules(path):
150158
finder = importlib.machinery.FileFinder(path)
151159

152160
for name in filenames:
153-
if not any(name.endswith(suffix) for suffix in SUFFIXES):
161+
if any(fnmatch.fnmatch(name, entry) for entry in skiplist):
162+
# Path is on skiplist
163+
continue
164+
elif not any(name.endswith(suffix) for suffix in SUFFIXES):
154165
# Possibly a package
155166
if "." in name:
156167
continue

0 commit comments

Comments
 (0)