spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.22k stars 1.59k forks source link

Console is cleared when running in a dedicated console #20408

Open schtandard opened 1 year ago

schtandard commented 1 year ago

Issue Report Checklist

Problem Description

When running every script in a dedicated console, the console is always cleared before running, irrespective of the relevant setting.

What steps reproduce the problem?

  1. In Preferences -> Run under Console select Execute in a dedicated console.
  2. Under General settings do not check Remove all variables before execution.
  3. Run a script.
  4. Run it again.

What is the expected output? What do you see instead?

I would expect subsequent runs of the same script to execute in the console without removing any variables, just like when using Execute in current console. Instead, a %clear is issued before every run, removing all variables before execution. The setting that seems to be intended to control this behavior appears not to have any effect.

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0          :  1.4.1 (OK)
chardet >=2.0.0               :  5.1.0 (OK)
cloudpickle >=0.5.0           :  2.2.1 (OK)
cookiecutter >=1.6.0          :  2.1.1 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.0.2 (OK)
IPython >=7.31.1;<9.0.0       :  8.8.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.2 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  4.17.3 (OK)
keyring >=17.0.0              :  23.13.1 (OK)
nbconvert >=4.0               :  7.2.8 (OK)
numpydoc >=0.6.0              :  1.5.0 (OK)
paramiko >=2.4.0              :  2.12.0 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.9.4 (OK)
pygments >=2.0                :  2.14.0 (OK)
pylint >=2.5.0;<3.0           :  2.15.10 (OK)
pylint_venv >=2.1.1           :  2.3.0 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.7.1;<1.8.0          :  1.7.1 (OK)
pylsp_black >=1.2.0           :  1.2.1 (OK)
qdarkstyle >=3.0.2;<3.1.0     :  3.0.3 (OK)
qstylizer >=0.2.2             :  0.2.2 (OK)
qtawesome >=1.2.1             :  1.2.2 (OK)
qtconsole >=5.4.0;<5.5.0      :  5.4.0 (OK)
qtpy >=2.1.0                  :  2.3.0 (OK)
rtree >=0.9.7                 :  1.0.1 (OK)
setuptools >=49.6.0           :  66.0.0 (OK)
sphinx >=0.6.6                :  6.1.3 (OK)
spyder_kernels >=2.4.2;<2.5.0 :  2.4.2 (OK)
textdistance >=4.2.0          :  4.5.0 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.2.1 (OK)
zmq >=22.1.0                  :  25.0.0 (OK)

# Optional:
cython >=0.21                 :  None (NOK)
matplotlib >=3.0.0            :  3.6.3 (OK)
numpy >=1.7                   :  1.24.1 (OK)
pandas >=1.1.1                :  1.5.3 (OK)
scipy >=0.17.0                :  1.10.0 (OK)
sympy >=0.7.3                 :  1.11.1 (OK)
dalthviz commented 1 year ago

Hi @schtandard thank you for the feedback! I think I was able to reproduce this. Did you by any chance set a custom preference for your files using the Run > Configuration per file... option? The thing is that the config that you can set from the preferences is the one that is referenced from the Run configuration per file dialog as default so maybe you have the option Run file with custom configuration set in that dialog?

This the config I have in order to reproduce this. Preferences config (default) vs Run configuration per file (the one that can override the default config):

imagen

Let us know if the info above helps!

schtandard commented 1 year ago

Hi @dalthviz, thanks for looking into this. I have not set any preferences per file, no. Here's a screenshot of my settings.

image

schtandard commented 1 year ago

Just in case, I also just tested it with per file configuration (identical to the default) and there is no change; the variables are still cleared before execution.

dalthviz commented 1 year ago

Rereading the OP, you mean by variables removed that they disappear from the Variable Explorer? I think the %clear magic only removes the prompts and I think that is not configurable. So basically what you want is to preserve the prompt/console output between dedicated console executions right?

schtandard commented 1 year ago

Hmm, it seems you are right. I thought I had verified that it also cleared the variables, but I can't reproduce that now.

I would still prefer for the %clear not to happen at all. The effects of previous commands in the console are not erased, so erasing their inputs and outputs is confusing and unnecessarily makes them unavailable (both through scrolling and through ipython's In[] and Out[] magic). It also does not match the behavior of Spyder's default setting to Execute in current console, where no %clear is issued (no matter if variables are cleared or not).

Seeing as the issue as reported is non-existent, should I close it and open an appropriate feature request for removing the %clear or making it configurable? Or should I just leave this one open instead?

ccordoba12 commented 1 year ago

I would still prefer for the %clear not to happen at all. The effects of previous commands in the console are not erased, so erasing their inputs and outputs is confusing and unnecessarily makes them unavailable ... It also does not match the behavior of Spyder's default setting to Execute in current console, where no %clear is issued (no matter if variables are cleared or not).

I think this is a fair point. We clear dedicated consoles after each execution because that's how they worked in the (very old) Spyder 2 days.

We'll take a look at this for Spyder 6, to be released later this year.