Skip to content

Commit 0b3aecf

Browse files
committed
style: collapse nested if statements in test_regexes.py (SIM102)
1 parent ca4636d commit 0b3aecf

1 file changed

Lines changed: 69 additions & 27 deletions

File tree

scripts/test_regexes.py

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,18 @@ def check_group_quality(match, regex_str):
7777
mc = groups.get("mc")
7878
version = groups.get("version")
7979

80-
if mc:
81-
# mc group should only contain version-like characters (digits and dots)
82-
if re.search(r"[a-zA-Z]", mc):
83-
warnings.append(f"mc group contains non-version chars: '{mc}'")
84-
85-
if version and mc:
86-
# version should not contain the MC version
87-
if mc in version:
88-
warnings.append(f"version group contains MC version '{mc}': '{version}'")
89-
90-
if version:
91-
# version starting with MC version pattern (1.X.Y-...) followed by a separator
92-
# and another digit is suspicious if there's no mc group
93-
if not mc and re.match(r"1\.\d{2,}(?:\.\d+)*[-+]\d", version):
94-
warnings.append(f"version may contain MC version (no mc group): '{version}'")
80+
# mc group should only contain version-like characters (digits and dots)
81+
if mc and re.search(r"[a-zA-Z]", mc):
82+
warnings.append(f"mc group contains non-version chars: '{mc}'")
83+
84+
# version should not contain the MC version
85+
if version and mc and mc in version:
86+
warnings.append(f"version group contains MC version '{mc}': '{version}'")
87+
88+
# version starting with MC version pattern (1.X.Y-...) followed by a separator
89+
# and another digit is suspicious if there's no mc group
90+
if version and not mc and re.match(r"1\.\d{2,}(?:\.\d+)*[-+]\d", version):
91+
warnings.append(f"version may contain MC version (no mc group): '{version}'")
9592

9693
return warnings
9794

@@ -172,8 +169,20 @@ async def check_curse(session, mod_name, mod_data, compiled_regex, *, use_cache=
172169
all_files_info.append(f"Non-matching: {non_matching}")
173170

174171
if last_update and last_update < STALE_CUTOFF:
175-
return STALE, f"Match: {latest} -> {match.groupdict()}", last_update, filenames[:5] + all_files_info, quality_warnings
176-
return PASS, f"Match: {latest} -> {match.groupdict()}", last_update, filenames[:5] + all_files_info, quality_warnings
172+
return (
173+
STALE,
174+
f"Match: {latest} -> {match.groupdict()}",
175+
last_update,
176+
filenames[:5] + all_files_info,
177+
quality_warnings,
178+
)
179+
return (
180+
PASS,
181+
f"Match: {latest} -> {match.groupdict()}",
182+
last_update,
183+
filenames[:5] + all_files_info,
184+
quality_warnings,
185+
)
177186

178187
return FAIL, "No filenames found", last_update, [], quality_warnings
179188

@@ -212,7 +221,9 @@ async def check_jenkins(session, mod_name, mod_data, compiled_regex, *, use_cach
212221
return FAIL, f"Artifact index {item_idx} out of range ({len(filenames)} artifacts)", last_update, filenames, []
213222

214223

215-
async def check_github_release(session, mod_name, mod_data, compiled_regex, config, *, use_cache=False, all_files=False):
224+
async def check_github_release(
225+
session, mod_name, mod_data, compiled_regex, config, *, use_cache=False, all_files=False
226+
):
216227
github = mod_data["github"]
217228
repo = github["repo"]
218229
type_ = github.get("type", "asset")
@@ -247,7 +258,13 @@ async def check_github_release(session, mod_name, mod_data, compiled_regex, conf
247258
if match:
248259
quality_warnings = check_group_quality(match, compiled_regex.pattern)
249260
if last_update and last_update < STALE_CUTOFF:
250-
return STALE, f"Match tag: {tag_name} -> {match.groupdict()}", last_update, [tag_name], quality_warnings
261+
return (
262+
STALE,
263+
f"Match tag: {tag_name} -> {match.groupdict()}",
264+
last_update,
265+
[tag_name],
266+
quality_warnings,
267+
)
251268
return PASS, f"Match tag: {tag_name} -> {match.groupdict()}", last_update, [tag_name], quality_warnings
252269
return FAIL, f"No match on tag: {tag_name}", last_update, [tag_name], []
253270
else:
@@ -262,14 +279,26 @@ async def check_github_release(session, mod_name, mod_data, compiled_regex, conf
262279
if match:
263280
quality_warnings = check_group_quality(match, compiled_regex.pattern)
264281
if last_update and last_update < STALE_CUTOFF:
265-
return STALE, f"Match: {name} -> {match.groupdict()}", last_update, asset_names[:5], quality_warnings
282+
return (
283+
STALE,
284+
f"Match: {name} -> {match.groupdict()}",
285+
last_update,
286+
asset_names[:5],
287+
quality_warnings,
288+
)
266289
return PASS, f"Match: {name} -> {match.groupdict()}", last_update, asset_names[:5], quality_warnings
267290

268291
all_assets = []
269292
for release in releases[:3]:
270293
all_assets.extend(a["name"] for a in release.get("assets", []))
271294
total_releases = min(3, len(releases))
272-
return FAIL, f"No match in {len(all_assets)} assets across {total_releases} releases", last_update, all_assets[:10], []
295+
return (
296+
FAIL,
297+
f"No match in {len(all_assets)} assets across {total_releases} releases",
298+
last_update,
299+
all_assets[:10],
300+
[],
301+
)
273302

274303

275304
async def check_forge_json(session, mod_name, mod_data, compiled_regex, *, use_cache=False, all_files=False):
@@ -396,13 +425,22 @@ async def test_mod(session, mod_name, mod_data, config, *, use_cache=False, all_
396425
try:
397426
if function == "github_release":
398427
status, detail, last_update, samples, quality_warnings = await checker(
399-
session, mod_name, mod_data, compiled_regex, config,
400-
use_cache=use_cache, all_files=all_files,
428+
session,
429+
mod_name,
430+
mod_data,
431+
compiled_regex,
432+
config,
433+
use_cache=use_cache,
434+
all_files=all_files,
401435
)
402436
else:
403437
status, detail, last_update, samples, quality_warnings = await checker(
404-
session, mod_name, mod_data, compiled_regex,
405-
use_cache=use_cache, all_files=all_files,
438+
session,
439+
mod_name,
440+
mod_data,
441+
compiled_regex,
442+
use_cache=use_cache,
443+
all_files=all_files,
406444
)
407445
except Exception as e:
408446
status = DEAD
@@ -470,8 +508,12 @@ async def main():
470508
continue
471509

472510
result = await test_mod(
473-
session, mod_name, mod_data, config,
474-
use_cache=args.cache, all_files=args.all_files,
511+
session,
512+
mod_name,
513+
mod_data,
514+
config,
515+
use_cache=args.cache,
516+
all_files=args.all_files,
475517
)
476518
results.append(result)
477519

0 commit comments

Comments
 (0)