Skip to content
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

Bugfix report different behavior based on path #262

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion prospector/blender_combinations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ combinations:
- # No exception type(s) specified
- pylint: bare-except
- frosted: W101
- pep8: E722

- # Spaces around keyword/paramater equals
- pep8: E251
Expand Down Expand Up @@ -203,4 +204,4 @@ combinations:

-
- pep257: D103
- pylint: missing-docstring
- pylint: missing-docstring
13 changes: 5 additions & 8 deletions prospector/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ def __init__(self):

self.paths = self._get_work_path(self.config, self.arguments)
self.explicit_file_mode = all(map(os.path.isfile, self.paths))

if os.path.isdir(self.paths[0]):
self.workdir = self.paths[0]
else:
self.workdir = os.getcwd()
self.workdir = os.getcwd()

self.profile, self.strictness = self._get_profile(self.workdir, self.config)
self.libraries = self._find_used_libraries(self.config, self.profile)
Expand Down Expand Up @@ -61,10 +57,11 @@ def get_output_report(self):
if self.config.output_format is not None:
output_report = self.config.output_format
else:
output_report = [(self.profile.output_format, self.profile.output_target or [])]
output_report = [(self.profile.output_format, self.profile.output_target)]

if not all(output_report):
output_report = [('grouped', [])]
for index, report in enumerate(output_report):
if not all(report):
output_report[index] = (report[0] or 'grouped', report[1] or [])

return output_report

Expand Down
8 changes: 5 additions & 3 deletions prospector/finder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import os

from prospector.pathutils import is_virtualenv


Expand Down Expand Up @@ -187,7 +189,7 @@ def _find_paths(ignore, curpath, rootpath):
return files, modules, packages, directories


def find_python(ignores, paths, explicit_file_mode, workdir=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check here

def find_python(ignores, paths, explicit_file_mode, workdir=''):
"""
Returns a FoundFiles class containing a list of files, packages, directories,
where files are simply all python (.py) files, packages are directories
Expand All @@ -198,5 +200,5 @@ def find_python(ignores, paths, explicit_file_mode, workdir=None):
return SingleFiles(paths, workdir or os.getcwd())
else:
assert len(paths) == 1
files, modules, directories, packages = _find_paths(ignores, paths[0], paths[0])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check here

return FoundFiles(paths[0], files, modules, directories, packages, ignores)
files, modules, directories, packages = _find_paths(ignores, paths[0], workdir)
return FoundFiles(workdir, files, modules, directories, packages, ignores)
2 changes: 1 addition & 1 deletion prospector/postfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def filter_messages(relative_filepaths, root, messages):
# first get rid of the pylint informational messages
relative_message_path = os.path.relpath(message.location.path)

if message.source == 'pylint' and message.code in ('suppressed-message',):
if message.source == 'pylint' and message.code in ('suppressed-message', 'file-ignored',):
continue

# some files are skipped entirely by messages
Expand Down
32 changes: 30 additions & 2 deletions prospector/tools/pep8/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,41 @@ def configure(self, prospector_config, found_files):
external_config = conf_path
break

# create a list of packages, but don't include packages which are
# subpackages of others as checks will be duplicated
packages = [
os.path.split(p)
for p in found_files.iter_package_paths(abspath=False)
]
packages.sort(key=len)
check_paths = set()
for package in packages:
package_path = os.path.join(*package)
if len(package) == 1:
check_paths.add(package_path)
continue
for i in range(1, len(package)):
if os.path.join(*package[:-i]) in check_paths:
break
else:
check_paths.add(package_path)

for filepath in found_files.iter_module_paths(abspath=False):
package = os.path.dirname(filepath).split(os.path.sep)
for i in range(0, len(package)):
if os.path.join(*package[:i + 1]) in check_paths:
break
else:
check_paths.add(filepath)

check_paths = [found_files.to_absolute_path(p) for p in check_paths]

# Instantiate our custom pep8 checker.
self.checker = ProspectorStyleGuide(
paths=list(found_files.iter_package_paths()),
paths=check_paths,
found_files=found_files,
config_file=external_config
)

if not use_config or external_config is None:
configured_by = None
# This means that we don't have existing config to use.
Expand Down
5 changes: 3 additions & 2 deletions tests/finder/test_file_finder.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# -*- coding: utf-8 -*-
import os
from unittest import TestCase

from prospector.finder import find_python
from prospector.pathutils import is_virtualenv


class TestSysPath(TestCase):

def _run_test(self, name, expected):
root = os.path.join(os.path.dirname(__file__), 'testdata', name)
files = find_python([], [root], explicit_file_mode=False)

expected = [os.path.join(root, e).rstrip(os.path.sep) for e in expected]
expected = [os.path.relpath(os.path.join(root, e).rstrip(os.path.sep)) for e in expected]
actual = files.get_minimal_syspath()

expected.sort(key=lambda x: len(x))
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ skip_missing_interpreters = true
deps =
nose
py27: mock
commands = nosetests tests
commands = nosetests tests {posargs}