Skip to content

Commit cf5763e

Browse files
committed
Make importcompletion skiplist configurable (fixes #849)
1 parent ec79bd8 commit cf5763e

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

bpython/config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ def loadini(struct, configfile):
7070
"default_autoreload": False,
7171
"editor": os.environ.get("VISUAL", os.environ.get("EDITOR", "vi")),
7272
"flush_output": True,
73+
"import_completion_skiplist": ":".join(
74+
(
75+
# version tracking
76+
".git",
77+
".svn",
78+
".hg"
79+
# XDG
80+
".config",
81+
".local",
82+
".share",
83+
# nodejs
84+
"node_modules",
85+
# PlayOnLinux
86+
"PlayOnLinux's virtual drives",
87+
# wine
88+
"dosdevices",
89+
# Python byte code cache
90+
"__pycache__",
91+
)
92+
),
7393
"highlight_show_source": True,
7494
"hist_duplicates": True,
7595
"hist_file": "~/.pythonhist",
@@ -188,6 +208,9 @@ def get_key_no_doublebind(command):
188208
struct.default_autoreload = config.getboolean(
189209
"general", "default_autoreload"
190210
)
211+
struct.import_completion_skiplist = config.get(
212+
"general", "import_completion_skiplist"
213+
).split(":")
191214

192215
struct.pastebin_key = get_key_no_doublebind("pastebin")
193216
struct.copy_clipboard_key = get_key_no_doublebind("copy_clipboard")

bpython/importcompletion.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,14 @@
3838

3939

4040
class ModuleGatherer:
41-
def __init__(self, path=None):
41+
def __init__(self, path=None, skiplist=None):
4242
# The cached list of all known modules
4343
self.modules = set()
4444
# List of stored paths to compare against so that real paths are not repeated
4545
# handles symlinks not mount points
4646
self.paths = set()
4747
# Patterns to skip
48-
# TODO: This skiplist should be configurable.
49-
self.skiplist = (
50-
# version tracking
51-
".git",
52-
".svn",
53-
".hg"
54-
# XDG
55-
".config",
56-
".local",
57-
".share",
58-
# nodejs
59-
"node_modules",
60-
# PlayOnLinux
61-
"PlayOnLinux's virtual drives",
62-
# wine
63-
"dosdevices",
64-
# cache
65-
"__pycache__",
66-
)
48+
self.skiplist = skiplist if skiplist is not None else tuple()
6749
self.fully_loaded = False
6850
self.find_iterator = self.find_all_modules(path)
6951

bpython/repl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,9 @@ def __init__(self, interp, config):
444444
except OSError:
445445
pass
446446

447-
self.module_gatherer = ModuleGatherer()
447+
self.module_gatherer = ModuleGatherer(
448+
skiplist=self.config.import_completion_skiplist
449+
)
448450
self.completers = autocomplete.get_default_completer(
449451
config.autocomplete_mode, self.module_gatherer
450452
)

doc/sphinx/source/configuration-options.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ Whether to use Unicode characters to draw boxes.
174174

175175
.. versionadded:: 0.14
176176

177+
import_completion_skiplist
178+
^^^^^^^^^^^^^^^^^^^^^^^^^^
179+
A `:`-seperated list of patterns to skip when processing modules for import completion.
180+
181+
.. versionadded:: 0.21
182+
177183
Keyboard
178184
--------
179185
This section refers to the ``[keyboard]`` section in your

0 commit comments

Comments
 (0)