|
67 | 67 |
|
68 | 68 | import os |
69 | 69 | import io |
70 | | -import re |
71 | 70 | import sys |
72 | 71 | import cmd |
73 | | -import bdb |
74 | 72 | import dis |
| 73 | +import bdb |
75 | 74 | import code |
76 | | -import glob |
77 | | -import json |
78 | 75 | import stat |
79 | 76 | import token |
80 | 77 | import types |
81 | 78 | import atexit |
82 | 79 | import codeop |
83 | | -import pprint |
84 | | -import signal |
85 | | -import socket |
86 | 80 | import typing |
87 | 81 | import inspect |
88 | | -import weakref |
89 | 82 | import builtins |
90 | | -import tempfile |
91 | | -import textwrap |
92 | | -import tokenize |
93 | 83 | import itertools |
94 | | -import traceback |
95 | 84 | import linecache |
96 | | -import selectors |
97 | | -import threading |
98 | | -import _colorize |
99 | 85 |
|
100 | 86 | from contextlib import ExitStack, closing, contextmanager |
101 | 87 | from types import CodeType |
102 | 88 | from warnings import deprecated |
103 | 89 |
|
| 90 | +lazy import _colorize |
| 91 | +lazy import argparse |
104 | 92 | lazy import asyncio |
105 | | - |
106 | | -try: |
107 | | - import _pyrepl.utils |
108 | | -except ModuleNotFoundError: |
109 | | - _pyrepl = None |
| 93 | +lazy import glob |
| 94 | +lazy import json |
| 95 | +lazy import pprint |
| 96 | +lazy import re |
| 97 | +lazy import runpy |
| 98 | +lazy import selectors |
| 99 | +lazy import shlex |
| 100 | +lazy import signal |
| 101 | +lazy import socket |
| 102 | +lazy import tempfile |
| 103 | +lazy import textwrap |
| 104 | +lazy import threading |
| 105 | +lazy import tokenize |
| 106 | +lazy import traceback |
| 107 | +lazy import weakref |
110 | 108 |
|
111 | 109 |
|
112 | 110 | class Restart(Exception): |
@@ -247,7 +245,6 @@ class _ModuleTarget(_ExecutableTarget): |
247 | 245 | def __init__(self, target): |
248 | 246 | self._target = target |
249 | 247 |
|
250 | | - import runpy |
251 | 248 | try: |
252 | 249 | _, self._spec, self._code = runpy._get_module_details(self._target) |
253 | 250 | except ImportError as e: |
@@ -282,8 +279,6 @@ def namespace(self): |
282 | 279 |
|
283 | 280 | class _ZipTarget(_ExecutableTarget): |
284 | 281 | def __init__(self, target): |
285 | | - import runpy |
286 | | - |
287 | 282 | self._target = os.path.realpath(target) |
288 | 283 | sys.path.insert(0, self._target) |
289 | 284 | try: |
@@ -466,6 +461,7 @@ def complete(self, text, state): |
466 | 461 | return None |
467 | 462 |
|
468 | 463 | def gen_colors(self, buffer): |
| 464 | + import _pyrepl.utils |
469 | 465 | from _pyrepl.utils import ColorSpan, Span |
470 | 466 |
|
471 | 467 | if not buffer.strip(): |
@@ -1271,7 +1267,11 @@ def handle_command_def(self, line): |
1271 | 1267 | return False |
1272 | 1268 |
|
1273 | 1269 | def _colorize_code(self, code): |
1274 | | - if self.colorize and _pyrepl: |
| 1270 | + if self.colorize: |
| 1271 | + try: |
| 1272 | + import _pyrepl.utils |
| 1273 | + except ModuleNotFoundError: |
| 1274 | + return code |
1275 | 1275 | colors = list(_pyrepl.utils.gen_colors(code)) |
1276 | 1276 | chars, _ = _pyrepl.utils.disp_str(code, colors=colors, force_color=True) |
1277 | 1277 | code = "".join(chars) |
@@ -2089,7 +2089,6 @@ def do_run(self, arg): |
2089 | 2089 | 'e.g. "python -m pdb myscript.py"') |
2090 | 2090 | return |
2091 | 2091 | if arg: |
2092 | | - import shlex |
2093 | 2092 | argv0 = sys.argv[0:1] |
2094 | 2093 | try: |
2095 | 2094 | sys.argv = shlex.split(arg) |
@@ -3787,9 +3786,7 @@ def parse_args(): |
3787 | 3786 | # "python -m pdb -m foo -p 1" should pass "-p 1" to "foo". |
3788 | 3787 | # "python -m pdb foo.py -m bar" should pass "-m bar" to "foo.py". |
3789 | 3788 | # "python -m pdb -m foo -m bar" should pass "-m bar" to "foo". |
3790 | | - # This require some customized parsing logic to find the actual debug target. |
3791 | | - |
3792 | | - import argparse |
| 3789 | + # This requires some customized parsing logic to find the actual debug target. |
3793 | 3790 |
|
3794 | 3791 | parser = argparse.ArgumentParser( |
3795 | 3792 | usage="%(prog)s [-h] [-c command] (-m module | -p pid | pyfile) [args ...]", |
|
0 commit comments