Skip to content

Commit

Permalink
Merge pull request #4056 from andfoy/find_in_files_bar
Browse files Browse the repository at this point in the history
PR: Several Find in Files improvements
  • Loading branch information
ccordoba12 authored May 14, 2017
2 parents 426184f + 4cd0f9b commit a22b4ff
Show file tree
Hide file tree
Showing 14 changed files with 679 additions and 502 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ environment:

matrix:
- PYTHON_VERSION: "2.7"
- PYTHON_VERSION: "3.6"
#- PYTHON_VERSION: "3.6"

platform:
-x64
Expand Down
4 changes: 2 additions & 2 deletions continuous_integration/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ if [ "$CIRCLE_NODE_INDEX" = "3" ]; then
export CONDA_DEPENDENCIES=""
else
export CONDA_DEPENDENCIES_FLAGS="--quiet"
export CONDA_DEPENDENCIES="rope pyflakes sphinx pygments pylint pycodestyle psutil nbconvert \
export CONDA_DEPENDENCIES="rope pyflakes sphinx pygments pylint psutil nbconvert \
qtawesome pickleshare qtpy pyzmq chardet mock nomkl pandas \
pytest pytest-cov numpydoc scipy cython pillow"
export PIP_DEPENDENCIES="coveralls pytest-qt pytest-xvfb flaky jedi"
export PIP_DEPENDENCIES="coveralls pytest-qt pytest-xvfb flaky jedi pycodestyle"
fi


Expand Down
11 changes: 6 additions & 5 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,6 @@ def create_edit_action(text, tr_text, icon):
self.set_splash("")

self.debug_print(" ..widgets")
# Find in files
if CONF.get('find_in_files', 'enable'):
from spyder.plugins.findinfiles import FindInFiles
self.findinfiles = FindInFiles(self)
self.findinfiles.register_plugin()

# Explorer
if CONF.get('explorer', 'enable'):
Expand Down Expand Up @@ -855,6 +850,12 @@ def create_edit_action(text, tr_text, icon):
self.projects.register_plugin()
self.project_path = self.projects.get_pythonpath(at_start=True)

# Find in files
if CONF.get('find_in_files', 'enable'):
from spyder.plugins.findinfiles import FindInFiles
self.findinfiles = FindInFiles(self)
self.findinfiles.register_plugin()

# External console
self.set_splash(_("Loading external console..."))
from spyder.plugins.externalconsole import ExternalConsole
Expand Down
7 changes: 2 additions & 5 deletions spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
# Main constants
#==============================================================================
# Find in files exclude patterns
EXCLUDE_PATTERNS = [r'\.pyc$|\.pyo$|\.orig$|\.hg|\.svn|\bbuild\b',
r'\.pyc$|\.pyo$|\.orig$|\.hg|\.svn']
EXCLUDE_PATTERNS = [r'\.pyc$|\.pyo$|\.git']

# Extensions that should be visible in Spyder's file/project explorers
SHOW_EXT = ['.py', '.ipynb', '.txt', '.dat', '.pdf', '.png', '.svg']
Expand Down Expand Up @@ -291,8 +290,6 @@
{
'enable': True,
'supported_encodings': ["utf-8", "iso-8859-1", "cp1252"],
'include': '',
'include_regexp': True,
'exclude': EXCLUDE_PATTERNS,
'exclude_regexp': True,
'search_text_regexp': True,
Expand Down Expand Up @@ -660,7 +657,7 @@
# or if you want to *rename* options, then you need to do a MAJOR update in
# version, e.g. from 3.0.0 to 4.0.0
# 3. You don't need to touch this value if you're just adding a new option
CONF_VERSION = '33.2.0'
CONF_VERSION = '34.0.0'

# Main configuration instance
try:
Expand Down
6 changes: 4 additions & 2 deletions spyder/plugins/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ class Editor(SpyderPluginWidget):
open_dir = Signal(str)
breakpoints_saved = Signal()
run_in_current_extconsole = Signal(str, str, str, bool, bool)

open_file_update = Signal(str)

def __init__(self, parent, ignore_last_opened_files=False):
if PYQT5:
SpyderPluginWidget.__init__(self, parent, main=parent)
Expand Down Expand Up @@ -1596,7 +1597,8 @@ def opened_files_list_changed(self):
action.setEnabled(enable and WINPDB_PATH is not None)
else:
action.setEnabled(enable)

self.open_file_update.emit(self.get_current_filename())

def update_code_analysis_actions(self):
editorstack = self.get_current_editorstack()
results = editorstack.get_analysis_results()
Expand Down
45 changes: 16 additions & 29 deletions spyder/plugins/findinfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,13 @@ def __init__(self, parent=None):
search_text += self.search_text_samples

search_text_regexp = self.get_option('search_text_regexp')
include = self.get_option('include')
if not include:
include = self.include_patterns()
include_idx = self.get_option('include_idx', None)
include_regexp = self.get_option('include_regexp')
exclude = self.get_option('exclude')
exclude_idx = self.get_option('exclude_idx', None)
exclude_regexp = self.get_option('exclude_regexp')
in_python_path = self.get_option('in_python_path')
more_options = self.get_option('more_options')
FindInFilesWidget.__init__(self, parent,
search_text, search_text_regexp, search_path,
include, include_idx, include_regexp,
exclude, exclude_idx, exclude_regexp,
supported_encodings,
in_python_path, more_options)
Expand All @@ -79,6 +73,18 @@ def refreshdir(self):
"""Refresh search directory"""
self.find_options.set_directory(getcwd())

def set_project_path(self, path):
"""Refresh current project path"""
self.find_options.set_project_path(path)

def set_current_opened_file(self, path):
"""Get path of current opened file in editor"""
self.find_options.set_file_path(path)

def unset_project_path(self):
"""Refresh current project path"""
self.find_options.disable_project_search()

@Slot()
def findinfiles_callback(self):
"""Find in files callback"""
Expand All @@ -97,23 +103,6 @@ def findinfiles_callback(self):
if text:
self.find()

@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'\.ipy$|\.pyw?$|\.rst$|\.txt$',
'.',
]
return patterns

#------ SpyderPluginMixin API ---------------------------------------------
def switch_to_plugin(self):
"""Switch to plugin
Expand Down Expand Up @@ -144,7 +133,10 @@ def register_plugin(self):
self.edit_goto.connect(self.main.editor.load)
self.redirect_stdio.connect(self.main.redirect_internalshell_stdio)
self.main.workingdirectory.refresh_findinfiles.connect(self.refreshdir)

self.main.projects.sig_project_loaded.connect(self.set_project_path)
self.main.projects.sig_project_closed.connect(self.unset_project_path)
self.main.editor.open_file_update.connect(self.set_current_opened_file)

findinfiles_action = create_action(self, _("&Find in files"),
icon=ima.icon('findf'),
triggered=self.findinfiles_callback,
Expand All @@ -165,20 +157,15 @@ def closing_plugin(self, cancelable=False):
options = self.find_options.get_options(all=True)
if options is not None:
search_text, text_re, search_path, \
include, include_idx, include_re, \
exclude, exclude_idx, exclude_re, \
in_python_path, more_options = options
hist_limit = 15
search_text = search_text[:hist_limit]
search_path = search_path[:hist_limit]
include = include[:hist_limit]
exclude = exclude[:hist_limit]
self.set_option('search_text', search_text)
self.set_option('search_text_regexp', text_re)
self.set_option('search_path', search_path)
self.set_option('include', include)
self.set_option('include_idx', include_idx)
self.set_option('include_regexp', include_re)
self.set_option('exclude', exclude)
self.set_option('exclude_idx', exclude_idx)
self.set_option('exclude_regexp', exclude_re)
Expand Down
54 changes: 26 additions & 28 deletions spyder/plugins/tests/test_findinfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,33 @@
# Standard library imports
import re

# 3rd party imports
import pytest

# Local imports
from spyder.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 spyder.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)
def check_regex(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_exclude_patterns_are_valid_regex():
checks = check_regex(EXCLUDE_PATTERNS)
assert all(checks)


if __name__ == "__main__":
pytest.main()
2 changes: 1 addition & 1 deletion spyder/utils/external/binaryornot/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def is_binary(filename):
logger.debug('is_binary: %(filename)r', locals())

# Check if the file extension is in a list of known binary types
binary_extensions = ['pyc']
binary_extensions = ['pyc', 'iso']
for ext in binary_extensions:
if filename.endswith(ext):
return True
Expand Down
Loading

0 comments on commit a22b4ff

Please sign in to comment.