Skip to content

Commit

Permalink
Merge pull request #7816 from ehabkost/find-files-empty-exclude
Browse files Browse the repository at this point in the history
PR: Don't ignore all files when exclude pattern is empty
  • Loading branch information
ccordoba12 authored Sep 3, 2018
2 parents f384555 + a10a893 commit 41f3cf3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
23 changes: 14 additions & 9 deletions spyder/widgets/findinfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def initialize(self, path, is_file, exclude,
self.rootpath = path
self.python_path = False
self.hg_manifest = False
self.exclude = re.compile(exclude)
if exclude:
self.exclude = re.compile(exclude)
self.texts = texts
self.text_re = text_re
self.is_file = is_file
Expand Down Expand Up @@ -143,14 +144,15 @@ def find_files_in_path(self, path):
if self.stopped:
return False
dirname = os.path.join(path, d)
if re.search(self.exclude, dirname + os.sep):
if self.exclude \
and re.search(self.exclude, dirname + os.sep):
dirs.remove(d)
for f in files:
with QMutexLocker(self.mutex):
if self.stopped:
return False
filename = os.path.join(path, f)
if re.search(self.exclude, filename):
if self.exclude and re.search(self.exclude, filename):
continue
if is_text_file(filename):
self.find_string_in_file(filename)
Expand Down Expand Up @@ -557,13 +559,16 @@ def get_options(self, all=False):
file_search = self.path_selection_combo.is_file_search()
path = self.path_selection_combo.get_current_searchpath()

# Finding text occurrences
if not exclude_re:
items = [fnmatch.translate(item.strip())
for item in exclude.split(",")
if item.strip() != '']
exclude = '|'.join(items)

# Validate regular expressions:

try:
if not exclude_re:
items = [fnmatch.translate(item.strip())
for item in exclude.split(",")]
exclude = '|'.join(items)
else:
if exclude:
exclude = re.compile(exclude)
except Exception:
exclude_edit = self.exclude_pattern.lineEdit()
Expand Down
23 changes: 23 additions & 0 deletions spyder/widgets/tests/test_findinfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,29 @@ def test_exclude_extension_string(qtbot):
assert files_filtered


def test_exclude_extension_empty_regex(qtbot):
find_in_files = setup_findinfiles(qtbot, exclude="")
find_in_files.set_search_text("spam")
find_in_files.find_options.set_directory(osp.join(LOCATION, "data"))
find_in_files.find()
blocker = qtbot.waitSignal(find_in_files.sig_finished)
blocker.wait()
matches = process_search_results(find_in_files.result_browser.data)
assert expected_results() == matches


def test_exclude_extension_string(qtbot):
find_in_files = setup_findinfiles(qtbot, exclude="",
exclude_regexp=False)
find_in_files.set_search_text("spam")
find_in_files.find_options.set_directory(osp.join(LOCATION, "data"))
find_in_files.find()
blocker = qtbot.waitSignal(find_in_files.sig_finished)
blocker.wait()
matches = process_search_results(find_in_files.result_browser.data)
assert expected_results() == matches


def test_exclude_extension_multiple_string(qtbot):
find_in_files = setup_findinfiles(qtbot, exclude="*.py, *.cpp",
exclude_regexp=False)
Expand Down

0 comments on commit 41f3cf3

Please sign in to comment.