Skip to content

Commit 1b4c9e6

Browse files
[GHA] bandit (#3144)
### Changes - Add sdl.yml with bandit check (version and config like in jenkins job) - Use defusedxml instead of xml - Return #noseq inxamples (was deleted by mistake in #3091)
1 parent 523a698 commit 1b4c9e6

File tree

15 files changed

+48
-12
lines changed

15 files changed

+48
-12
lines changed

.github/scripts/pytest_md_summary.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
# limitations under the License.
1111

1212
import sys
13-
import xml.etree.ElementTree as ET
13+
14+
from defusedxml import ElementTree as ET
1415

1516

1617
def parse_xml_report(xml_file) -> None:

.github/workflows/examples.yml

+1
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ jobs:
124124
- name: Test Summary
125125
if: ${{ !cancelled() }}
126126
run: |
127+
pip install defusedxml==0.7.1
127128
python .github/scripts/pytest_md_summary.py pytest-results.xml >> $GITHUB_STEP_SUMMARY

.github/workflows/sdl.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: sdl
2+
permissions: read-all
3+
4+
on:
5+
pull_request:
6+
types:
7+
- opened
8+
- reopened
9+
- synchronize
10+
11+
jobs:
12+
bandit:
13+
runs-on: ubuntu-20.04
14+
timeout-minutes: 10
15+
defaults:
16+
run:
17+
shell: bash
18+
steps:
19+
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
20+
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
21+
with:
22+
python-version: 3.10.14
23+
- name: Install bandit
24+
run: pip install bandit[toml]==1.7.4
25+
- name: Run bandit
26+
run: bandit -c pyproject.toml -r .
27+

examples/post_training_quantization/onnx/mobilenet_v2/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def run_benchmark(path_to_model: Path, shape: List[int]) -> float:
7171
"-t", "15",
7272
"-shape", str(shape),
7373
] # fmt: skip
74-
cmd_output = subprocess.check_output(command, text=True)
74+
cmd_output = subprocess.check_output(command, text=True) # nosec
7575
print(*cmd_output.splitlines()[-8:], sep="\n")
7676
match = re.search(r"Throughput\: (.+?) FPS", str(cmd_output))
7777
return float(match.group(1))

examples/post_training_quantization/onnx/yolov8_quantize_with_accuracy_control/deploy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def run_benchmark(model_path: Path, config) -> float:
7474
"-t", "30",
7575
"-shape", str([1, 3, config.imgsz, config.imgsz]),
7676
] # fmt: skip
77-
cmd_output = subprocess.check_output(command, text=True)
77+
cmd_output = subprocess.check_output(command, text=True) # nosec
7878
match = re.search(r"Throughput\: (.+?) FPS", cmd_output)
7979
return float(match.group(1))
8080

examples/post_training_quantization/openvino/anomaly_stfpm_quantize_with_accuracy_control/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def run_benchmark(model_path: Path, shape: List[int]) -> float:
9191
"-t", "15",
9292
"-shape", str(shape),
9393
] # fmt: skip
94-
cmd_output = subprocess.check_output(command, text=True)
94+
cmd_output = subprocess.check_output(command, text=True) # nosec
9595
print(*cmd_output.splitlines()[-8:], sep="\n")
9696
match = re.search(r"Throughput\: (.+?) FPS", cmd_output)
9797
return float(match.group(1))

examples/post_training_quantization/openvino/mobilenet_v2/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def validate(model: ov.Model, val_loader: torch.utils.data.DataLoader) -> float:
5757

5858
def run_benchmark(model_path: Path, shape: List[int]) -> float:
5959
cmd = ["benchmark_app", "-m", model_path.as_posix(), "-d", "CPU", "-api", "async", "-t", "15", "-shape", str(shape)]
60-
cmd_output = subprocess.check_output(cmd, text=True)
60+
cmd_output = subprocess.check_output(cmd, text=True) # nosec
6161
print(*cmd_output.splitlines()[-8:], sep="\n")
6262
match = re.search(r"Throughput\: (.+?) FPS", cmd_output)
6363
return float(match.group(1))

examples/post_training_quantization/openvino/yolov8/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def benchmark_performance(model_path: Path, config) -> float:
9191
"-t", "30",
9292
"-shape", str([1, 3, config.imgsz, config.imgsz]),
9393
] # fmt: skip
94-
cmd_output = subprocess.check_output(command, text=True)
94+
cmd_output = subprocess.check_output(command, text=True) # nosec
9595
match = re.search(r"Throughput\: (.+?) FPS", cmd_output)
9696
return float(match.group(1))
9797

examples/post_training_quantization/openvino/yolov8_quantize_with_accuracy_control/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def benchmark_performance(model_path, config) -> float:
117117
"-t", "30",
118118
"-shape", str([1, 3, config.imgsz, config.imgsz]),
119119
] # fmt: skip
120-
cmd_output = subprocess.check_output(command, text=True)
120+
cmd_output = subprocess.check_output(command, text=True) # nosec
121121
match = re.search(r"Throughput\: (.+?) FPS", cmd_output)
122122
return float(match.group(1))
123123

examples/post_training_quantization/tensorflow/mobilenet_v2/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def run_benchmark(model_path: Path, shape: List[int]) -> float:
4747
"-t", "15",
4848
"-shape", str(shape),
4949
] # fmt: skip
50-
cmd_output = subprocess.check_output(command, text=True)
50+
cmd_output = subprocess.check_output(command, text=True) # nosec
5151
print(*cmd_output.splitlines()[-8:], sep="\n")
5252
match = re.search(r"Throughput\: (.+?) FPS", cmd_output)
5353
return float(match.group(1))

examples/post_training_quantization/torch/mobilenet_v2/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def run_benchmark(model_path: Path, shape: List[int]) -> float:
7171
"-t", "15",
7272
"-shape", str(shape),
7373
] # fmt: skip
74-
cmd_output = subprocess.check_output(command, text=True)
74+
cmd_output = subprocess.check_output(command, text=True) # nosec
7575
print(*cmd_output.splitlines()[-8:], sep="\n")
7676
match = re.search(r"Throughput\: (.+?) FPS", cmd_output)
7777
return float(match.group(1))

examples/post_training_quantization/torch/ssd300_vgg16/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_model_size(ir_path: Path, m_type: str = "Mb") -> float:
5757

5858
def run_benchmark(model_path: Path) -> float:
5959
command = ["benchmark_app", "-m", model_path.as_posix(), "-d", "CPU", "-api", "async", "-t", "15"]
60-
cmd_output = subprocess.check_output(command, text=True)
60+
cmd_output = subprocess.check_output(command, text=True) # nosec
6161
print(*cmd_output.splitlines()[-8:], sep="\n")
6262
match = re.search(r"Throughput\: (.+?) FPS", cmd_output)
6363
return float(match.group(1))

examples/quantization_aware_training/torch/anomalib/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def run_benchmark(model_path: Path, shape: List[int]) -> float:
6969
"-t", "15",
7070
"-shape", str(shape),
7171
] # fmt: skip
72-
cmd_output = subprocess.check_output(command, text=True)
72+
cmd_output = subprocess.check_output(command, text=True) # nosec
7373
print(*cmd_output.splitlines()[-8:], sep="\n")
7474
match = re.search(r"Throughput\: (.+?) FPS", cmd_output)
7575
return float(match.group(1))

examples/quantization_aware_training/torch/resnet18/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def run_benchmark(model_path: Path, shape: Tuple[int, ...]) -> float:
217217
"-t", "15",
218218
"-shape", str(list(shape)),
219219
] # fmt: skip
220-
cmd_output = subprocess.check_output(command, text=True)
220+
cmd_output = subprocess.check_output(command, text=True) # nosec
221221
match = re.search(r"Throughput\: (.+?) FPS", cmd_output)
222222
return float(match.group(1))
223223

pyproject.toml

+7
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,10 @@ notice-rgx = """\
154154

155155
[tool.pytest.ini_options]
156156
pythonpath = "."
157+
158+
[tool.bandit]
159+
exclude_dirs = ["tools", "tests", "**/venv*", "build"]
160+
skips = [
161+
"B101", # assert_used
162+
"B404" , # import_subprocess
163+
]

0 commit comments

Comments
 (0)