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

Add support for Spyder in tqdm.auto #1559

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion tqdm/autonotebook.py
Expand Up @@ -6,6 +6,7 @@
>>> for i in trange(10):
... ...
"""
import os
import sys
from warnings import warn

Expand All @@ -21,7 +22,11 @@
except Exception:
from .std import tqdm, trange
else: # pragma: no cover
from .notebook import tqdm, trange
if "SPY_TESTING" in os.environ:
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • is SPY_TESTING always defined inside a spyder environment?
  • is it fairly plausible for SPY_TESTING to be defined outside spyder?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have used this approach for many years without any issues. Checking environment variables of the form SPY_XXXX is also suggested in https://stackoverflow.com/questions/53829284/how-to-know-if-a-script-is-running-in-spyder-or-any-other-python-ide.

I will create an issue at the Spyder issue tracker to check this is a good approach.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@casperdcl I have updated the detection method based on the suggestion by the Spyder devs. See spyder-ide/spyder#21929

# we are running in the Spyder environment
from .std import tqdm, trange
else:
from .notebook import tqdm, trange
from .std import TqdmExperimentalWarning
warn("Using `tqdm.autonotebook.tqdm` in notebook mode."
" Use `tqdm.tqdm` instead to force console mode"
Expand Down