Skip to content

Commit 40a50c9

Browse files
__main__ behavior for importcompletion.py
1 parent 83ca33e commit 40a50c9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

bpython/importcompletion.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(
6666
skiplist if skiplist is not None else tuple()
6767
)
6868
self.fully_loaded = False
69+
self.print_packages_traversed = False
6970

7071
if paths is None:
7172
self.modules.update(sys.builtin_module_names)
@@ -220,6 +221,8 @@ def find_modules(
220221
continue
221222
if (stat.st_dev, stat.st_ino) not in self.paths:
222223
self.paths.add((stat.st_dev, stat.st_ino))
224+
if (self.print_packages_traversed):
225+
print(path_real)
223226
for subname in self.find_modules(path_real):
224227
if subname is None:
225228
yield None # take a break to avoid unresponsiveness
@@ -250,3 +253,33 @@ def find_coroutine(self) -> Optional[bool]:
250253
self.fully_loaded = True
251254

252255
return True
256+
257+
258+
def discover(
259+
skiplist: Optional[Sequence[str]] = None,
260+
print_packages_traversed=True
261+
):
262+
module_gatherer = ModuleGatherer(skiplist=skiplist)
263+
module_gatherer.print_packages_traversed = print_packages_traversed
264+
while module_gatherer.find_coroutine():
265+
pass
266+
267+
268+
if __name__ == "__main__":
269+
import argparse
270+
from pathlib import Path
271+
272+
from bpython.config import Config, default_config_path
273+
274+
parser = argparse.ArgumentParser()
275+
parser.add_argument(
276+
"--config",
277+
default=default_config_path(),
278+
type=Path,
279+
help="Use CONFIG instead of default config file.",
280+
)
281+
config = Config(default_config_path())
282+
discover(
283+
config.import_completion_skiplist,
284+
print_packages_traversed=True
285+
)

0 commit comments

Comments
 (0)