Skip to content

Commit 6bc5a23

Browse files
committed
adding formatting
1 parent c06c9a9 commit 6bc5a23

3 files changed

Lines changed: 41 additions & 61 deletions

File tree

scripts/workflow/checkout_repos.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def load_repos_config(config_file="./repos.json"):
4040
sys.exit(1)
4141

4242
try:
43-
with open(config_path, 'r') as f:
43+
with open(config_path, "r") as f:
4444
repos = json.load(f)
4545
return repos
4646
except (json.JSONDecodeError, IOError) as e:
@@ -58,7 +58,7 @@ def is_commit_hash(ref):
5858
Returns:
5959
True if ref matches commit hash pattern
6060
"""
61-
return bool(re.match(r'^[0-9a-fA-F]{40}$', ref))
61+
return bool(re.match(r"^[0-9a-fA-F]{40}$", ref))
6262

6363

6464
def checkout_repo(name, url, ref, path):
@@ -85,29 +85,19 @@ def checkout_repo(name, url, ref, path):
8585
print(f" Detected commit hash. Cloning and then checking out.")
8686

8787
# Clone the repository
88-
subprocess.run(
89-
["git", "clone", url, path],
90-
check=True,
91-
capture_output=True
92-
)
88+
subprocess.run(["git", "clone", url, path], check=True, capture_output=True)
9389

9490
# Checkout specific commit
95-
subprocess.run(
96-
["git", "-C", path, "checkout", ref],
97-
check=True,
98-
capture_output=True
99-
)
91+
subprocess.run(["git", "-C", path, "checkout", ref], check=True, capture_output=True)
10092
else:
10193
print(f"Checking out {name} ({ref}) to {path}")
10294
print(f" Detected branch/tag. Cloning with --branch.")
10395

10496
# Clone with shallow copy and specific branch/tag
10597
# Add 'v' prefix if not already present (common convention)
106-
branch_ref = ref if ref.startswith('v') else f'v{ref}'
98+
branch_ref = ref if ref.startswith("v") else f"v{ref}"
10799
subprocess.run(
108-
["git", "clone", "--depth", "1", "--branch", branch_ref, url, path],
109-
check=True,
110-
capture_output=True
100+
["git", "clone", "--depth", "1", "--branch", branch_ref, url, path], check=True, capture_output=True
111101
)
112102

113103
return True
@@ -120,18 +110,18 @@ def checkout_repo(name, url, ref, path):
120110
def main():
121111
"""Main entry point."""
122112
# Load repository configurations
123-
repos = load_repos_config('./repos.json')
113+
repos = load_repos_config("./repos.json")
124114
repo_count = len(repos)
125115

126116
# Track successfully checked out repositories
127117
repo_paths = []
128118

129119
# Checkout each repository
130120
for i, repo in enumerate(repos):
131-
name = repo.get('name', f'repo-{i}')
132-
url = repo.get('url', '')
133-
ref = repo.get('version', '')
134-
path = repo.get('path', '')
121+
name = repo.get("name", f"repo-{i}")
122+
url = repo.get("url", "")
123+
ref = repo.get("version", "")
124+
path = repo.get("path", "")
135125

136126
if not all([url, ref, path]):
137127
print(f"Warning: Skipping {name} - missing required fields", file=sys.stderr)
@@ -141,13 +131,13 @@ def main():
141131
repo_paths.append(path)
142132

143133
# Output all paths (comma-separated for GitHub Actions compatibility)
144-
repo_paths_output = ','.join(repo_paths)
134+
repo_paths_output = ",".join(repo_paths)
145135

146136
# Write to GITHUB_OUTPUT if available
147-
github_output = os.environ.get('GITHUB_OUTPUT')
137+
github_output = os.environ.get("GITHUB_OUTPUT")
148138
if github_output:
149139
try:
150-
with open(github_output, 'a') as f:
140+
with open(github_output, "a") as f:
151141
f.write(f"repo_paths={repo_paths_output}\n")
152142
except IOError as e:
153143
print(f"Warning: Failed to write GITHUB_OUTPUT: {e}", file=sys.stderr)
@@ -159,5 +149,5 @@ def main():
159149
return 0 if len(repo_paths) == repo_count else 1
160150

161151

162-
if __name__ == '__main__':
152+
if __name__ == "__main__":
163153
sys.exit(main())

scripts/workflow/parse_repos.py

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717

1818
import json
19+
import os
1920
import sys
2021
import subprocess
2122
from pathlib import Path
@@ -24,16 +25,8 @@
2425
def install_dependencies():
2526
"""Ensure jq is installed (for reference, though we use Python's json)."""
2627
try:
27-
subprocess.run(
28-
["sudo", "apt-get", "update"],
29-
check=True,
30-
capture_output=True
31-
)
32-
subprocess.run(
33-
["sudo", "apt-get", "install", "-y", "jq"],
34-
check=True,
35-
capture_output=True
36-
)
28+
subprocess.run(["sudo", "apt-get", "update"], check=True, capture_output=True)
29+
subprocess.run(["sudo", "apt-get", "install", "-y", "jq"], check=True, capture_output=True)
3730
except subprocess.CalledProcessError as e:
3831
print(f"Warning: Failed to install jq: {e}", file=sys.stderr)
3932

@@ -56,44 +49,39 @@ def parse_known_good(json_file="./known_good.json"):
5649
sys.exit(1)
5750

5851
try:
59-
with open(json_path, 'r') as f:
52+
with open(json_path, "r") as f:
6053
data = json.load(f)
6154
except json.JSONDecodeError as e:
6255
print(f"Error: Failed to parse JSON: {e}", file=sys.stderr)
6356
sys.exit(1)
6457

6558
# Extract target_sw modules
66-
modules = data.get('modules', {}).get('target_sw', {})
59+
modules = data.get("modules", {}).get("target_sw", {})
6760

6861
# Transform modules into repository objects
6962
repos = []
7063
module_outputs = {}
7164

7265
for name, config in modules.items():
73-
repo_url = config.get('repo', '')
74-
version = config.get('version', '')
75-
branch = config.get('branch', '')
76-
hash_val = config.get('hash', '')
66+
repo_url = config.get("repo", "")
67+
version = config.get("version", "")
68+
branch = config.get("branch", "")
69+
hash_val = config.get("hash", "")
7770

7871
# Use version, branch, or hash (in that order of preference)
7972
ref = version or branch or hash_val
8073

81-
repo_obj = {
82-
'name': name,
83-
'url': repo_url,
84-
'version': ref,
85-
'path': f'repos/{name}'
86-
}
74+
repo_obj = {"name": name, "url": repo_url, "version": ref, "path": f"repos/{name}"}
8775
repos.append(repo_obj)
8876

8977
# Store module outputs for GITHUB_OUTPUT compatibility
90-
module_outputs[f'{name}_url'] = repo_url
78+
module_outputs[f"{name}_url"] = repo_url
9179
if version:
92-
module_outputs[f'{name}_version'] = version
80+
module_outputs[f"{name}_version"] = version
9381
if branch:
94-
module_outputs[f'{name}_branch'] = branch
82+
module_outputs[f"{name}_branch"] = branch
9583
if hash_val:
96-
module_outputs[f'{name}_hash'] = hash_val
84+
module_outputs[f"{name}_hash"] = hash_val
9785

9886
return repos, len(modules), module_outputs
9987

@@ -103,7 +91,7 @@ def write_repos_json(repos, output_file="./repos.json"):
10391
output_path = Path(output_file)
10492

10593
try:
106-
with open(output_path, 'w') as f:
94+
with open(output_path, "w") as f:
10795
json.dump(repos, f, indent=2)
10896
print(f"Generated {output_file}:")
10997
print(json.dumps(repos, indent=2))
@@ -120,11 +108,11 @@ def write_github_output(outputs):
120108
Args:
121109
outputs: Dictionary of key-value pairs to output
122110
"""
123-
github_output = Path(os.environ.get('GITHUB_OUTPUT', '/dev/null'))
111+
github_output = Path(os.environ.get("GITHUB_OUTPUT", "/dev/null"))
124112

125113
if github_output.exists() or github_output.parent.exists():
126114
try:
127-
with open(github_output, 'a') as f:
115+
with open(github_output, "a") as f:
128116
for key, value in outputs.items():
129117
f.write(f"{key}={value}\n")
130118
except IOError as e:
@@ -139,18 +127,18 @@ def main():
139127
# install_dependencies()
140128

141129
# Parse known_good.json
142-
repos, module_count, module_outputs = parse_known_good('./known_good.json')
130+
repos, module_count, module_outputs = parse_known_good("./known_good.json")
143131

144132
# Write repos.json
145133
write_repos_json(repos)
146134

147135
# Write GitHub Actions outputs
148-
github_outputs = {'MODULE_COUNT': str(module_count)}
136+
github_outputs = {"MODULE_COUNT": str(module_count)}
149137
github_outputs.update(module_outputs)
150138
write_github_output(github_outputs)
151139

152140
print("Parse complete!")
153141

154142

155-
if __name__ == '__main__':
143+
if __name__ == "__main__":
156144
main()

scripts/workflow/recategorize_guidelines.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ def recategorize_sarif():
6868
[
6969
"python3",
7070
RECATEGORIZE_SCRIPT,
71-
"--coding-standards-schema-file", CODING_STANDARDS_SCHEMA,
72-
"--sarif-schema-file", SARIF_SCHEMA,
71+
"--coding-standards-schema-file",
72+
CODING_STANDARDS_SCHEMA,
73+
"--sarif-schema-file",
74+
SARIF_SCHEMA,
7375
CODING_STANDARDS_CONFIG,
7476
SARIF_FILE,
7577
str(output_file),
7678
],
7779
check=True,
7880
capture_output=True,
79-
text=True
81+
text=True,
8082
)
8183

8284
print("Recategorization completed successfully")
@@ -120,5 +122,5 @@ def main():
120122
sys.exit(0)
121123

122124

123-
if __name__ == '__main__':
125+
if __name__ == "__main__":
124126
main()

0 commit comments

Comments
 (0)