Spyder: Adding applications to file associations is broken on Windows due to unescaped backslashes

Created on 10 Nov 2019  路  6Comments  路  Source: spyder-ide/spyder

Description

What steps will reproduce the problem?

  1. From a clean config, open the File Associations tab of the Files prefs pane
  2. Add any extension (e.g. .txt) to enable the "add" option for external programs
  3. Click the add button, and the resulting error appears

I haven't investigated the relevant code thoroughly, but it appears to be due to unescaped backslashes in Windows file paths combined with use of eval. I'd suggest simply using standard forward slashes instead (using replace to convert them before parsing if necessary) since they are equally accepted on Windows as backslashes.

Also, even after I dismiss the error, my cursor remains stuck in the "hourglass" mode that was triggered with the failed launch of the file open dialog.

Traceback

  File "C:\Miniconda3\envs\spyder-4\lib\site-packages\spyder\plugins\explorer\widgets\fileassociations.py", line 496, in add_application
    self._dlg_applications = ApplicationsDialog(self)
  File "C:\Miniconda3\envs\spyder-4\lib\site-packages\spyder\plugins\explorer\widgets\fileassociations.py", line 145, in __init__
    self.setup()
  File "C:\Miniconda3\envs\spyder-4\lib\site-packages\spyder\plugins\explorer\widgets\fileassociations.py", line 152, in setup
    apps = get_installed_applications()
  File "C:\Miniconda3\envs\spyder-4\lib\site-packages\spyder\utils\programs.py", line 493, in get_installed_applications
    apps = _get_win_applications()
  File "C:\Miniconda3\envs\spyder-4\lib\site-packages\spyder\utils\programs.py", line 362, in _get_win_applications
    expanded_fpath = literal_eval(expanded_fpath)
  File "C:\Miniconda3\envs\spyder-4\lib\ast.py", line 46, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "C:\Miniconda3\envs\spyder-4\lib\ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    c:\program files (x86)\malwarebytes' anti-malware\mbam.exe
     ^
SyntaxError: invalid syntax

Versions

  • Spyder version: 4.0.0rc1
  • Python version: 3.7.5
  • Qt version: 5.9.6
  • PyQt5 version: 5.9.2
  • Operating System: Windows 8.1

Dependencies

cloudpickle >=0.5.0          :  0.7.0 (OK)
pygments >=2.0               :  2.3.1 (OK)
qtconsole >=4.5.5            :  4.5.5 (OK)
nbconvert >=4.0              :  5.4.0 (OK)
sphinx >=0.6.6               :  1.8.4 (OK)
pylint >=0.25                :  2.2.2 (OK)
psutil >=0.3                 :  5.6.3 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  17.1.2 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.8.0 (OK)
spyder_kernels >=1.7.0;<2.0.0:  1.7.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.3 (OK)
cython >=0.21                :  0.29.4 (OK)
IPython >=4.0                :  7.2.0 (OK)
matplotlib >=2.0.0           :  3.0.2 (OK)
pandas >=0.13.1              :  0.24.2 (OK)
numpy >=1.7                  :  1.15.4 (OK)
scipy >=0.17.0               :  1.2.0 (OK)
pyls >=0.29.3;<0.30.0        :  0.29.3 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
File Explorer Bug

All 6 comments

Also, not sure what's up with the dependency report but conda list confirms I have all three of watchdog, keyring and pympler installed in my Spyder 4 env and Spyder even used keyring to remember my Github token to submit this report.

@goanpeca, please take a look at this one.

Also, not sure what's up with the dependency report but conda list confirms I have all three of watchdog, keyring and pympler installed in my Spyder 4 env and Spyder even used keyring to remember my Github token to submit this report.

Please read carefully: they don't have available versions to report (because the packages themselves don't declare them), but they are marked as OK.

@ccordoba12 I see, but it isn't clear simply from the context that the None was referring to the version as opposed to the installation status, and OK to the installation status as opposed to whether lack of that package was a critical problem (e.g. if it was optional).

By the way, even if the package doesn't declare __version__ or similar, its easy to get the version using Setuptools' pkg_resources, since all those packages still have one. Here's a snippit adapted directly from my own production code:

import pip._vendor.pkg_resources as pkg_resources  # Or just `import pkg_resources` if you know you'll have setuptools available, like with conda, linux distros, etc
for package in pkg_resources.working_set:
    if package.project_name.lower() == "PACKAGENAME":
        package_version = package.version
        break

EDIT: Oops, accidentally hit close. Sorry!

If you found a fix, please submit a pull request for that, along with tests. If not, we'll try to fix that when more important things are solved.

@ccordoba12 Sure, I'll add it to my list. As you say its not at all critical and it should be a quick fix and test for me to do so I'll try to get to it perhaps after the Spyder 4.0 release. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LDONT picture LDONT  路  3Comments

hedeqing picture hedeqing  路  3Comments

gabrielclow picture gabrielclow  路  3Comments

goanpeca picture goanpeca  路  3Comments

marianux picture marianux  路  3Comments