Skip to content

Commit 05817f9

Browse files
Merge branch 'main' into scott/token-validation
2 parents 7888089 + 424e8ee commit 05817f9

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

codecov_cli/services/staticanalysis/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import typing
55
from functools import partial
6-
from multiprocessing import get_context
6+
from multiprocessing import Pool
77
from pathlib import Path
88

99
import click
@@ -187,7 +187,9 @@ async def process_files(
187187
length=len(files_to_analyze),
188188
label="Analyzing files",
189189
) as bar:
190-
with get_context("fork").Pool(processes=numberprocesses) as pool:
190+
# https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods
191+
# from the link above, we want to use the default start methods
192+
with Pool(processes=numberprocesses) as pool:
191193
file_results = pool.imap_unordered(mapped_func, files_to_analyze)
192194
for result in file_results:
193195
bar.update(1, result)

codecov_cli/services/upload/upload_collector.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ def _get_file_fixes(
112112

113113
try:
114114
with open(filename, "r") as f:
115+
# If lineno is unset that means that the
116+
# file is empty thus the eof should be 0
117+
# so lineno will be set to -1 here
118+
lineno = -1
119+
# overwrite lineno in this for loop
120+
# if f is empty, lineno stays at -1
115121
for lineno, line_content in enumerate(f):
116122
if any(
117123
pattern.match(line_content)
@@ -123,7 +129,6 @@ def _get_file_fixes(
123129
for pattern in fix_patterns_to_apply.without_reason
124130
):
125131
fixed_lines_without_reason.add(lineno + 1)
126-
127132
if fix_patterns_to_apply.eof:
128133
eof = lineno + 1
129134
except UnicodeDecodeError as err:

tests/services/static_analysis/test_static_analysis_service.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ async def test_process_files_with_error(self, mocker):
3232
],
3333
)
3434
)
35-
mock_get_context = mocker.patch(
36-
"codecov_cli.services.staticanalysis.get_context"
37-
)
35+
mock_pool = mocker.patch("codecov_cli.services.staticanalysis.Pool")
3836

3937
def side_effect(config, filename: FileAnalysisRequest):
4038
if filename.result_filename == "correct_file.py":
@@ -59,12 +57,12 @@ def imap_side_effect(mapped_func, files):
5957
results.append(mapped_func(file))
6058
return results
6159

62-
mock_get_context.return_value.Pool.return_value.__enter__.return_value.imap_unordered.side_effect = (
60+
mock_pool.return_value.__enter__.return_value.imap_unordered.side_effect = (
6361
imap_side_effect
6462
)
6563

6664
results = await process_files(files_found, 1, {})
67-
mock_get_context.return_value.Pool.return_value.__enter__.return_value.imap_unordered.assert_called()
65+
mock_pool.return_value.__enter__.return_value.imap_unordered.assert_called()
6866
assert mock_analyze_function.call_count == 2
6967
assert results == dict(
7068
all_data={"correct_file.py": {"hash": "abc123"}},

0 commit comments

Comments
 (0)