Spyder: "Projects > Recent" always opens last project

Created on 13 Aug 2019  路  9Comments  路  Source: spyder-ide/spyder

Description

What steps will reproduce the problem?

  • Create 2+ projects
  • Click Projects:recent
  • Select any except top
  • Frustrate :D

Versions

  • Spyder version: 4.0.0b4
  • Python version: 3.7.3
  • Qt version: 5.12.4
  • PyQt5 version: 5.12.3
  • Operating System: Linux 4.19.0-5-amd64

Dependencies

pygments >=2.0    :  2.4.2 (OK)
qdarkstyle >=2.6.4:  2.7 (OK)
sphinx >=0.6.6    :  2.1.2 (OK)
psutil >=0.3      :  5.6.3 (OK)
pyls >=0.27.0     :  v0.28.1 (OK)
nbconvert >=4.0   :  5.6.0 (OK)
pandas >=0.13.1   :  None (NOK)
numpy >=1.7       :  None (NOK)
sympy >=0.7.3     :  None (NOK)
cython >=0.21     :  None (NOK)
qtconsole >=4.5.2 :  4.5.2 (OK)
IPython >=4.0     :  7.7.0 (OK)
matplotlib >=2.0.0:  None (NOK)
pylint >=0.25     :  2.3.1 (OK)
Projects Bug

All 9 comments

It's really funny, but I pulled solution earlier: https://github.com/spyder-ide/spyder/pull/8662/files
Today solution is almost the same

@dalthviz, please verify if this is the case or not.

@ccordoba12, I added locally almost the same fixes and now it works fine for me.
This is the same pattern: someone does not know about scope of variables. Unfortunately, spyder does not display annotations.
So, when i would have free time, i can create merge request with this fix

@ccordoba12 @kai3341 testing it works for me as expected with conda and pip:

p

Conda env details:

# packages in environment at C:\Users\Daniel\Anaconda3\envs\testing:
#
# Name                    Version                   Build  Channel
alabaster                 0.7.12                   py37_0
argh                      0.26.2                py37_1001    spyder-ide
asn1crypto                0.24.0                   py37_0
astroid                   2.2.5                    py37_0
atomicwrites              1.3.0                    py37_1
attrs                     19.1.0                   py37_1
autopep8                  1.4.4                      py_0
babel                     2.7.0                      py_0
backcall                  0.1.0                    py37_0
blas                      1.0                         mkl
bleach                    3.1.0                    py37_0
ca-certificates           2019.5.15                     0
certifi                   2019.6.16                py37_1
cffi                      1.12.3           py37h7a1dbc1_0
chardet                   3.0.4                 py37_1003
cloudpickle               1.2.1                      py_0
colorama                  0.4.1                    py37_0
cryptography              2.7              py37h7a1dbc1_0
decorator                 4.4.0                    py37_1
defusedxml                0.6.0                      py_0
diff-match-patch          20181111                   py_0    spyder-ide
docutils                  0.15.1                   py37_0
entrypoints               0.3                      py37_0
future                    0.17.1                   py37_0
icc_rt                    2019.0.0             h0cc432a_1
icu                       58.2                 ha66f8fd_1
idna                      2.8                      py37_0
imagesize                 1.1.0                    py37_0
importlib_metadata        0.19                     py37_0
intel-openmp              2019.4                      245
ipykernel                 5.1.1            py37h39e3cac_0
ipython                   7.7.0            py37h39e3cac_0
ipython_genutils          0.2.0                    py37_0
isort                     4.3.21                   py37_0
jedi                      0.13.3                   py37_0
jinja2                    2.10.1                   py37_0
jpeg                      9b                   hb83a4c4_2
jsonschema                3.0.1                    py37_0
jupyter_client            5.3.1                      py_0
jupyter_core              4.5.0                      py_0
keyring                   18.0.0                   py37_0
lazy-object-proxy         1.4.1            py37he774522_0
libpng                    1.6.37               h2a8f88b_0
libsodium                 1.0.16               h9d3ae62_0
markupsafe                1.1.1            py37he774522_0
mccabe                    0.6.1                    py37_1
mistune                   0.8.4            py37he774522_0
mkl                       2019.4                      245
mkl_fft                   1.0.12           py37h14836fe_0
mkl_random                1.0.2            py37h343c172_0
nbconvert                 5.5.0                      py_0
nbformat                  4.4.0                    py37_0
numpy                     1.16.4           py37h19fb1c0_0
numpy-base                1.16.4           py37hc3f5095_0
numpydoc                  0.9.1                      py_0
openssl                   1.1.1c               he774522_1
packaging                 19.0                     py37_0
pandas                    0.25.0           py37ha925a31_0
pandoc                    2.2.3.2                       0
pandocfilters             1.4.2                    py37_1
parso                     0.5.0                      py_0
pathtools                 0.1.2                      py_1    spyder-ide
pexpect                   4.7.0                    py37_0
pickleshare               0.7.5                    py37_0
pip                       19.1.1                   py37_0
pluggy                    0.12.0                     py_0
prompt_toolkit            2.0.9                    py37_0
psutil                    5.6.3            py37he774522_0
pycodestyle               2.5.0                    py37_0
pycparser                 2.19                     py37_0
pydocstyle                3.0.0                    py37_0
pyflakes                  2.1.1                    py37_0
pygments                  2.4.2                      py_0
pylint                    2.3.1                    py37_0
pyopenssl                 19.0.0                   py37_0
pyparsing                 2.4.0                      py_0
pyqt                      5.9.2            py37h6538335_2
pyrsistent                0.14.11          py37he774522_0
pysocks                   1.7.0                    py37_0
python                    3.7.3                h8c8aaf0_1
python-dateutil           2.8.0                    py37_0
python-jsonrpc-server     0.1.2                      py_0    spyder-ide
python-language-server    0.28.0                   py37_0    spyder-ide
pytz                      2019.1                     py_0
pywin32                   223              py37hfa6e2cd_1
pyxdg                     0.26                       py_0    spyder-ide
pyyaml                    5.1.1            py37he774522_0
pyzmq                     18.0.0           py37ha925a31_0
qdarkstyle                2.7                        py_0    spyder-ide
qt                        5.9.7            vc14h73c81de_0
qtawesome                 0.5.7                    py37_1
qtconsole                 4.5.2                      py_0
qtpy                      1.8.0                      py_0
requests                  2.22.0                   py37_0
rope                      0.14.0                     py_0
setuptools                41.0.1                   py37_0
sip                       4.19.8           py37h6538335_0
six                       1.12.0                   py37_0
snowballstemmer           1.9.0                      py_0
sphinx                    2.1.2                      py_0
sphinxcontrib-applehelp   1.0.1                      py_0
sphinxcontrib-devhelp     1.0.1                      py_0
sphinxcontrib-htmlhelp    1.0.2                      py_0
sphinxcontrib-jsmath      1.0.1                      py_0
sphinxcontrib-qthelp      1.0.2                      py_0
sphinxcontrib-serializinghtml 1.1.3                      py_0
spyder                    4.0.0b4                  py37_0    spyder-ide
spyder-kernels            1.4.0                    py37_0    spyder-ide
sqlite                    3.29.0               he774522_0
testpath                  0.4.2                    py37_0
tornado                   6.0.3            py37he774522_0
traitlets                 4.3.2                    py37_0
urllib3                   1.24.2                   py37_0
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.15.26706          h3a45250_4
watchdog                  0.9.0                    py37_1    spyder-ide
wcwidth                   0.1.7                    py37_0
webencodings              0.5.1                    py37_1
wheel                     0.33.4                   py37_0
win_inet_pton             1.1.0                    py37_0
wincertstore              0.2                      py37_0
wrapt                     1.11.2           py37he774522_0
yaml                      0.1.7                hc54c509_2
yapf                      0.28.0                     py_0
zeromq                    4.3.1                h33f27b4_3
zipp                      0.5.2                      py_0
zlib                      1.2.11               h62dcd97_3

pip env details:

# packages in environment at C:\Users\Daniel\Anaconda3\envs\pipprojects:
#
# Name                    Version                   Build  Channel
alabaster                 0.7.12                   pypi_0    pypi
argh                      0.26.2                   pypi_0    pypi
asn1crypto                0.24.0                   pypi_0    pypi
astroid                   2.2.5                    pypi_0    pypi
atomicwrites              1.3.0                    pypi_0    pypi
attrs                     19.1.0                   pypi_0    pypi
autopep8                  1.4.4                    pypi_0    pypi
babel                     2.7.0                    pypi_0    pypi
backcall                  0.1.0                    pypi_0    pypi
bcrypt                    3.1.7                    pypi_0    pypi
bleach                    3.1.0                    pypi_0    pypi
certifi                   2019.6.16                py36_0
cffi                      1.12.3                   pypi_0    pypi
chardet                   3.0.4                    pypi_0    pypi
cloudpickle               1.2.1                    pypi_0    pypi
colorama                  0.4.1                    pypi_0    pypi
cryptography              2.7                      pypi_0    pypi
decorator                 4.4.0                    pypi_0    pypi
defusedxml                0.6.0                    pypi_0    pypi
diff-match-patch          20181111                 pypi_0    pypi
docutils                  0.14                     pypi_0    pypi
entrypoints               0.3                      pypi_0    pypi
future                    0.17.1                   pypi_0    pypi
helpdev                   0.6.10                   pypi_0    pypi
idna                      2.8                      pypi_0    pypi
imagesize                 1.1.0                    pypi_0    pypi
importlib-metadata        0.18                     pypi_0    pypi
ipykernel                 5.1.1                    pypi_0    pypi
ipython                   7.6.1                    pypi_0    pypi
ipython-genutils          0.2.0                    pypi_0    pypi
isort                     4.3.21                   pypi_0    pypi
jedi                      0.13.3                   pypi_0    pypi
jinja2                    2.10.1                   pypi_0    pypi
jsonschema                3.0.1                    pypi_0    pypi
jupyter-client            5.3.1                    pypi_0    pypi
jupyter-core              4.5.0                    pypi_0    pypi
keyring                   19.0.2                   pypi_0    pypi
lazy-object-proxy         1.4.1                    pypi_0    pypi
markupsafe                1.1.1                    pypi_0    pypi
mccabe                    0.6.1                    pypi_0    pypi
mistune                   0.8.4                    pypi_0    pypi
nbconvert                 5.5.0                    pypi_0    pypi
nbformat                  4.4.0                    pypi_0    pypi
numpydoc                  0.9.1                    pypi_0    pypi
packaging                 19.0                     pypi_0    pypi
pandocfilters             1.4.2                    pypi_0    pypi
paramiko                  2.6.0                    pypi_0    pypi
parso                     0.5.1                    pypi_0    pypi
pathtools                 0.1.2                    pypi_0    pypi
pexpect                   4.7.0                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pip                       19.1.1                   py36_0
pluggy                    0.12.0                   pypi_0    pypi
prompt-toolkit            2.0.9                    pypi_0    pypi
psutil                    5.6.3                    pypi_0    pypi
ptyprocess                0.6.0                    pypi_0    pypi
pycodestyle               2.5.0                    pypi_0    pypi
pycparser                 2.19                     pypi_0    pypi
pydocstyle                4.0.0                    pypi_0    pypi
pyflakes                  2.1.1                    pypi_0    pypi
pygments                  2.4.2                    pypi_0    pypi
pylint                    2.3.1                    pypi_0    pypi
pynacl                    1.3.0                    pypi_0    pypi
pyparsing                 2.4.0                    pypi_0    pypi
pyqt5                     5.12.3                   pypi_0    pypi
pyqt5-sip                 4.19.18                  pypi_0    pypi
pyqtwebengine             5.12.1                   pypi_0    pypi
pyrsistent                0.15.3                   pypi_0    pypi
python                    3.6.8                h9f7ef89_7
python-dateutil           2.8.0                    pypi_0    pypi
python-jsonrpc-server     0.2.0                    pypi_0    pypi
python-language-server    0.27.0                   pypi_0    pypi
pytz                      2019.1                   pypi_0    pypi
pywin32-ctypes            0.2.0                    pypi_0    pypi
pyyaml                    5.1.1                    pypi_0    pypi
pyzmq                     18.0.2                   pypi_0    pypi
qdarkstyle                2.7                      pypi_0    pypi
qtawesome                 0.5.7                    pypi_0    pypi
qtconsole                 4.5.2                    pypi_0    pypi
qtpy                      1.8.0                    pypi_0    pypi
requests                  2.22.0                   pypi_0    pypi
rope                      0.14.0                   pypi_0    pypi
setuptools                41.0.1                   py36_0
six                       1.12.0                   pypi_0    pypi
snowballstemmer           1.9.0                    pypi_0    pypi
sphinx                    2.1.2                    pypi_0    pypi
sphinxcontrib-applehelp   1.0.1                    pypi_0    pypi
sphinxcontrib-devhelp     1.0.1                    pypi_0    pypi
sphinxcontrib-htmlhelp    1.0.2                    pypi_0    pypi
sphinxcontrib-jsmath      1.0.1                    pypi_0    pypi
sphinxcontrib-qthelp      1.0.2                    pypi_0    pypi
sphinxcontrib-serializinghtml 1.1.3                    pypi_0    pypi
spyder                    4.0.0b4                  pypi_0    pypi
spyder-kernels            1.4.0                    pypi_0    pypi
sqlite                    3.29.0               he774522_0
testpath                  0.4.2                    pypi_0    pypi
tornado                   6.0.3                    pypi_0    pypi
traitlets                 4.3.2                    pypi_0    pypi
typed-ast                 1.4.0                    pypi_0    pypi
urllib3                   1.25.3                   pypi_0    pypi
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.15.26706          h3a45250_4
watchdog                  0.9.0                    pypi_0    pypi
wcwidth                   0.1.7                    pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
wheel                     0.33.4                   py36_0
wincertstore              0.2              py36h7fe50ca_0
wrapt                     1.11.2                   pypi_0    pypi
yapf                      0.28.0                   pypi_0    pypi
zipp                      0.5.2                    pypi_0    pypi

@kai3341 do you note any significant difference between your packages list and mine?

@dalthviz, an error happend not in foreign package. Look here:
https://github.com/spyder-ide/spyder/blob/master/spyder/plugins/projects/plugin.py#L226
This is root of problem. I suggested to use regular function. In this case it will be:

    def build_opener(self, project):
        def opener(*args, **kwargs):
            self.open_project(path=project)
        return opener
...
                    action = create_action(
                        self,
                        name,
                        icon=ima.icon('project'),
                        triggered=self.build_opener(project),
                    )

Or if you want lambda:

lambda path: lambda _: self.open_project(path=path)(path=project)

The main reason of this error -- incorrect work with closures

@kai3341, we have a code test for this, so I don't understand how it's still failing. However, please open a pull request with your suggested changes and if that test pass then I'll merge it.

Sorry for reviving this closed thread, but I would like to understand why it was not working previously with lambda _, p=project: self.open_project(path=p).

p=project creates a new variable p local to the lambda and computed when the lambda is defined so it should work and actually, it does work when I test it locally... so I do not understand.

Any ideas?

Besides, this is the solution that is endorsed by the official FAQ :
https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result

Also:
https://stackoverflow.com/a/2295372/4481445

Good question. It's really funny, but test code works fine, but the same code at SpyderIDE worked incorrectly. So there is open question how does this code used?

The only difference is argument handling. In case of lambda _, p=project: self.open_project(path=p) variable p can be overriden, in case of lambda p: lambda *args, **kwargs: self.open_project(path=p) variable p is in closure and can not be overriden

So, for me it's good challenge to answer what the difference

Thanks for your answer @kai3341. This is indeed very strange because the SpyderIDE code was working as expected for me, as well as for the other developers, and the CI tests were all passing on Travis and Azure.

Anyway, thanks for your help, Ill continue to think about this...

Was this page helpful?
0 / 5 - 0 ratings