Skip to content

Commit aecc350

Browse files
committed
style: fix linting and formatting in resync-all-specs.py
Applied black formatting and fixed ruff issues (noqa placements, type hints, and pathlib migration) to pass CI/CD.
1 parent 88a6046 commit aecc350

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

.evergreen/scripts/resync-all-specs.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import subprocess
77
from argparse import Namespace
88
from subprocess import CalledProcessError
9-
from typing import Optional
109

1110

1211
def resync_specs(directory: pathlib.Path, errored: dict[str, str]) -> None:
@@ -19,8 +18,8 @@ def resync_specs(directory: pathlib.Path, errored: dict[str, str]) -> None:
1918
if spec.name in ["asynchronous"]:
2019
continue
2120
try:
22-
subprocess.run(
23-
["bash", "./.evergreen/resync-specs.sh", spec.name], # noqa: S603, S607
21+
subprocess.run( # noqa: S603
22+
["bash", "./.evergreen/resync-specs.sh", spec.name], # noqa: S607
2423
capture_output=True,
2524
text=True,
2625
check=True,
@@ -32,16 +31,24 @@ def resync_specs(directory: pathlib.Path, errored: dict[str, str]) -> None:
3231

3332
def apply_patches(errored):
3433
print("Beginning to apply patches")
35-
subprocess.run(["bash", "./.evergreen/remove-unimplemented-tests.sh"], check=True) # noqa: S603, S607
34+
subprocess.run(
35+
["bash", "./.evergreen/remove-unimplemented-tests.sh"], # noqa: S607
36+
check=True,
37+
)
3638
try:
3739
# Avoid shell=True by passing arguments as a list.
3840
# Note: glob expansion doesn't work in shell=False, so we use a list of files.
39-
import glob
40-
41-
patches = glob.glob("./.evergreen/spec-patch/*")
41+
patches = [str(p) for p in pathlib.Path("./.evergreen/spec-patch/").glob("*")]
4242
if patches:
43-
subprocess.run(
44-
["git", "apply", "-R", "--allow-empty", "--whitespace=fix"] + patches,
43+
subprocess.run( # noqa: S603
44+
[ # noqa: S607
45+
"git",
46+
"apply",
47+
"-R",
48+
"--allow-empty",
49+
"--whitespace=fix",
50+
*patches,
51+
],
4552
check=True,
4653
stderr=subprocess.PIPE,
4754
)
@@ -59,7 +66,11 @@ def check_new_spec_directories(directory: pathlib.Path) -> list[str]:
5966
and (pathlib.Path(entry.path) / "tests").is_dir()
6067
and len(list(os.scandir(pathlib.Path(entry.path) / "tests"))) > 1
6168
}
62-
test_set = {entry.name.replace("-", "_") for entry in os.scandir(directory) if entry.is_dir()}
69+
test_set = {
70+
entry.name.replace("-", "_")
71+
for entry in os.scandir(directory)
72+
if entry.is_dir()
73+
}
6374
known_mappings = {
6475
"ocsp_support": "ocsp",
6576
"client_side_operations_timeout": "csot",
@@ -78,12 +89,14 @@ def check_new_spec_directories(directory: pathlib.Path) -> list[str]:
7889
return list(spec_set - test_set)
7990

8091

81-
def write_summary(errored: dict[str, str], new: list[str], filename: Optional[str]) -> None:
92+
def write_summary(
93+
errored: dict[str, str], new: list[str], filename: str | None
94+
) -> None:
8295
"""Generate the PR description"""
8396
pr_body = ""
8497
# Avoid shell=True and complex pipes by using Python to process git output
8598
process = subprocess.run(
86-
["git", "diff", "--name-only"],
99+
["git", "diff", "--name-only"], # noqa: S607
87100
capture_output=True,
88101
text=True,
89102
check=True,
@@ -94,7 +107,7 @@ def write_summary(errored: dict[str, str], new: list[str], filename: Optional[st
94107
parts = f.split("/")
95108
if len(parts) > 1:
96109
succeeded_set.add(parts[1])
97-
succeeded = sorted(list(succeeded_set))
110+
succeeded = sorted(succeeded_set)
98111

99112
if len(succeeded) > 0:
100113
pr_body += "The following specs were changed:\n -"
@@ -132,7 +145,9 @@ def main(args: Namespace):
132145
description="Python Script to resync all specs and generate summary for PR."
133146
)
134147
parser.add_argument(
135-
"--filename", help="Name of file for the summary to be written into.", default=None
148+
"--filename",
149+
help="Name of file for the summary to be written into.",
150+
default=None,
136151
)
137152
args = parser.parse_args()
138153
main(args)

0 commit comments

Comments
 (0)