Skip to content

Commit

Permalink
Globs: Change Glob-not-found warning
Browse files Browse the repository at this point in the history
The new message suggests users to remove unmatched files from the
respective section of their .coafile. This feedback is more explicit
and  can help to avoid user confusion.

Closes coala#4146
  • Loading branch information
mrtes committed May 8, 2017
1 parent 2cf2416 commit b1a0cdc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
14 changes: 9 additions & 5 deletions coalib/collecting/Collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ def icollect(file_paths, ignored_globs=None, match_cache={}):


def collect_files(file_paths, log_printer, ignored_file_paths=None,
limit_file_paths=None):
limit_file_paths=None, section_name=''):
"""
Evaluate globs in file paths and return all matching files
:param file_paths: File path or list of such that can include globs
:param ignored_file_paths: List of globs that match to-be-ignored files
:param limit_file_paths: List of globs that the files are limited to
:param section_name: Name of currently executing section
:return: List of paths of all matching files
"""
limit_fnmatch = (functools.partial(fnmatch, globs=limit_file_paths)
Expand All @@ -82,7 +83,10 @@ def collect_files(file_paths, log_printer, ignored_file_paths=None,
collected_files, file_globs_with_files = [], []

_warn_if_unused_glob(log_printer, file_paths, file_globs_with_files,
"No files matching '{}' were found.")
'No files matching \'{}\' were found. '
'If this rule is not required, you can remove it '
'from section [' + section_name + '] in your '
'.coafile to deactivate this warning.')
limited_files = list(filter(limit_fnmatch, collected_files))
return limited_files

Expand Down Expand Up @@ -174,9 +178,9 @@ def collect_bears(bear_dirs, bear_globs, kinds, log_printer,

if warn_if_unused_glob:
_warn_if_unused_glob(log_printer, bear_globs, bear_globs_with_bears,
"No bears matching '{}' were found. Make sure you "
'have coala-bears installed or you have typed the '
'name correctly.')
'No bears matching \'{}\' were found. Make sure '
'you have coala-bears installed or you have typed '
'the name correctly.')
return bears_found


Expand Down
3 changes: 2 additions & 1 deletion coalib/processes/Processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ def instantiate_processes(section,
glob_list(section.get('files', '')),
log_printer,
ignored_file_paths=glob_list(section.get('ignore', '')),
limit_file_paths=glob_list(section.get('limit_files', '')))
limit_file_paths=glob_list(section.get('limit_files', '')),
section_name=section.name)

# This stores all matched files irrespective of whether coala is run
# only on changed files or not. Global bears require all the files
Expand Down
15 changes: 11 additions & 4 deletions tests/collecting/CollectorsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ def test_file_empty(self):
self.assertRaises(TypeError, collect_files)

def test_file_invalid(self):
self.assertEqual(collect_files(['invalid_path'],
self.log_printer), [])
self.assertEqual(collect_files(file_paths=['invalid_path'],
log_printer=self.log_printer,
ignored_file_paths=None,
limit_file_paths=None,
section_name='section'), [])
self.assertEqual([log.message for log in self.log_printer.logs],
["No files matching 'invalid_path' were found."])
['No files matching \'invalid_path\' were found. '
'If this rule is not required, you can remove it '
'from section [section] in your .coafile to '
'deactivate this warning.'
])

def test_file_collection(self):
self.assertEqual(collect_files([os.path.join(self.collectors_test_dir,
Expand Down Expand Up @@ -212,7 +219,7 @@ def test_bear_invalid(self):
['invalid kind'],
self.log_printer), ([],))
self.assertEqual([log.message for log in self.log_printer.logs],
["No bears matching 'invalid_name' were found. Make "
['No bears matching \'invalid_name\' were found. Make '
'sure you have coala-bears installed or you have '
'typed the name correctly.'])

Expand Down

0 comments on commit b1a0cdc

Please sign in to comment.