-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Fix 3 bugs and add 4 improvements to Find in Files #6095
PR: Fix 3 bugs and add 4 improvements to Find in Files #6095
Conversation
- All the code related to the management of the search path for the FindInFiles widget was isolated in a new class. - The inheritance to the BaseComboBox was dropped since it was causing problems. - Dropped the custom model that was used for the combobox. Everything is managed with the default model of the QComboBox class. This fixed another issue with the previous implementation of the combo-box.
When the combobox popup list is visible and the delete key is pressed, the highlighted external path is removed from the list.
Jean, could you also fix codecov to show failures only when coverage decreases in 1%? Thanks! |
Hello @jnsebgosselin! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on January 09, 2018 at 05:20 Hours UTC |
@ccordoba12 While working on the tests for the FindInFiles plugin, I found out an additional bug. The get_options method of the FindOptions widget is used for two things:
The problem is that there is safeguards within the For example, the options won't be saved to the config file if the
I think this should be fixed in another PR. I will built my tests around this issue for the moment. |
@ccordoba12 I think this is ready to be reviewed. I'll go over it again tomorrow just to be sure. There is a lot of stuff to review in this, so feel free to push it back to 3.2.7 if you do not have the time for 3.2.6. I'll try to document a little better the changes I've made later in the description of this PR. Also, I'm not sure I understand well the use of More than 350 lines of tests added for a meager 0.3% increase in coverage... damn :D |
spyder/widgets/findinfiles.py
Outdated
from qtpy.QtCore import QMutex, QMutexLocker, Qt, QThread, Signal, Slot, QSize | ||
from qtpy.QtWidgets import (QHBoxLayout, QLabel, QListWidget, QSizePolicy, | ||
from qtpy.QtCore import (QMutex, QMutexLocker, Qt, QThread, Signal, Slot, | ||
QSize, QEvent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please organize these imports in alphabetical order
spyder/widgets/findinfiles.py
Outdated
QTreeWidgetItem, QVBoxLayout, QWidget, | ||
QStyledItemDelegate, QStyleOptionViewItem, | ||
QApplication, QStyle, QListWidgetItem) | ||
QApplication, QStyle, QMessageBox) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These imports too
spyder/widgets/findinfiles.py
Outdated
current position and added back at the end. If the maximum number of | ||
paths is reached, the oldest external path is removed from the list. | ||
""" | ||
if not os.path.exists(path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change os.path
to osp
(that's our custom in Spyder).
spyder/widgets/findinfiles.py
Outdated
return | ||
self.removeItem(self.findText(path)) | ||
self.addItem(path) | ||
self.setItemData(self.count()-1, path, Qt.ToolTipRole) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces around -
spyder/widgets/findinfiles.py
Outdated
self.removeItem(self.findText(path)) | ||
self.addItem(path) | ||
self.setItemData(self.count()-1, path, Qt.ToolTipRole) | ||
while self.count() > MAX_PATH_HISTORY+EXTERNAL_PATHS: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces around +
|
||
def get_external_paths(self): | ||
"""Returns a list of the external paths listed in the combobox.""" | ||
return [to_text_string(self.itemText(i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to use here to_unicode_from_fs
(from utils/encoding.py
) to deal with non-ascii dirs on Windows that uses encodings like cp-1251 (Russian).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this is not the proper place to do it. I'll point to the right place below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I replace to_text_string(self.itemText(i)
by self.itemText(i)
?
I do not understand what to_text_string
is doing here since self.itemText(i)
is already returning a unicode str by default as stated, for instance, in the PySide documentation). Or is it returning a QString
in some version of PyQt on python 2? In PySide, the QString
class does not even exist I think.
All this encoding stuff is mumbo jumbo to me, no matter how many times I've read on this subject XD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've seen that to_text_string
was always used with itemText
everywhere else. So maybe it is safer to keep it that way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've read that Python 2, PyQt API #1 is returning a QString
, so I'll keep the to_text_string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good idea.
spyder/widgets/findinfiles.py
Outdated
external_path = self.select_directory() | ||
if len(external_path) > 0: | ||
self.add_external_path(external_path) | ||
self.setCurrentIndex(self.count()-1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces around -
spyder/widgets/findinfiles.py
Outdated
directory = getexistingdirectory( | ||
self, _("Select directory"), self.path) | ||
if directory: | ||
directory = to_text_string(osp.abspath(to_text_string(directory))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the right place to use to_unicode_from_fs
. So this should be
directory = encoding.to_unicode_from_fs(osp.abspath(directory))
spyder/widgets/findinfiles.py
Outdated
if self.currentIndex() == PROJECT: | ||
self.setCurrentIndex(CWD) | ||
else: | ||
path = to_text_string(osp.abspath(to_text_string(path))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to
path = encoding.to_unicode_from_fs(osp.abspath(path))
Could you add some tests to verity that this is correct in Python 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmh, it seems we're not transforming to Unicode our project paths, so maybe this is for another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened issue #6103 about this (which I'll fix for 3.2.6), so please change this line to
path = osp.abspath(path)
spyder/widgets/findinfiles.py
Outdated
self.removeItem(index) | ||
self.showPopup() | ||
# Set the view selection so that it doesn't bounce around. | ||
new_index = min(self.count()-1, index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces around -
I like a lot the new I left some minor comments, except for the use of |
Thank you very much Carlos for this quick review, this is very nice! To do:
|
spyder/widgets/findinfiles.py
Outdated
self.clear_external_paths() | ||
self.setCurrentIndex(0) | ||
elif idx >= EXTERNAL_PATHS: | ||
self.external_path = to_text_string(self.itemText(idx)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here, should I replace to_text_string(self.itemText(idx))
by self.itemText(idx)
.
spyder/widgets/findinfiles.py
Outdated
|
||
def set_directory(self, directory): | ||
self.path = to_text_string(osp.abspath(to_text_string(directory))) | ||
self.path_selection_combo.path = to_text_string(osp.abspath( | ||
to_text_string(directory))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should to_text_string(osp.abspath(to_text_string(directory)))
be changed to osp.abspath(directory)
or to_unicode_from_fs(osp.abspath(directory))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this is only used in one place:
So this should be osp.abspath(directory)
because getcwd_or_home
already returns unicode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thank you. I'll remove the to_text_string
here.
|
||
def set_file_path(self, path): | ||
self.file_path = path | ||
self.path_selection_combo.file_path = path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should path
be changed for osp.abspath(path)
or to_unicode_from_fs(osp.abspath(path))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this is only used in one place
and, since it sets the path of current file in the Editor, I think it's fine as it is, or you can change it to osp.abspath(path)
if you want to be certain to have a full path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll leave it like that. If it ain't broke, don't fix it.
I added a non-ASCII path to the tests... and all hell breaks loose lol The test is passing for Python3 in AppVeyor, but not for Python 2. I don't understand why the tests are failing on Travis though, I'm not sure it is related to this PR... |
The "good news" is that I'm able to make the test crash locally with Python2, so I should be able to debug this... but probably not until next year XD |
This reverts commit 2ce5810.
…find_in_files_fixes
@ccordoba12 Just so you know, this is ready, but I would like you to check again carefully some of the places where we return a So good thinking in pushing it back to 3.2.7. It wouldn't be a bad idea if you could play a little bit with the changes I've made locally also. |
I left my comments above.
Yep, I agree too. If things go as planned, we'll release 3.2.7 by the end of January. |
The directory is already unicode. So there is no need to use to_text_string here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot Jean, this is a really great improvement!
Fixes #5306 Conflicts: - spyder/widgets/findinfiles.py - spyder/widgets/tests/test_findinfiles.py
Fixes #5306
Fix issue reported in Paths in the "Search in" combobox of the "Find in File" plugin becomes corrupted #5306 (comment)
Fix issue reported in Paths in the "Search in" combobox of the "Find in File" plugin becomes corrupted #5306 (comment)
Fix issue reported in Paths in the "Search in" combobox of the "Find in File" plugin becomes corrupted #5306 (comment)
When populating the
Search in
QComboBox, do not add the paths that do not exists on the file system.When hovering over an item of the QComboBox and pressing Del, remove the item from the list.
Add a
Clear this list
option belowSelect other directory
.Show the full path when hovering over an item in the
Search in
QComboBox.Expand the tests for the FindInFiles Widget.
Expand the tests for the FindInFiles Plugin.