-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathplatform.py
More file actions
45 lines (36 loc) · 1.39 KB
/
platform.py
File metadata and controls
45 lines (36 loc) · 1.39 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
"""Platform utilities.
Refs: https://github.com/microsoft/recommenders/blob/main/recommenders/utils/notebook_utils.py
"""
from pathlib import Path
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.
"""
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.
"""
try:
if str(Path(".").resolve()) == "/databricks/driver":
return True
else:
return False
except NameError:
return False
# TODO maybe add is_synapse()