MCPcopy Create free account
hub / github.com/datapane/datapane / _get_environment

Function _get_environment

python-client/src/datapane/ipython/environment.py:57–84  ·  view source on GitHub ↗

Determines the current IPython environment and returns an instance of the appropriate class

()

Source from the content-addressed store, hash-verified

55
56
57def _get_environment() -> PythonEnvironment:
58 """Determines the current IPython environment and returns an instance of the appropriate class"""
59
60 # TODO: change this to be a list, and put the logic in a `.supported()` method
61 if "google.colab" in sys.modules:
62 return ColabEnvironment()
63 elif {"CODESPACES", "JUPYTERLAB_PATH", "VSCODE_CWD"}.issubset(set(os.environ)):
64 return CodespacesVSCodeJupyterEnvironment()
65 elif {"CODESPACES", "JUPYTERLAB_PATH", "JPY_PARENT_PID"}.issubset(set(os.environ)):
66 return CodespacesJupyterLabEnvironment()
67 elif is_zqm_interactive_shell() and "PAPERMILL_OUTPUT_PATH" in get_ipython_user_ns():
68 return PapermillEnvironment()
69 elif is_zqm_interactive_shell() and "VSCODE_PID" in os.environ:
70 return VSCodeJupyterEnvironment()
71 elif is_zqm_interactive_shell() and {"JPY_SESSION_NAME", "JPY_PARENT_PID"}.issubset(set(os.environ)):
72 return JupyterLabEnvironment()
73 elif is_zqm_interactive_shell() and "JPY_PARENT_PID" in os.environ:
74 return JupyterNotebookEnvironment()
75 elif is_zqm_interactive_shell():
76 return UnsupportedNotebookEnvironment()
77 elif "PYCHARM_HOSTED" in os.environ:
78 return PyCharmEnvironment()
79 elif "VSCODE_PID" in os.environ:
80 return VSCodeEnvironment()
81 elif is_terminal_interactive_shell():
82 return IPythonTerminalEnvironment()
83 else:
84 return UnrecognizedEnvironment()
85
86
87class PythonEnvironment:

Callers 1

get_environmentFunction · 0.85

Tested by

no test coverage detected