1
+ import errno
1
2
import os
2
3
import sys
3
4
5
+
4
6
CAN_USE_PYREPL : bool
5
- if sys .platform != "win32" :
6
- CAN_USE_PYREPL = True
7
+ FAIL_REASON : str
8
+ try :
9
+ if sys .platform == "win32" and sys .getwindowsversion ().build < 10586 :
10
+ raise RuntimeError ("Windows 10 TH2 or later required" )
11
+ if not os .isatty (sys .stdin .fileno ()):
12
+ raise OSError (errno .ENOTTY , "tty required" , "stdin" )
13
+ from .simple_interact import check
14
+ if err := check ():
15
+ raise RuntimeError (err )
16
+ except Exception as e :
17
+ CAN_USE_PYREPL = False
18
+ FAIL_REASON = f"warning: can't use pyrepl: { e } "
7
19
else :
8
- CAN_USE_PYREPL = sys .getwindowsversion ().build >= 10586 # Windows 10 TH2
20
+ CAN_USE_PYREPL = True
21
+ FAIL_REASON = ""
9
22
10
23
11
24
def interactive_console (mainmodule = None , quiet = False , pythonstartup = False ):
12
- global CAN_USE_PYREPL
13
25
if not CAN_USE_PYREPL :
26
+ if not os .environ .get ('PYTHON_BASIC_REPL' , None ) and FAIL_REASON :
27
+ from .trace import trace
28
+ trace (FAIL_REASON )
29
+ print (FAIL_REASON , file = sys .stderr )
14
30
return sys ._baserepl ()
15
31
16
32
if mainmodule :
@@ -20,6 +36,7 @@ def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
20
36
namespace = __main__ .__dict__
21
37
namespace .pop ("__pyrepl_interactive_console" , None )
22
38
39
+ # sys._baserepl() above does this internally, we do it here
23
40
startup_path = os .getenv ("PYTHONSTARTUP" )
24
41
if pythonstartup and startup_path :
25
42
import tokenize
@@ -34,22 +51,5 @@ def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
34
51
if not hasattr (sys , "ps2" ):
35
52
sys .ps2 = "... "
36
53
37
- run_interactive = None
38
- try :
39
- import errno
40
- if not os .isatty (sys .stdin .fileno ()):
41
- raise OSError (errno .ENOTTY , "tty required" , "stdin" )
42
- from .simple_interact import check
43
- if err := check ():
44
- raise RuntimeError (err )
45
- from .simple_interact import run_multiline_interactive_console
46
- run_interactive = run_multiline_interactive_console
47
- except Exception as e :
48
- from .trace import trace
49
- msg = f"warning: can't use pyrepl: { e } "
50
- trace (msg )
51
- print (msg , file = sys .stderr )
52
- CAN_USE_PYREPL = False
53
- if run_interactive is None :
54
- return sys ._baserepl ()
55
- run_interactive (namespace )
54
+ from .simple_interact import run_multiline_interactive_console
55
+ run_multiline_interactive_console (namespace )
0 commit comments