Skip to content

Commit 1e0d703

Browse files
committed
Auto-format codebase
This runs `ruff` autoformatting and fixing across the whole repo.
1 parent e9bcffd commit 1e0d703

10 files changed

Lines changed: 120 additions & 79 deletions

File tree

codecov_cli/commands/create_report_result.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,12 @@ def create_report_results(
3737
),
3838
)
3939
create_report_results_logic(
40-
commit_sha, code, slug, git_service, token, enterprise_url, fail_on_error, args
40+
commit_sha,
41+
code,
42+
slug,
43+
git_service,
44+
token,
45+
enterprise_url,
46+
fail_on_error,
47+
args,
4148
)

codecov_cli/commands/empty_upload.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,12 @@ def empty_upload(
7676
),
7777
)
7878
return empty_upload_logic(
79-
commit_sha, slug, token, git_service, enterprise_url, fail_on_error, force, args
79+
commit_sha,
80+
slug,
81+
token,
82+
git_service,
83+
enterprise_url,
84+
fail_on_error,
85+
force,
86+
args,
8087
)

codecov_cli/helpers/glob.py

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,46 @@ def translate(pat, *, recursive=False, include_hidden=False, seps=None):
3131
seps = (os.path.sep, os.path.altsep)
3232
else:
3333
seps = os.path.sep
34-
escaped_seps = ''.join(map(re.escape, seps))
35-
any_sep = f'[{escaped_seps}]' if len(seps) > 1 else escaped_seps
36-
not_sep = f'[^{escaped_seps}]'
34+
escaped_seps = "".join(map(re.escape, seps))
35+
any_sep = f"[{escaped_seps}]" if len(seps) > 1 else escaped_seps
36+
not_sep = f"[^{escaped_seps}]"
3737
if include_hidden:
38-
one_last_segment = f'{not_sep}+'
39-
one_segment = f'{one_last_segment}{any_sep}'
40-
any_segments = f'(?:.+{any_sep})?'
41-
any_last_segments = '.*'
38+
one_last_segment = f"{not_sep}+"
39+
one_segment = f"{one_last_segment}{any_sep}"
40+
any_segments = f"(?:.+{any_sep})?"
41+
any_last_segments = ".*"
4242
else:
43-
one_last_segment = f'[^{escaped_seps}.]{not_sep}*'
44-
one_segment = f'{one_last_segment}{any_sep}'
45-
any_segments = f'(?:{one_segment})*'
46-
any_last_segments = f'{any_segments}(?:{one_last_segment})?'
43+
one_last_segment = f"[^{escaped_seps}.]{not_sep}*"
44+
one_segment = f"{one_last_segment}{any_sep}"
45+
any_segments = f"(?:{one_segment})*"
46+
any_last_segments = f"{any_segments}(?:{one_last_segment})?"
4747

4848
results = []
4949
parts = re.split(any_sep, pat)
5050
last_part_idx = len(parts) - 1
5151
for idx, part in enumerate(parts):
52-
if part == '*':
52+
if part == "*":
5353
results.append(one_segment if idx < last_part_idx else one_last_segment)
54-
elif recursive and part == '**':
54+
elif recursive and part == "**":
5555
if idx < last_part_idx:
56-
if parts[idx + 1] != '**':
56+
if parts[idx + 1] != "**":
5757
results.append(any_segments)
5858
else:
5959
results.append(any_last_segments)
6060
else:
6161
if part:
62-
if not include_hidden and part[0] in '*?':
63-
results.append(r'(?!\.)')
64-
results.extend(_translate(part, f'{not_sep}*', not_sep)[0])
62+
if not include_hidden and part[0] in "*?":
63+
results.append(r"(?!\.)")
64+
results.extend(_translate(part, f"{not_sep}*", not_sep)[0])
6565
if idx < last_part_idx:
6666
results.append(any_sep)
67-
res = ''.join(results)
68-
return fr'(?s:{res})\Z'
67+
res = "".join(results)
68+
return rf"(?s:{res})\Z"
69+
70+
71+
_re_setops_sub = re.compile(r"([&~|])").sub
6972

7073

71-
_re_setops_sub = re.compile(r'([&~|])').sub
7274
def _translate(pat, star, question_mark):
7375
res = []
7476
add = res.append
@@ -77,69 +79,70 @@ def _translate(pat, star, question_mark):
7779
i, n = 0, len(pat)
7880
while i < n:
7981
c = pat[i]
80-
i = i+1
81-
if c == '*':
82+
i = i + 1
83+
if c == "*":
8284
# store the position of the wildcard
8385
star_indices.append(len(res))
8486
add(star)
8587
# compress consecutive `*` into one
86-
while i < n and pat[i] == '*':
88+
while i < n and pat[i] == "*":
8789
i += 1
88-
elif c == '?':
90+
elif c == "?":
8991
add(question_mark)
90-
elif c == '[':
92+
elif c == "[":
9193
j = i
92-
if j < n and pat[j] == '!':
93-
j = j+1
94-
if j < n and pat[j] == ']':
95-
j = j+1
96-
while j < n and pat[j] != ']':
97-
j = j+1
94+
if j < n and pat[j] == "!":
95+
j = j + 1
96+
if j < n and pat[j] == "]":
97+
j = j + 1
98+
while j < n and pat[j] != "]":
99+
j = j + 1
98100
if j >= n:
99-
add('\\[')
101+
add("\\[")
100102
else:
101103
stuff = pat[i:j]
102-
if '-' not in stuff:
103-
stuff = stuff.replace('\\', r'\\')
104+
if "-" not in stuff:
105+
stuff = stuff.replace("\\", r"\\")
104106
else:
105107
chunks = []
106-
k = i+2 if pat[i] == '!' else i+1
108+
k = i + 2 if pat[i] == "!" else i + 1
107109
while True:
108-
k = pat.find('-', k, j)
110+
k = pat.find("-", k, j)
109111
if k < 0:
110112
break
111113
chunks.append(pat[i:k])
112-
i = k+1
113-
k = k+3
114+
i = k + 1
115+
k = k + 3
114116
chunk = pat[i:j]
115117
if chunk:
116118
chunks.append(chunk)
117119
else:
118-
chunks[-1] += '-'
120+
chunks[-1] += "-"
119121
# Remove empty ranges -- invalid in RE.
120-
for k in range(len(chunks)-1, 0, -1):
121-
if chunks[k-1][-1] > chunks[k][0]:
122-
chunks[k-1] = chunks[k-1][:-1] + chunks[k][1:]
122+
for k in range(len(chunks) - 1, 0, -1):
123+
if chunks[k - 1][-1] > chunks[k][0]:
124+
chunks[k - 1] = chunks[k - 1][:-1] + chunks[k][1:]
123125
del chunks[k]
124126
# Escape backslashes and hyphens for set difference (--).
125127
# Hyphens that create ranges shouldn't be escaped.
126-
stuff = '-'.join(s.replace('\\', r'\\').replace('-', r'\-')
127-
for s in chunks)
128-
i = j+1
128+
stuff = "-".join(
129+
s.replace("\\", r"\\").replace("-", r"\-") for s in chunks
130+
)
131+
i = j + 1
129132
if not stuff:
130133
# Empty range: never match.
131-
add('(?!)')
132-
elif stuff == '!':
134+
add("(?!)")
135+
elif stuff == "!":
133136
# Negated empty range: match any character.
134-
add('.')
137+
add(".")
135138
else:
136139
# Escape set operations (&&, ~~ and ||).
137-
stuff = _re_setops_sub(r'\\\1', stuff)
138-
if stuff[0] == '!':
139-
stuff = '^' + stuff[1:]
140-
elif stuff[0] in ('^', '['):
141-
stuff = '\\' + stuff
142-
add(f'[{stuff}]')
140+
stuff = _re_setops_sub(r"\\\1", stuff)
141+
if stuff[0] == "!":
142+
stuff = "^" + stuff[1:]
143+
elif stuff[0] in ("^", "["):
144+
stuff = "\\" + stuff
145+
add(f"[{stuff}]")
143146
else:
144147
add(re.escape(c))
145148
assert i == n

codecov_cli/helpers/request.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def wrapper(*args, **kwargs):
7979
)
8080
sleep(backoff_time(retry))
8181
retry += 1
82-
raise Exception(f"Request failed after too many retries. URL: {kwargs.get('url', args[0] if args else 'Unknown')}")
82+
raise Exception(
83+
f"Request failed after too many retries. URL: {kwargs.get('url', args[0] if args else 'Unknown')}"
84+
)
8385

8486
return wrapper
8587

codecov_cli/plugins/compress_pycoverage_contexts.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def run_preparation(self, collector) -> PreparationPluginReturn:
6464
)
6565
return PreparationPluginReturn(
6666
success=False,
67-
messages=[f"File to compress {self.file_to_compress} is not a file."],
67+
messages=[
68+
f"File to compress {self.file_to_compress} is not a file."
69+
],
6870
)
6971
# Create in and out streams
7072
fd_in = open(self.file_to_compress, "rb")

codecov_cli/plugins/gcov.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def run_preparation(self, collector) -> PreparationPluginReturn:
4040
logger.warning(f"{self.executable} is not installed or can't be found.")
4141
return
4242

43-
filename_include_regex = globs_to_regex(["*.gcno", *self.patterns_to_include])
43+
filename_include_regex = globs_to_regex(
44+
["*.gcno", *self.patterns_to_include]
45+
)
4446
filename_exclude_regex = globs_to_regex(self.patterns_to_ignore)
4547

4648
matched_paths = [

codecov_cli/services/report/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ def send_create_report_request(
5555
pull_request_number,
5656
args,
5757
):
58-
data = {
59-
"cli_args": args,
60-
"code": code,
61-
}
58+
data = {"cli_args": args, "code": code}
6259
headers = get_token_header(token)
6360
upload_url = enterprise_url or CODECOV_INGEST_URL
6461
url = f"{upload_url}/upload/{service}/{encoded_slug}/commits/{commit_sha}/reports"
@@ -101,9 +98,7 @@ def send_reports_result_request(
10198
enterprise_url,
10299
args,
103100
):
104-
data = {
105-
"cli_args": args,
106-
}
101+
data = {"cli_args": args}
107102
headers = get_token_header(token)
108103
upload_url = enterprise_url or CODECOV_API_URL
109104
url = f"{upload_url}/upload/{service}/{encoded_slug}/commits/{commit_sha}/reports/{report_code}/results"

command_dump.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def command_dump(commands):
1616

1717
if "Commands:" in split_docs:
1818
sub_commands = [
19-
sub_command.strip() for sub_command in split_docs[index_of + 1 :] if sub_command.strip()
19+
sub_command.strip()
20+
for sub_command in split_docs[index_of + 1 :]
21+
if sub_command.strip()
2022
]
2123
for sub_command in sub_commands:
2224
command_docs = "\n".join(

tests/commands/test_invoke_empty_upload.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,37 @@
44
from codecov_cli.main import cli
55
from tests.factory import FakeProvider, FakeVersioningSystem
66

7+
78
def test_invoke_empty_upload_with_create_commit(mocker):
8-
create_commit_mock = mocker.patch("codecov_cli.commands.empty_upload.create_commit_logic")
9-
empty_upload_mock = mocker.patch("codecov_cli.commands.empty_upload.empty_upload_logic")
9+
create_commit_mock = mocker.patch(
10+
"codecov_cli.commands.empty_upload.create_commit_logic"
11+
)
12+
empty_upload_mock = mocker.patch(
13+
"codecov_cli.commands.empty_upload.empty_upload_logic"
14+
)
1015

1116
fake_ci_provider = FakeProvider({FallbackFieldEnum.commit_sha: None})
1217
mocker.patch("codecov_cli.main.get_ci_adapter", return_value=fake_ci_provider)
1318

1419
runner = CliRunner()
15-
result = runner.invoke(cli, ["empty-upload",
16-
"-C", "command-sha",
17-
"--slug", "owner/repo",
18-
"--parent-sha", "asdf",
19-
"--branch", "main",
20-
"--pr", 1234], obj={})
20+
result = runner.invoke(
21+
cli,
22+
[
23+
"empty-upload",
24+
"-C",
25+
"command-sha",
26+
"--slug",
27+
"owner/repo",
28+
"--parent-sha",
29+
"asdf",
30+
"--branch",
31+
"main",
32+
"--pr",
33+
1234,
34+
],
35+
obj={},
36+
)
2137
assert result.exit_code == 0
2238

2339
create_commit_mock.assert_called_once()
2440
empty_upload_mock.assert_called_once()
25-

tests/services/upload/test_coverage_file_finder.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,16 @@ def test_find_coverage_files_with_directory_named_as_file(
226226
for file in coverage_files:
227227
file.touch()
228228

229-
coverage_file_finder.explicitly_listed_files = [Path("coverage.xml/coverage.xml")]
229+
coverage_file_finder.explicitly_listed_files = [
230+
Path("coverage.xml/coverage.xml")
231+
]
230232
result = sorted(
231233
[file.get_filename() for file in coverage_file_finder.find_files()]
232234
)
233235
expected = [
234-
UploadCollectionResultFile(Path(f"{project_root}/coverage.xml/coverage.xml")),
236+
UploadCollectionResultFile(
237+
Path(f"{project_root}/coverage.xml/coverage.xml")
238+
),
235239
]
236240
expected_paths = sorted([file.get_filename() for file in expected])
237241
assert result == expected_paths
@@ -241,7 +245,9 @@ def test_find_coverage_files_with_directory_named_as_file(
241245
[file.get_filename() for file in coverage_file_finder.find_files()]
242246
)
243247
expected = [
244-
UploadCollectionResultFile(Path(f"{project_root}/coverage.xml/coverage.xml")),
248+
UploadCollectionResultFile(
249+
Path(f"{project_root}/coverage.xml/coverage.xml")
250+
),
245251
]
246252
expected_paths = sorted([file.get_filename() for file in expected])
247253
assert result == expected_paths

0 commit comments

Comments
 (0)