Skip to content

Commit 31157a1

Browse files
committed
mypy and ruff fixes
Add jenkins pipelines python to github validation
1 parent 0b490f1 commit 31157a1

11 files changed

Lines changed: 86 additions & 42 deletions

File tree

.github/workflows/python_verify.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ on:
44
branches:
55
- main
66
paths:
7-
- 'client/smoke_tests/**'
8-
- 'client/src/**'
9-
- 'environment/**'
10-
- 'tests/**'
7+
- 'client/smoke_tests/**/*.py'
8+
- 'client/src/**/*.py'
9+
- 'environment/**/*.py'
10+
- 'tests/**/*.py'
11+
- 'jenkins/pipelines/**/*.py'
1112
pull_request:
1213
branches:
1314
- "**"
1415
paths:
15-
- 'client/smoke_tests/**'
16-
- 'client/src/**'
17-
- 'environment/**'
18-
- 'tests/**'
16+
- 'client/smoke_tests/**/*.py'
17+
- 'client/src/**/*.py'
18+
- 'environment/**/*.py'
19+
- 'tests/**/*.py'
20+
- 'jenkins/pipelines/**/*.py'
1921

2022
jobs:
2123
mypy:

.github/workflows/verify_python.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ echo "Checking client files (including smoke tests)..."
1313
python -m mypy client --exclude=venv
1414
echo "Checking environment setup..."
1515
python -m mypy environment --exclude=venv --explicit-package-bases --check-untyped-defs
16+
echo "Checking Jenkins pipelines..."
17+
python -m mypy jenkins --exclude=venv --explicit-package-bases
1618
deactivate
1719
rm -rf venv

environment/aws/common/io.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
Unzip the contents of a zip file to a directory.
1717
"""
1818

19-
from contextlib import contextmanager
2019
import os
2120
import tarfile
2221
import zipfile

environment/aws/start_backend.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def convert(
6060

6161
self.fail("Unable to convert non string value to TopologyConfig", param, ctx)
6262

63+
6364
def topology_has_aws_resources(topology: TopologyConfig) -> bool:
6465
"""
6566
Check if the topology has any AWS resources.
@@ -78,6 +79,7 @@ def topology_has_aws_resources(topology: TopologyConfig) -> bool:
7879
or topology.wants_logslurp
7980
)
8081

82+
8183
def terraform_apply(public_key_name: Optional[str], topology: TopologyConfig) -> None:
8284
"""
8385
Apply the Terraform configuration to set up the AWS environment.
@@ -95,7 +97,7 @@ def terraform_apply(public_key_name: Optional[str], topology: TopologyConfig) ->
9597
if not topology_has_aws_resources(topology):
9698
click.secho("No AWS resources requested, skipping terraform", fg="yellow")
9799
return
98-
100+
99101
if public_key_name is None:
100102
raise Exception(
101103
"--public-key-name was not provided, but it is required for AWS resources."
@@ -106,7 +108,7 @@ def terraform_apply(public_key_name: Optional[str], topology: TopologyConfig) ->
106108
raise Exception(
107109
f"Command 'terraform init' failed with exit status {result.returncode}: {result.stderr}"
108110
)
109-
111+
110112
sgw_count = topology.total_sgw_count
111113
cbs_count = topology.total_cbs_count
112114
lb_count = topology.total_lb_count
@@ -388,6 +390,7 @@ def cli_entry(
388390
steps,
389391
)
390392

393+
391394
def script_entry(
392395
topology: TopologyConfig,
393396
public_key_name: Optional[str],
@@ -407,11 +410,16 @@ def script_entry(
407410
)
408411
else:
409412
args = [
410-
"--topology", topology,
411-
"--public-key-name", public_key_name,
412-
"--tdk-config-in", tdk_config_in,
413-
"--private-key", private_key,
414-
"--tdk-config-out", tdk_config_out
413+
"--topology",
414+
topology,
415+
"--public-key-name",
416+
public_key_name,
417+
"--tdk-config-in",
418+
tdk_config_in,
419+
"--private-key",
420+
private_key,
421+
"--tdk-config-out",
422+
tdk_config_out,
415423
]
416424
cli_entry(args)
417425

jenkins/pipelines/android/logcat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ def adb_logcat(adb_path, device_serial):
1919

2020
with subprocess.Popen(cmd, stdout=subprocess.PIPE) as log:
2121
while True:
22-
line = log.stdout.readline()
23-
if not line:
22+
if not log.stdout:
2423
break
2524

26-
line = line.decode("utf-8")
25+
line = log.stdout.readline().decode()
2726

2827
if out_file is not None:
2928
out_file.write(line)

jenkins/pipelines/android/setup_test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
from typing import Optional
5-
import click
64
import os
75
import sys
6+
from io import TextIOWrapper
87
from pathlib import Path
8+
from typing import Optional, cast
9+
10+
import click
911

1012
SCRIPT_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
1113

1214
if __name__ == "__main__":
1315
sys.path.append(str(SCRIPT_DIR.parents[2]))
14-
sys.stdout.reconfigure(encoding="utf-8")
16+
if isinstance(sys.stdout, TextIOWrapper):
17+
cast(TextIOWrapper, sys.stdout).reconfigure(encoding="utf-8")
1518

1619
from jenkins.pipelines.shared.setup_test import setup_test
1720

21+
1822
@click.command()
1923
@click.argument("cbl_version")
2024
@click.argument("dataset_version")
@@ -36,8 +40,9 @@ def cli_entry(
3640
SCRIPT_DIR / "topology_single_device.json",
3741
SCRIPT_DIR / "config_android.json",
3842
"jak_android",
39-
private_key
43+
private_key,
4044
)
4145

46+
4247
if __name__ == "__main__":
4348
cli_entry()

jenkins/pipelines/c/setup_test.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
import click
54
import os
65
import sys
6+
from io import TextIOWrapper
77
from pathlib import Path
8-
from typing import Optional
8+
from typing import Optional, cast
9+
10+
import click
911

1012
SCRIPT_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
1113
if __name__ == "__main__":
1214
sys.path.append(str(SCRIPT_DIR.parents[2]))
13-
sys.stdout.reconfigure(encoding="utf-8")
15+
if isinstance(sys.stdout, TextIOWrapper):
16+
cast(TextIOWrapper, sys.stdout).reconfigure(encoding="utf-8")
1417

1518
from jenkins.pipelines.shared.setup_test import setup_test
1619

20+
1721
@click.command()
1822
@click.argument("platform")
1923
@click.argument("cbl_version")
@@ -41,5 +45,6 @@ def cli_entry(
4145
private_key,
4246
)
4347

48+
4449
if __name__ == "__main__":
4550
cli_entry()

jenkins/pipelines/dotnet/setup_test.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
import click
54
import os
65
import sys
6+
from io import TextIOWrapper
77
from pathlib import Path
8-
from typing import Optional
8+
from typing import Optional, cast
9+
10+
import click
911

1012
SCRIPT_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
1113
if __name__ == "__main__":
1214
sys.path.append(str(SCRIPT_DIR.parents[2]))
13-
sys.stdout.reconfigure(encoding="utf-8")
15+
if isinstance(sys.stdout, TextIOWrapper):
16+
cast(TextIOWrapper, sys.stdout).reconfigure(encoding="utf-8")
1417

1518
from jenkins.pipelines.shared.setup_test import setup_test
1619

20+
1721
@click.command()
1822
@click.argument("platform")
1923
@click.argument("cbl_version")
@@ -40,5 +44,6 @@ def cli_entry(
4044
private_key,
4145
)
4246

47+
4348
if __name__ == "__main__":
4449
cli_entry()

jenkins/pipelines/ios/setup_test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
from typing import Optional
5-
import click
64
import os
75
import sys
6+
from io import TextIOWrapper
87
from pathlib import Path
8+
from typing import Optional, cast
9+
10+
import click
911

1012
SCRIPT_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
1113

1214
if __name__ == "__main__":
1315
sys.path.append(str(SCRIPT_DIR.parents[2]))
14-
sys.stdout.reconfigure(encoding="utf-8")
16+
if isinstance(sys.stdout, TextIOWrapper):
17+
cast(TextIOWrapper, sys.stdout).reconfigure(encoding="utf-8")
1518

1619
from jenkins.pipelines.shared.setup_test import setup_test
1720

21+
1822
@click.command()
1923
@click.argument("cbl_version")
2024
@click.argument("dataset_version")
@@ -35,9 +39,10 @@ def cli_entry(
3539
sgw_version,
3640
SCRIPT_DIR / "topology_single_device.json",
3741
SCRIPT_DIR / "config.json",
38-
f"swift_ios",
42+
"swift_ios",
3943
private_key,
4044
)
4145

46+
4247
if __name__ == "__main__":
4348
cli_entry()

jenkins/pipelines/java/webservice/setup_test.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
import click
54
import os
65
import sys
6+
from io import TextIOWrapper
77
from pathlib import Path
8-
from typing import Optional
8+
from typing import Optional, cast
9+
10+
import click
911

1012
SCRIPT_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
1113
if __name__ == "__main__":
1214
sys.path.append(str(SCRIPT_DIR.parents[3]))
13-
sys.stdout.reconfigure(encoding="utf-8")
15+
if isinstance(sys.stdout, TextIOWrapper):
16+
cast(TextIOWrapper, sys.stdout).reconfigure(encoding="utf-8")
1417

1518
from jenkins.pipelines.shared.setup_test import setup_test
1619

20+
1721
@click.command()
1822
@click.argument("platform")
1923
@click.argument("cbl_version")
@@ -40,5 +44,6 @@ def cli_entry(
4044
private_key,
4145
)
4246

47+
4348
if __name__ == "__main__":
4449
cli_entry()

0 commit comments

Comments
 (0)