Skip to content

Commit e817685

Browse files
ci: 🤖 format with pre-commit
1 parent fdce829 commit e817685

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/ccbr_tools/module_list.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@
6464
"""
6565

6666

67-
6867
import sys
6968
import re
7069
import subprocess
7170
import json
7271

72+
7373
def get_loaded_modules():
7474
try:
7575
# Execute 'module list' within a shell and capture stderr
@@ -78,7 +78,7 @@ def get_loaded_modules():
7878
shell=True,
7979
stdout=subprocess.PIPE,
8080
stderr=subprocess.PIPE,
81-
text=True
81+
text=True,
8282
)
8383
# 'module list' outputs to stderr
8484
output = result.stderr
@@ -87,20 +87,22 @@ def get_loaded_modules():
8787
print(f"Error executing 'module list': {e}")
8888
return ""
8989

90+
9091
def parse_modules(output):
9192
modules = {}
9293
# Regular expression to match module entries like '1) module_name/version'
93-
pattern = re.compile(r'\d+\)\s+([\w\-/\.]+)')
94+
pattern = re.compile(r"\d+\)\s+([\w\-/\.]+)")
9495
matches = pattern.findall(output)
9596
for module_info in matches:
9697
# Split module name and version
97-
if '/' in module_info:
98-
name, version = module_info.rsplit('/', 1)
98+
if "/" in module_info:
99+
name, version = module_info.rsplit("/", 1)
99100
else:
100101
name, version = module_info, ""
101102
modules[name] = version
102103
return modules
103104

105+
104106
def print_help():
105107
help_message = """
106108
Usage:
@@ -110,14 +112,17 @@ def print_help():
110112
"""
111113
print(help_message.strip())
112114

115+
113116
def main():
114117
args = sys.argv[1:]
115118

116119
if len(args) == 0:
117120
# No arguments provided; print all loaded modules in JSON format
118121
output = get_loaded_modules()
119122
modules = parse_modules(output)
120-
module_list = [{'name': name, 'version': version} for name, version in modules.items()]
123+
module_list = [
124+
{"name": name, "version": version} for name, version in modules.items()
125+
]
121126
print(json.dumps(module_list, indent=4))
122127
elif len(args) == 1:
123128
if args[0] in ("-h", "--help"):
@@ -139,5 +144,6 @@ def main():
139144
print_help()
140145
sys.exit(1)
141146

147+
142148
if __name__ == "__main__":
143149
main()

0 commit comments

Comments
 (0)