|
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 | | -import asyncio |
88 | 81 | import inspect |
89 | | -import weakref |
90 | 82 | import builtins |
91 | | -import tempfile |
92 | | -import textwrap |
93 | | -import tokenize |
94 | 83 | import itertools |
95 | | -import traceback |
96 | 84 | import linecache |
97 | | -import selectors |
98 | | -import threading |
99 | | -import _colorize |
100 | 85 |
|
101 | 86 | from contextlib import ExitStack, closing, contextmanager |
102 | 87 | from types import CodeType |
103 | 88 | from warnings import deprecated |
104 | 89 |
|
105 | | -try: |
106 | | - import _pyrepl.utils |
107 | | -except ModuleNotFoundError: |
108 | | - _pyrepl = None |
| 90 | +lazy import _colorize |
| 91 | +lazy import argparse |
| 92 | +lazy import asyncio |
| 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 |
109 | 108 |
|
110 | 109 |
|
111 | 110 | class Restart(Exception): |
@@ -246,7 +245,6 @@ class _ModuleTarget(_ExecutableTarget): |
246 | 245 | def __init__(self, target): |
247 | 246 | self._target = target |
248 | 247 |
|
249 | | - import runpy |
250 | 248 | try: |
251 | 249 | _, self._spec, self._code = runpy._get_module_details(self._target) |
252 | 250 | except ImportError as e: |
@@ -281,8 +279,6 @@ def namespace(self): |
281 | 279 |
|
282 | 280 | class _ZipTarget(_ExecutableTarget): |
283 | 281 | def __init__(self, target): |
284 | | - import runpy |
285 | | - |
286 | 282 | self._target = os.path.realpath(target) |
287 | 283 | sys.path.insert(0, self._target) |
288 | 284 | try: |
@@ -465,6 +461,7 @@ def complete(self, text, state): |
465 | 461 | return None |
466 | 462 |
|
467 | 463 | def gen_colors(self, buffer): |
| 464 | + import _pyrepl.utils |
468 | 465 | from _pyrepl.utils import ColorSpan, Span |
469 | 466 |
|
470 | 467 | if not buffer.strip(): |
@@ -1266,7 +1263,11 @@ def handle_command_def(self, line): |
1266 | 1263 | return False |
1267 | 1264 |
|
1268 | 1265 | def _colorize_code(self, code): |
1269 | | - if self.colorize and _pyrepl: |
| 1266 | + if self.colorize: |
| 1267 | + try: |
| 1268 | + import _pyrepl.utils |
| 1269 | + except ModuleNotFoundError: |
| 1270 | + return code |
1270 | 1271 | colors = list(_pyrepl.utils.gen_colors(code)) |
1271 | 1272 | chars, _ = _pyrepl.utils.disp_str(code, colors=colors, force_color=True) |
1272 | 1273 | code = "".join(chars) |
@@ -2084,7 +2085,6 @@ def do_run(self, arg): |
2084 | 2085 | 'e.g. "python -m pdb myscript.py"') |
2085 | 2086 | return |
2086 | 2087 | if arg: |
2087 | | - import shlex |
2088 | 2088 | argv0 = sys.argv[0:1] |
2089 | 2089 | try: |
2090 | 2090 | sys.argv = shlex.split(arg) |
@@ -3778,9 +3778,7 @@ def parse_args(): |
3778 | 3778 | # "python -m pdb -m foo -p 1" should pass "-p 1" to "foo". |
3779 | 3779 | # "python -m pdb foo.py -m bar" should pass "-m bar" to "foo.py". |
3780 | 3780 | # "python -m pdb -m foo -m bar" should pass "-m bar" to "foo". |
3781 | | - # This require some customized parsing logic to find the actual debug target. |
3782 | | - |
3783 | | - import argparse |
| 3781 | + # This requires some customized parsing logic to find the actual debug target. |
3784 | 3782 |
|
3785 | 3783 | parser = argparse.ArgumentParser( |
3786 | 3784 | usage="%(prog)s [-h] [-c command] (-m module | -p pid | pyfile) [args ...]", |
|
0 commit comments