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

Support duplicate-code message with --jobs #8757

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: 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()
Copy link
Contributor

Choose a reason for hiding this comment

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

Simple as that is it! Great stuff!! :)

Copy link
Member

Choose a reason for hiding this comment

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

Holy mother of Guido, was it that simple ?!



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.
Copy link
Contributor

Choose a reason for hiding this comment

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

is it no longer [considered] a mix-in class?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, see #6383 and #8409

Copy link
Contributor

Choose a reason for hiding this comment

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

Oooooh, hadn't seen those, sexy

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
Copy link
Member Author

Choose a reason for hiding this comment

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

No reason to expect similarity to fail when checking only one file. Maybe an earlier version of this test checked the same file twice?

Copy link
Contributor

Choose a reason for hiding this comment

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

The comment was very unclear, sorry about that.

It was meant to say something like:

if we test the same file twice, which this test was doing, in parallel mode we get extra errors, so we only test a single file here in parallel mode, ensuring it errors. All parallel checks are in their own file now.

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