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

allow click to interoperate with jupyter notebooks #918

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions click/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,17 @@ def echo(message=None, file=None, nl=True, err=False, color=None):
:param color: controls if the terminal supports ANSI colors or not. The
default is autodetection.
"""
if file is None:
if is_running_jupyter():
if err:
file = _default_text_stderr()
file = sys.stderr
else:
file = _default_text_stdout()
file = sys.stdout
else:

This comment was marked as off-topic.

This comment was marked as off-topic.

if file is None:
if err:
file = _default_text_stderr()
else:
file = _default_text_stdout()

# Convert non bytes/text into the native string type.
if message is not None and not isinstance(message, echo_native_types):
Expand Down Expand Up @@ -348,6 +354,11 @@ def get_os_args():
return sys.argv[1:]


def is_running_jupyter():
"""Return if running inside a Jupyter Notebook"""
return bool(os.getenv("JPY_PARENT_PID"))


def format_filename(filename, shorten=False):
"""Formats a filename for user display. The main purpose of this
function is to ensure that the filename can be displayed at all. This
Expand Down