Skip to content

Commit

Permalink
avoid starting unnecessary processes when file count is limited
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Feb 16, 2025
1 parent cf1542c commit f35737a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/flake8/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def start(self) -> None:
exclude=self.exclude,
)
)
self.jobs = min(len(self.filenames), self.jobs)

def stop(self) -> None:
"""Stop checking files."""
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_checker_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ def test_multiprocessing_cpu_count_not_implemented():
assert manager.jobs == 0


def test_jobs_count_limited_to_file_count():
style_guide = style_guide_mock()
style_guide.options.jobs = JobsArgument("4")
style_guide.options.filenames = ["file1", "file2"]
manager = checker.Manager(style_guide, finder.Checkers([], [], []), [])
assert manager.jobs == 4
manager.start()
assert manager.jobs == 2


def test_make_checkers():
"""Verify that we create a list of FileChecker instances."""
style_guide = style_guide_mock()
Expand Down

0 comments on commit f35737a

Please # to comment.