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

Spyder reloading wrong submodule after directory change #13076

Open jennirinker opened 4 years ago

jennirinker commented 4 years ago

Issue Report Checklist

Problem Description

If I have two submodules (e.g., _utils.py) in two different directories and I have loaded one, spyder attempts to reload the same one even after I switch working directories in the "Files" pane.

What steps reproduce the problem?

  1. Have two same-names submodules, e.g. _utils.py, in two separate directories.
  2. With working directory in the first folder, import some function from the submodule (e.g. from _utils import example 1).
  3. Use the Files pane to change spyder's working directory to the other folder.
  4. Try to import a different function from the other submodulde (e.g. from _utils import example_2)

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

Spyder throws an ImportError if example_2 not defined in the first submodule.

Versions

Dependencies


# Mandatory:
atomicwrites >=1.2.0           :  1.4.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.4.1 (OK)
diff_match_patch >=20181111    :  20181111 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.15.0 (OK)
jedi =0.15.2                   :  0.15.2 (OK)
nbconvert >=4.0                :  5.6.1 (OK)
numpydoc >=0.6.0               :  1.0.0 (OK)
paramiko >=2.4.0               :  2.7.1 (OK)
parso =0.5.2                   :  0.5.2 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.7.0 (OK)
pygments >=2.0                 :  2.6.1 (OK)
pylint >=0.25                  :  2.5.3 (OK)
pyls >=0.31.9;<0.32.0          :  0.31.10 (OK)
qdarkstyle >=2.8               :  2.8.1 (OK)
qtawesome >=0.5.7              :  0.7.2 (OK)
qtconsole >=4.6.0              :  4.7.4 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.4 (OK)
sphinx >=0.6.6                 :  3.0.4 (OK)
spyder_kernels >=1.9.1;<1.10.0 :  1.9.1 (OK)
watchdog                       :  None (OK)
zmq >=17                       :  18.1.1 (OK)

# Optional:
cython >=0.21                  :  None (OK)
matplotlib >=2.0.0             :  3.0.2 (OK)
numpy >=1.7                    :  1.15.4 (OK)
pandas >=0.13.1                :  0.24.0 (OK)
scipy >=0.17.0                 :  1.2.0 (OK)
sympy >=0.7.3                  :  None (OK)
goanpeca commented 4 years ago

Hi @jennirinker, thanks for the report. It seems to be an odd usage, but indeed a problem. @impact27 thoughts on how we could solve this?

impact27 commented 4 years ago

Is there an option to disable module reloading? This would solve this. Also we could catch the error so we could print a message along the lines of: "An import error was thrown while reloading the module {}. You can disable automatic module reloading by ..."

jennirinker commented 4 years ago

"Odd usage" is my middle name. :/

@impact27, do you mean like a global option to disable reloading? Because I think reloading in general is desired behaviour.

Would it be possible to have an internal flag that tracks the last-run cwd and compares with the current cwd on execution? Then, if the directories are different, it reimports modules? Sorry if this solution isn't implementable, I'm not familiar with the inner workings of spyder's executions.

ccordoba12 commented 4 years ago

The only way to avoid this would be to add an option so users can exclude particular directories from the reload mechanism.

@impact27, what do you think?

impact27 commented 4 years ago

CWD is not a really good way because it can change while the code executes, so it is not robust. Excluding directories sounds more reasonable.

ccordoba12 commented 4 years ago

Agreed. @impact27, could you help us to implement this functionality?