Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pandas/io/formats/console.py : 12%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Internal module for console introspection
3"""
5from shutil import get_terminal_size
8def get_console_size():
9 """
10 Return console size as tuple = (width, height).
12 Returns (None,None) in non-interactive session.
13 """
14 from pandas import get_option
16 display_width = get_option("display.width")
17 display_height = get_option("display.max_rows")
19 # Consider
20 # interactive shell terminal, can detect term size
21 # interactive non-shell terminal (ipnb/ipqtconsole), cannot detect term
22 # size non-interactive script, should disregard term size
24 # in addition
25 # width,height have default values, but setting to 'None' signals
26 # should use Auto-Detection, But only in interactive shell-terminal.
27 # Simple. yeah.
29 if in_interactive_session():
30 if in_ipython_frontend():
31 # sane defaults for interactive non-shell terminal
32 # match default for width,height in config_init
33 from pandas._config.config import get_default_val
35 terminal_width = get_default_val("display.width")
36 terminal_height = get_default_val("display.max_rows")
37 else:
38 # pure terminal
39 terminal_width, terminal_height = get_terminal_size()
40 else:
41 terminal_width, terminal_height = None, None
43 # Note if the User sets width/Height to None (auto-detection)
44 # and we're in a script (non-inter), this will return (None,None)
45 # caller needs to deal.
46 return (display_width or terminal_width, display_height or terminal_height)
49# ----------------------------------------------------------------------
50# Detect our environment
53def in_interactive_session():
54 """
55 Check if we're running in an interactive shell.
57 Returns
58 -------
59 bool
60 True if running under python/ipython interactive shell.
61 """
62 from pandas import get_option
64 def check_main():
65 try:
66 import __main__ as main
67 except ModuleNotFoundError:
68 return get_option("mode.sim_interactive")
69 return not hasattr(main, "__file__") or get_option("mode.sim_interactive")
71 try:
72 return __IPYTHON__ or check_main() # noqa
73 except NameError:
74 return check_main()
77def in_ipython_frontend():
78 """
79 Check if we're inside an an IPython zmq frontend.
81 Returns
82 -------
83 bool
84 """
85 try:
86 ip = get_ipython() # noqa
87 return "zmq" in str(type(ip)).lower()
88 except NameError:
89 pass
91 return False