Skip to content

Commit

Permalink
Support duplicate-code message with --jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jun 10, 2023
1 parent 2acca90 commit 0a88e97
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/374.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Support ``duplicate-code`` message when parallelizing with ``--jobs``.

Closes #374
3 changes: 3 additions & 0 deletions pylint/checkers/similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,11 @@ def reduce_map_data(self, linter: PyLinter, data: list[list[LineSet]]) -> None:
"""Reduces and recombines data into a format that we can report on.
The partner function of get_map_data()
Calls self.close() to actually calculate and report duplicate code.
"""
Similar.combine_mapreduce_data(self, linesets_collection=data)
self.close()


def register(linter: PyLinter) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pylint/lint/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def check_parallel(
"""Use the given linter to lint the files with given amount of workers (jobs).
This splits the work filestream-by-filestream. If you need to do work across
multiple files, as in the similarity-checker, then implement the map/reduce mixin functionality.
multiple files, as in the similarity-checker, then implement the map/reduce functionality.
"""
# The linter is inherited by all the pool's workers, i.e. the linter
# is identical to the linter object here. This is required so that
Expand Down
1 change: 0 additions & 1 deletion tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def test_parallel_execution(self) -> None:
join(HERE, "functional", "a", "arguments.py"),
],
out=out,
# We expect similarities to fail and an error
code=MSG_TYPES_STATUS["E"],
)
assert (
Expand Down
17 changes: 17 additions & 0 deletions tests/test_similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ def test_duplicate_code_raw_strings_all(self) -> None:
expected_output=expected_output,
)

@pytest.mark.needs_two_cores
def test_duplicate_code_parallel(self) -> None:
path = join(DATA, "raw_strings_all")
expected_output = "Similar lines in 2 files"
self._test_output(
[
path,
"--disable=all",
"--enable=duplicate-code",
"--ignore-imports=no",
"--ignore-signatures=no",
"--min-similarity-lines=4",
"--jobs=2",
],
expected_output=expected_output,
)

def test_duplicate_code_raw_strings_disable_file(self) -> None:
"""Tests disabling duplicate-code at the file level in a single file."""
path = join(DATA, "raw_strings_disable_file")
Expand Down

0 comments on commit 0a88e97

Please sign in to comment.