Skip to content

Commit 89fb649

Browse files
committed
[ci] Run black
Run black code formatter using GH actions to ensure style consistency in our Python files. Run it on main and in every PR. Run black to fix the current issues in `vbox-adapter-check.py` and `vbox-clean-snapshots.py`.
1 parent c1cb8b4 commit 89fb649

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

.github/workflows/linter.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Linter
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
lint:
11+
runs-on: windows-2022
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
15+
- name: Install black
16+
run: pip install black
17+
- name: Run black
18+
run: black --line-length=120 --check --diff .

virtualbox/vbox-adapter-check.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ def get_vm_uuids(dynamic_only):
5151
return vm_uuids
5252

5353

54-
def change_network_adapters_to_hostonly(
55-
vm_uuid, vm_name, hostonly_ifname, do_not_modify
56-
):
54+
def change_network_adapters_to_hostonly(vm_uuid, vm_name, hostonly_ifname, do_not_modify):
5755
"""Verify all adapters are in an allowed configuration. Must be poweredoff"""
5856
try:
5957
# gather adapters in incorrect configurations
@@ -72,9 +70,7 @@ def change_network_adapters_to_hostonly(
7270
# nic8="none"
7371

7472
vminfo = run_vboxmanage(["showvminfo", vm_uuid, "--machinereadable"])
75-
for nic_number, nic_value in re.findall(
76-
'^nic(\d+)="(\S+)"', vminfo, flags=re.M
77-
):
73+
for nic_number, nic_value in re.findall('^nic(\d+)="(\S+)"', vminfo, flags=re.M):
7874
if nic_value not in ALLOWED_ADAPTER_TYPES:
7975
nics_with_internet.append(f"nic{nic_number}")
8076
invalid_nics_msg += f"{nic_number} "
@@ -115,9 +111,7 @@ def change_network_adapters_to_hostonly(
115111

116112
# Show notification using PyGObject
117113
Notify.init("VirtualBox adapter check")
118-
notification = Notify.Notification.new(
119-
f"INTERNET IN VM: {vm_name}", message, "dialog-error"
120-
)
114+
notification = Notify.Notification.new(f"INTERNET IN VM: {vm_name}", message, "dialog-error")
121115
# Set highest priority
122116
notification.set_urgency(2)
123117
notification.show()
@@ -167,9 +161,7 @@ def main(argv=None):
167161
vm_uuids = get_vm_uuids(args.dynamic_only)
168162
if len(vm_uuids) > 0:
169163
for vm_name, vm_uuid in vm_uuids:
170-
change_network_adapters_to_hostonly(
171-
vm_uuid, vm_name, hostonly_ifname, args.do_not_modify
172-
)
164+
change_network_adapters_to_hostonly(vm_uuid, vm_name, hostonly_ifname, args.do_not_modify)
173165
else:
174166
print(f"[Warning ⚠️] No VMs found")
175167
except Exception as e:

virtualbox/vbox-clean-snapshots.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def is_protected(protected_snapshots, snapshot_name):
2626
"""Check if snapshot_name contains any of the strings in the protected_snapshots list (case insensitive)"""
2727
return any(p.lower() in snapshot_name.lower() for p in protected_snapshots)
2828

29+
2930
def get_snapshot_children(vm_name, root_snapshot_name, protected_snapshots):
3031
"""Get the children of a snapshot (including the snapshot) using 'VBoxManage snapshot' with the 'list' option.
3132
@@ -149,9 +150,7 @@ def main(argv=None):
149150
)
150151
args = parser.parse_args(args=argv)
151152

152-
delete_snapshot_and_children(
153-
args.vm_name, args.root_snapshot, args.protected_snapshots
154-
)
153+
delete_snapshot_and_children(args.vm_name, args.root_snapshot, args.protected_snapshots)
155154

156155

157156
if __name__ == "__main__":

0 commit comments

Comments
 (0)