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

Fix pylint parallel execution #577

Merged
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 CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Contributors
* Carlos Coêlho (`@chocoelho <https://github.com/chocoelho>`_)
* Carlos Cruz (`@ccruz09 <https://github.com/ccruz09>`_)
* Claudiu Popa (`@PCManticore <https://github.com/PCManticore>`_)
* D Morgan (`@morgangraphics <https://github.com/morgangraphics>` _)
* D Morgan (`@morgangraphics <https://github.com/morgangraphics>`_)
* David J Pugh (`@djpugh <https://github.com/djpugh>`_)
* Eric Brown (`@ericwb <https://github.com/ericwb>`_)
* Florian Bruhin (`@The-Compiler <https://github.com/The-Compiler>`_)
Expand All @@ -25,6 +25,7 @@ Contributors
* Luke Hinds (`@lukehinds <https://github.com/lukehinds>`_)
* Matt Seymour (`@mattseymour <https://github.com/mattseymour>`_)
* Michael Tinsley (`@michaeltinsley <https://github.com/michaeltinsley>`_)
* Michal Petrucha (`@koniiiik <https://github.com/koniiiik>`_)
* Phil Frost (`@bitglue <https://github.com/bitglue>`_)
* Phil Jones (`@pgjones <https://github.com/pgjones>`_)
* Pierre Sassoulas (`@Pierre-Sassoulas <https://github.com/Pierre-Sassoulas>`_)
Expand Down
110 changes: 72 additions & 38 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions prospector/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ def __init__(self, workdir: Path = None):
self.messages: List[Message] = []

def make_exclusion_filter(self):
# Only close over the attributes required by the filter, rather
# than the entire self, because ProspectorConfig can't be pickled
# because of the config attribute, which would break parallel
# pylint.
ignores, workdir = self.ignores, self.workdir

def _filter(path: Path):
for ignore in self.ignores:
for ignore in ignores:
# first figure out where the path is, relative to the workdir
# ignore-paths/patterns will usually be relative to a repository
# root or the CWD, but the path passed to prospector may not be
path = path.resolve().absolute()
if is_relative_to(path, self.workdir):
path = path.relative_to(self.workdir)
if is_relative_to(path, workdir):
path = path.relative_to(workdir)
if ignore.match(str(path)):
return True
return False
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ include = [
prospector = 'prospector.run:main'

[tool.poetry.dependencies]
python = ">=3.7,<4.0"
python = ">=3.7.2,<4.0"
carlio marked this conversation as resolved.
Show resolved Hide resolved
pylint = ">=2.8.3"
pylint-celery = "0.3"
pylint-django = "~2.5"
Expand Down
5 changes: 5 additions & 0 deletions tests/tools/pylint/parallel/.prospector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
max-line-length: 40

pylint:
options:
jobs: 2
Empty file.
2 changes: 2 additions & 0 deletions tests/tools/pylint/parallel/one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def this_is_a_line_that_is_longer_than_40_characters():
return "hi"
18 changes: 16 additions & 2 deletions tests/tools/pylint/test_pylint_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def _get_pylint_tool_and_prospector_config(argv_patch=None) -> Tuple[PylintTool,
return pylint_tool, config


def _get_test_files(*names: str):
def _get_test_files(*names: str, exclusion_filters=None):
paths = [THIS_DIR / name for name in names]
return FileFinder(*paths)
return FileFinder(*paths, exclusion_filters=exclusion_filters)


class TestPylintTool(TestCase):
Expand Down Expand Up @@ -95,3 +95,17 @@ def test_will_throw_useless_suppression(self):
assert any(
m.code == "useless-suppression" for m in messages
), "There should be at least one useless suppression"

def test_parallel_execution(self):
root = THIS_DIR / "parallel"

with patch("pathlib.Path.cwd", return_value=root.absolute()):
pylint_tool, config = _get_pylint_tool_and_prospector_config()
self.assertEqual(Path(config.workdir).absolute(), root.absolute())

found_files = _get_test_files(root, exclusion_filters=[config.make_exclusion_filter()])
pylint_tool.configure(config, found_files)
assert pylint_tool._linter.config.jobs == 2

messages = pylint_tool.run(found_files)
assert "line-too-long" in [msg.code for msg in messages if msg.source == "pylint"]