Spyder: Paths in the "Search in" combobox of the "Find in File" plugin becomes corrupted

Created on 21 Sep 2017  路  15Comments  路  Source: spyder-ide/spyder

Description of your problem

Related to PR #4822 that fixed Issues #4814 and #4809.

What steps will reproduce the problem?

  1. I don't know... I'm sorry. I'll add more info in the future if I can. I'm using this feature a lot, so I'll keep my eyes opened!

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

Sometimes, _Other directories_ in the _Search in_ combobox of the _Find in File_ plugin becomes corrupted with no way of removing them. For instance, the <PyQt5.QtWidgets.QListWidget... shown in the screenshot below was actually C:\Users\jsgosselin\spyder before it became corrupted at some point. This is the third time that this problem occurs for me.

Besides, I think an option should be added below _Select other directory_ to clear the list.

image

Please provide any additional information below

Versions and main components

  • Spyder Version: branch 3.x and master
  • Python Version: 3.6.2
  • Qt Version: 5.9.1
  • PyQt Version: 5.9
  • Operating system: Windows 7 64 bits

Dependencies

IPython >=4.0 : 6.1.0 (OK)
cython >=0.21 : 0.25.2 (OK)
jedi >=0.9.0 : 0.10.2 (OK)
nbconvert >=4.0 : 5.2.1 (OK)
numpy >=1.7 : 1.13.0 (OK)
pandas >=0.13.1 : 0.20.3 (OK)
pycodestyle >=2.3: 2.3.1 (OK)
pyflakes >=0.6.0 : 1.5.0 (OK)
pygments >=2.0 : 2.2.0 (OK)
pylint >=0.25 : 1.7.1 (OK)
qtconsole >=4.2.0: 4.4.0.dev (OK)
rope >=0.9.4 : 0.10.7 (OK)
sphinx >=0.6.6 : 1.6.2 (OK)
sympy >=0.7.3 : None (NOK)

Find in files Bug

All 15 comments

Here is a traceback:

Traceback (most recent call last):
  File "C:\Users\jsgosselin\spyder\spyder\widgets\findinfiles.py", line 114, in run
    self.find_files_in_path(self.rootpath)
  File "C:\Users\jsgosselin\spyder\spyder\widgets\findinfiles.py", line 132, in find_files_in_path
    for path, dirs, files in os.walk(path):
  File "C:\Python36\lib\os.py", line 335, in walk
    top = fspath(top)
TypeError: expected str, bytes or os.PathLike object, not NoneType

@andfoy, please take a look at this one.

@andfoy Would you mind if I take a look at this? I would like to fix this bug for the next release.

Jean, please go ahead and fix it :+1:

@ccordoba12 In addition to solve this issue, I had some ideas to improve how the Search in QComboBox works. What do you think?

  • [x] When populating the Search in QComboBox, do not add the paths that do not exists anymore.
  • [x] When hovering over an item of the QComboBox and pressing Del, remove the item from the list.
  • [x] Add a Clear this list option below Select other directory.
  • [x] Show the full path when hovering over an item in the Search in QComboBox.
  File "C:\Users\jsgosselin\spyder\spyder\widgets\findinfiles.py", line 408, in path_selection_changed
    self.external_path = item.path
AttributeError: 'QListWidgetItem' object has no attribute 'path'

Jean, I agree with all your suggestions.

The traceback posted in https://github.com/spyder-ide/spyder/issues/5306#issuecomment-334021119 does not seem to be related to the undesired behavior described in the OP.

Traceback (most recent call last):
  File "C:\Users\jsgosselin\spyder\spyder\widgets\findinfiles.py", line 115, in run
    self.find_files_in_path(self.rootpath)
  File "C:\Users\jsgosselin\spyder\spyder\widgets\findinfiles.py", line 133, in find_files_in_path
    for path, dirs, files in os.walk(path):
  File "C:\Python36\lib\os.py", line 335, in walk
    top = fspath(top)
TypeError: expected str, bytes or os.PathLike object, not NoneType

To reproduce this error:

  • Open a project in Spyder.
  • Go in the Find in Files plugin and from the Search in combobox, select the Project option.
  • Close the project.
  • Start the search.

fif_error1

The traceback posted in https://github.com/spyder-ide/spyder/issues/5306#issuecomment-353457679. does not seem to be related to the undesired behavior described in the OP. So far unfortunately, I have not been successful to produce a reproducible example of the issue described in the OP.

Traceback (most recent call last):
  File "C:\Users\jsgosselin\spyder\spyder\widgets\findinfiles.py", line 408, in path_selection_changed
    item = self.path_selection_contents.item(idx)
AttributeError: 'QListWidgetItem' object has no attribute 'path'

To reproduce this error:

  • Select a path in the Search in combobox.
  • Change the selection by rolling up the mouse wheel until the separator below the Select other directory is hit.

fif_error2

Ok, I found out how to reproduce the behaviour described in the OP 馃槀. This is happening when Enter is pressed when the focus is on the Search in combo-box and when an external path is selected.

The currently selected path is then moved at the beginning of the list, and an empty item is also added. This behaviour is explained by the keyPressEvent override in the BaseComboBox, from which the Search in combo-box is inheriting

Because of this, the wrong information is saved in the configuration file when the FindinFiles plugin is closed afterward. In the get_options method, the external paths are retrieved from index 6 of the Search in combo-box (see here). Due to what was explained above, the content that is supposed to be in index 1 to 5 is pushed down in the list. So running to_text_string on items that are not an instance of ExternalPathItem, such as a separator, returns a string of the object such as <PyQt5.QtWidgets.QListWidget...

fif_error3

Great! So PR coming?

@ccordoba12 Do I fix the 3 issues I've found while investigating this (see https://github.com/spyder-ide/spyder/issues/5306#issuecomment-354492631, https://github.com/spyder-ide/spyder/issues/5306#issuecomment-354493874, and https://github.com/spyder-ide/spyder/issues/5306#issuecomment-354506402) and do I implement the 4 proposed enhancements (see https://github.com/spyder-ide/spyder/issues/5306#issuecomment-352950794) in the same PR or do I split this in smaller, individual PR?

Everything in one PR seems easier to me because all fixes/improvements are related.

@ccordoba12 Alright thank you. The PR is on the way :)

Ok, moving this one to 3.2.6 then :-)

Was this page helpful?
0 / 5 - 0 ratings