-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathplatform.py
More file actions
54 lines (43 loc) · 1.77 KB
/
platform.py
File metadata and controls
54 lines (43 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
def is_jupyter() -> bool:
"""Check if the module is running on Jupyter notebook/console.
Note - there might be better way to check if the code is running on a jupyter notebook or not,
but this hacky way still works.
Ref:
https://stackoverflow.com/questions/15411967/how-can-i-check-if-code-is-executed-in-the-ipython-notebook
Returns:
bool: True if the module is running on Jupyter notebook or Jupyter console, False otherwise.
"""
# Should check is_databricks() and is_synapse() first since they also use the same ZMQ interactive shell.
if is_databricks() or is_synapse():
return False
try:
# Pre-loaded module `get_ipython()` tells you whether you are running inside IPython or not.
shell_name = get_ipython().__class__.__name__
# `ZMQInteractiveShell` tells you if this is an interactive mode (notebook).
if shell_name == "ZMQInteractiveShell":
return True
else:
return False
except NameError:
return False
def is_databricks() -> bool:
"""Check if the module is running on Databricks.
Returns:
bool: True if the module is running on Databricks notebook, False otherwise.
"""
# Note, this is a hacky way to check if the code is running on Databricks.
if "DATABRICKS_RUNTIME_VERSION" in os.environ:
return True
else:
return False
def is_synapse() -> bool:
"""Check if the module is running on Azure Synapse.
Returns:
bool: True if the module is running on Azure Synapse notebook, False otherwise.
"""
# Note, this is a hacky way to check if the code is running on Synapse.
if "SYNAPSE_ENABLE_CONFIG_MERGE_RULE" in os.environ:
return True
else:
return False