MCPcopy Index your code
hub / github.com/RustPython/RustPython / interactive_console

Function interactive_console

Lib/_pyrepl/main.py:24–59  ·  view source on GitHub ↗
(mainmodule=None, quiet=False, pythonstartup=False)

Source from the content-addressed store, hash-verified

22
23
24def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
25 if not CAN_USE_PYREPL:
26 if not os.getenv('PYTHON_BASIC_REPL') and FAIL_REASON:
27 from .trace import trace
28 trace(FAIL_REASON)
29 print(FAIL_REASON, file=sys.stderr)
30 return sys._baserepl()
31
32 if mainmodule:
33 namespace = mainmodule.__dict__
34 else:
35 import __main__
36 namespace = __main__.__dict__
37 namespace.pop("__pyrepl_interactive_console", None)
38
39 # sys._baserepl() above does this internally, we do it here
40 startup_path = os.getenv("PYTHONSTARTUP")
41 if pythonstartup and startup_path:
42 sys.audit("cpython.run_startup", startup_path)
43
44 import tokenize
45 with tokenize.open(startup_path) as f:
46 startup_code = compile(f.read(), startup_path, "exec")
47 exec(startup_code, namespace)
48
49 # set sys.{ps1,ps2} just before invoking the interactive interpreter. This
50 # mimics what CPython does in pythonrun.c
51 if not hasattr(sys, "ps1"):
52 sys.ps1 = ">>> "
53 if not hasattr(sys, "ps2"):
54 sys.ps2 = "... "
55
56 from .console import InteractiveColoredConsole
57 from .simple_interact import run_multiline_interactive_console
58 console = InteractiveColoredConsole(namespace, filename="<stdin>")
59 run_multiline_interactive_console(console)

Callers

nothing calls this directly

Calls 10

traceFunction · 0.90
hasattrFunction · 0.85
printFunction · 0.50
compileFunction · 0.50
execFunction · 0.50
popMethod · 0.45
openMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected