Skip to content

Commit 08579f4

Browse files
committed
IPython console: Add note to view own objects in the Variable Explorer
This is necessary for modules not available in the cwd.
1 parent df717d6 commit 08579f4

File tree

1 file changed

+52
-19
lines changed

1 file changed

+52
-19
lines changed

spyder/plugins/ipythonconsole/widgets/namespacebrowser.py

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# Standard library imports
1313
import logging
14+
import os
1415
from pickle import PicklingError, UnpicklingError
1516
import sys
1617

@@ -29,11 +30,12 @@
2930
# Max time before giving up when making a blocking call to the kernel
3031
CALL_KERNEL_TIMEOUT = 30
3132

32-
# URL to our Github issues
33+
# URLs
3334
GH_ISSUES = "https://github.com/spyder-ide/spyder/issues/new"
3435
VAREXP_DONATIONS = (
3536
"https://www.spyder-ide.org/donate/variable-explorer-improvements"
3637
)
38+
PROJECTS_DOC_PAGE = "https://docs.spyder-ide.org/current/panes/projects.html"
3739

3840

3941
class NamepaceBrowserWidget(RichJupyterWidget):
@@ -44,6 +46,7 @@ class NamepaceBrowserWidget(RichJupyterWidget):
4446
# --- Public API --------------------------------------------------
4547
def get_value(self, name):
4648
"""Ask kernel for a value"""
49+
# ---- Reasons
4750
reason_big = _("The variable is too big to be retrieved")
4851
reason_not_picklable = _(
4952
"It was not possible to create a copy of the variable in the "
@@ -66,17 +69,12 @@ def get_value(self, name):
6669
reason_missing_package_installer = _(
6770
"The '<tt>{}</tt>' module is required to open this variable. "
6871
"Unfortunately, it's not part of our installer, which means your "
69-
"variable can't be displayed by Spyder.<br><br>"
70-
"If you want to see this fixed in the future, please donate to "
71-
"this <a href='{}'>project</a>."
72+
"variable can't be displayed by Spyder."
7273
)
7374
reason_missing_package = _(
7475
"The '<tt>{}</tt>' module is required to open this variable and "
7576
"it's not installed alongside Spyder. To fix this problem, please "
7677
"install it in the same environment that you use to run Spyder."
77-
"<br><br>"
78-
"If you want to see this addressed in the future, please donate "
79-
"to this <a href='{}'>project</a>."
8078
)
8179
reason_mismatched_numpy = _(
8280
"There is a mismatch between the Numpy versions used by Spyder "
@@ -104,6 +102,23 @@ def get_value(self, name):
104102
"Python {} or {}."
105103
)
106104

105+
# ---- Notes
106+
missing_package_note_1 = _(
107+
"If you want to see this fixed in the future, please make a "
108+
"donation <a href='{}'>here</a>."
109+
).format(VAREXP_DONATIONS)
110+
111+
# This is necessary to inform users what they need to do to explore
112+
# their own objects.
113+
# See spyder-ide/spyder#15988
114+
missing_package_note_2 = _(
115+
"If the required module is yours, you need to create a "
116+
"<a href='{}'>Spyder project</a> for it or add the path where "
117+
"it's located to the PYTHONPATH manager (available in the "
118+
"<tt>Tools</tt> menu)."
119+
).format(PROJECTS_DOC_PAGE)
120+
121+
# ---- Final message
107122
msg = _(
108123
"<br>%s<br><br>"
109124
"<b>Note</b>: If you consider this to be a valid error that needs "
@@ -112,6 +127,7 @@ def get_value(self, name):
112127
).format(GH_ISSUES)
113128
msg_without_note = "<br>%s"
114129

130+
# ---- Raise error which includes the message
115131
kernel_call_success = False
116132
show_full_msg = True
117133
try:
@@ -203,26 +219,43 @@ def get_value(self, name):
203219
if not kernel_call_success:
204220
name = e.args[0].error.name
205221
reason = reason_missing_package_target.format(name)
206-
elif is_conda_based_app():
207-
# We don't show the full message in this case so people don't
208-
# report this problem to Github and instead encourage them to
209-
# donate to the project that will solve the problem.
210-
# See spyder-ide/spyder#24922 for the details.
211-
show_full_msg = False
212-
reason = reason_missing_package_installer.format(
213-
e.name, VAREXP_DONATIONS
214-
)
215-
elif e.name.startswith('numpy._core'):
222+
elif e.name.startswith('numpy._core') and not is_conda_based_app():
216223
reason = reason_mismatched_numpy
217224
elif e.name == 'pandas.core.indexes.numeric':
218225
reason = reason_mismatched_pandas
219226
else:
220227
# We don't show the full message in this case so people don't
221228
# report this problem to Github and instead encourage them to
222229
# donate to the project that will solve the problem.
230+
# See spyder-ide/spyder#24922 for the details.
223231
show_full_msg = False
224-
reason = reason_missing_package.format(
225-
e.name, VAREXP_DONATIONS
232+
233+
if is_conda_based_app():
234+
opening_paragraph = reason_missing_package_installer
235+
else:
236+
opening_paragraph = reason_missing_package
237+
238+
notes_vmargin = "0.4em" if os.name == "nt" else "0.3em"
239+
notes = (
240+
"<style>"
241+
"ul, li {{margin-left: -15px}}"
242+
"li {{margin-bottom: {}}}"
243+
"</style>"
244+
"<ul>"
245+
"<li>{}</li>"
246+
"<li>{}</li>"
247+
"</ul>"
248+
).format(
249+
notes_vmargin,
250+
missing_package_note_1,
251+
missing_package_note_2,
252+
)
253+
254+
reason = (
255+
opening_paragraph.format(e.name)
256+
+ "<br><br>"
257+
+ _("<b>Notes</b>:")
258+
+ notes
226259
)
227260

228261
if show_full_msg:

0 commit comments

Comments
 (0)