-
-
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/Find in files #3295
Merged
Merged
PR: Fix/Find in files #3295
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1c5c804
Improve extensions parsing from pygments lexer
goanpeca 6cddebb
Improve include patterns generation
goanpeca 4b54a4e
Add test to validate include and exclude patterns as valid regex
goanpeca 1835c59
Remove duplicates and sort extension list
goanpeca 797ea28
Remove uneeded space
goanpeca ed4d124
/Hide advanced options by default
goanpeca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,21 @@ | |
# pylint: disable=R0911 | ||
# pylint: disable=R0201 | ||
|
||
# Standard library imports | ||
import sys | ||
|
||
# Third party imports | ||
from qtpy.QtWidgets import QApplication | ||
from qtpy.QtCore import Signal, Slot | ||
|
||
# Local imports | ||
from spyderlib.config.base import _ | ||
from spyderlib.config.utils import get_edit_extensions | ||
from spyderlib.plugins import SpyderPluginMixin | ||
from spyderlib.py3compat import getcwd | ||
from spyderlib.utils import icon_manager as ima | ||
from spyderlib.utils.qthelpers import create_action | ||
from spyderlib.widgets.findinfiles import FindInFilesWidget | ||
from spyderlib.plugins import SpyderPluginMixin | ||
|
||
|
||
class FindInFiles(FindInFilesWidget, SpyderPluginMixin): | ||
|
@@ -94,14 +97,23 @@ def findinfiles_callback(self): | |
if text: | ||
self.find() | ||
|
||
def include_patterns(self): | ||
edit_ext = get_edit_extensions() | ||
patterns = [r'|'.join(['\\'+_ext+r'$' for _ext in edit_ext if _ext])+\ | ||
@staticmethod | ||
def include_patterns(): | ||
"""Generate regex common usage patterns to include section.""" | ||
# Change special characters, like + and . to convert into valid re | ||
clean_exts = [] | ||
for ext in get_edit_extensions(): | ||
ext = ext.replace('.', r'\.') | ||
ext = ext.replace('+', r'\+') | ||
clean_exts.append(ext) | ||
|
||
patterns = [r'|'.join([ext + r'$' for ext in clean_exts if ext]) + | ||
r'|README|INSTALL', | ||
r'\.pyw?$|\.ipy$|\.txt$|\.rst$', | ||
'.'] | ||
r'\.ipy$|\.pyw?$|\.rst$|\.txt$', | ||
'.', | ||
] | ||
return patterns | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this blank :-) |
||
#------ SpyderPluginMixin API --------------------------------------------- | ||
def switch_to_plugin(self): | ||
"""Switch to plugin | ||
|
@@ -171,3 +183,15 @@ def closing_plugin(self, cancelable=False): | |
self.set_option('in_python_path', in_python_path) | ||
self.set_option('more_options', more_options) | ||
return True | ||
|
||
|
||
def test(): | ||
from spyderlib.utils.qthelpers import qapplication | ||
app = qapplication() | ||
widget = FindInFiles() | ||
widget.show() | ||
sys.exit(app.exec_()) | ||
|
||
|
||
if __name__ == '__main__': | ||
test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
# ----------------------------------------------------------------------------- | ||
# Copyright © 2009- The Spyder Development Team | ||
# | ||
# Licensed under the terms of the MIT License | ||
# (see spyderlib/__init__.py for details) | ||
# ----------------------------------------------------------------------------- | ||
"""Test scripts for `findinfiles` plugin.""" | ||
|
||
# Standard library imports | ||
import re | ||
|
||
# Local imports | ||
from spyderlib.config.main import EXCLUDE_PATTERNS | ||
|
||
|
||
class TestFindInFilesPlugin: | ||
|
||
def check_regex(self, patterns): | ||
""" | ||
Check that regular expression patterns provided by compiling them. | ||
Return a list of booleans for each of the provided patterns. | ||
""" | ||
checks = [] | ||
for pattern in patterns: | ||
try: | ||
re.compile(pattern) | ||
is_valid = True | ||
except re.error: | ||
is_valid = False | ||
checks.append(is_valid) | ||
return checks | ||
|
||
def test_include_patterns_are_valid_regex(self, qtbot): | ||
# qtawesome requires a QApplication to exist, so widgets import must | ||
# happen inside the test (or with fixtures) | ||
from spyderlib.plugins.findinfiles import FindInFiles | ||
patterns = FindInFiles.include_patterns() | ||
checks = self.check_regex(patterns) | ||
assert all(checks) | ||
|
||
def test_exclude_patterns_are_valid_regex(self): | ||
checks = self.check_regex(EXCLUDE_PATTERNS) | ||
assert all(checks) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What do these changes do exactly?
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.
lexer_exts = [le[1:] for le in lexer_exts]
This code is wrong cause not all lexers extensions start with a
*
, so I fixed that so the actual generated patterns are valid regex. (this was causing find in files to not work after a clean install)