Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Databricks is not identified as Jupyter #2422

Closed
noklam opened this issue Jul 27, 2022 · 5 comments · Fixed by #2424
Closed

[BUG] Databricks is not identified as Jupyter #2422

noklam opened this issue Jul 27, 2022 · 5 comments · Fixed by #2424

Comments

@noklam
Copy link
Contributor

noklam commented Jul 27, 2022

You may find a solution to your problem in the docs or issues.

Describe the bug

Databricks is not considered as "Jupyter", therefore JUPYTER_LINES and JUPYTER_COLUMNS has no effect on the console log

Provide a minimal code example that demonstrates the issue if you can. If the issue is visual in nature, consider posting a screenshot.

Databricks has a Ipython type InteractiveShell which is neither Ipython or ZMQInteractiveShell

image

def _is_jupyter() -> bool:  # pragma: no cover
    """Check if we're running in a Jupyter notebook."""
    try:
        get_ipython  # type: ignore[name-defined]
    except NameError:
        return False
    ipython = get_ipython()  # type: ignore[name-defined]
    shell = ipython.__class__.__name__
    if "google.colab" in str(ipython.__class__) or shell == "ZMQInteractiveShell":
        return True  # Jupyter notebook or qtconsole
    elif shell == "TerminalInteractiveShell":
        return False  # Terminal running IPython
    else:
        return False  # Other type (?)

If you're using Rich in a terminal:

python -m rich.diagnose
pip freeze | grep rich

If you're using Rich in a Jupyter Notebook, run the following snippet in a cell
and paste the output in your bug report.

from rich.diagnose import report
report()
╭────────────────────── <class 'rich.console.Console'> ───────────────────────╮
│ A high level console interface.                                             │
│                                                                             │
│ ╭─────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=80 None>                                                 │ │
│ ╰─────────────────────────────────────────────────────────────────────────╯ │
│                                                                             │
│     color_system = None                                                     │
│         encoding = 'utf-8'                                                  │
│             file = <PythonShellImpl.ConsoleBuffer object at 0x7f462b809970> │
│           height = 25                                                       │
│    is_alt_screen = False                                                    │
│ is_dumb_terminal = False                                                    │
│   is_interactive = False                                                    │
│       is_jupyter = False                                                    │
│      is_terminal = False                                                    │
│   legacy_windows = False                                                    │
│         no_color = False                                                    │
│          options = ConsoleOptions(                                          │
│                        size=ConsoleDimensions(width=80, height=25),         │
│                        legacy_windows=False,                                │
│                        min_width=1,                                         │
│                        max_width=80,                                        │
│                        is_terminal=False,                                   │
│                        encoding='utf-8',                                    │
│                        max_height=25,                                       │
│                        justify=None,                                        │
│                        overflow=None,                                       │
│                        no_wrap=False,                                       │
│                        highlight=None,                                      │
│                        markup=None,                                         │
│                        height=None                                          │
│                    )                                                        │
│            quiet = False                                                    │
│           record = False                                                    │
│         safe_box = True                                                     │
│             size = ConsoleDimensions(width=80, height=25)                   │
│        soft_wrap = False                                                    │
│           stderr = False                                                    │
│            style = None                                                     │
│         tab_size = 8                                                        │
│            width = 80                                                       │
╰─────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'unknown',             │
│     'COLORTERM': None,             │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': '200',      │
│     'JUPYTER_LINES': '50',         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Linux"
@willmcgugan
Copy link
Collaborator

There is no future proof way of detecting Jupyter that I know of. I'd accept a PR for whatever fudge is required to detect Databricks...

@datajoely
Copy link

I've dumped the environment variables that are present in a Databricks notebook here

Potentially checking for both this var name and value would be the most reliable apporach:

DATABRICKS_ROOT_VIRTUALENV_ENV = "/databricks/python3"

@noklam
Copy link
Contributor Author

noklam commented Jul 27, 2022

I'll make a PR if this is ok, try to detect DATABRICKS_ROOT_VIRTUALENV_ENV.

@noklam
Copy link
Contributor Author

noklam commented Jul 28, 2022

PR created at #2424

@github-actions
Copy link

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants