Skip to content

Commit 2217a6a

Browse files
committed
run formatter
Signed-off-by: Kashish Mittal <kmittal@redhat.com>
1 parent c58f35e commit 2217a6a

8 files changed

Lines changed: 47 additions & 24 deletions

File tree

skills/rhdh-templates/scripts/analyze.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ def extract_from_package_json(path: Path, rel: str, candidates: dict[str, dict])
170170
except json.JSONDecodeError:
171171
return
172172
if isinstance(data.get("name"), str):
173-
_add_candidate(candidates, data["name"], category="name", source=rel, usually_parameterize="yes")
173+
_add_candidate(
174+
candidates, data["name"], category="name", source=rel, usually_parameterize="yes"
175+
)
174176
if isinstance(data.get("description"), str) and len(data["description"]) < 120:
175177
_add_candidate(
176178
candidates,
@@ -186,9 +188,13 @@ def extract_from_catalog_info(path: Path, rel: str, candidates: dict[str, dict])
186188
if not text:
187189
return
188190
for match in re.finditer(r"^\s*name:\s*['\"]?([\w.-]+)['\"]?\s*$", text, re.MULTILINE):
189-
_add_candidate(candidates, match.group(1), category="name", source=rel, usually_parameterize="yes")
191+
_add_candidate(
192+
candidates, match.group(1), category="name", source=rel, usually_parameterize="yes"
193+
)
190194
for match in re.finditer(r"^\s*owner:\s*['\"]?([\w:./-]+)['\"]?\s*$", text, re.MULTILINE):
191-
_add_candidate(candidates, match.group(1), category="owner", source=rel, usually_parameterize="yes")
195+
_add_candidate(
196+
candidates, match.group(1), category="owner", source=rel, usually_parameterize="yes"
197+
)
192198

193199

194200
def extract_from_pom(path: Path, rel: str, candidates: dict[str, dict]) -> None:
@@ -199,7 +205,9 @@ def extract_from_pom(path: Path, rel: str, candidates: dict[str, dict]) -> None:
199205
for match in re.finditer(rf"<{tag}>([^<]+)</{tag}>", text):
200206
cat = "name" if tag != "groupId" else "org"
201207
usually = "yes" if tag in {"artifactId", "name"} else "often"
202-
_add_candidate(candidates, match.group(1), category=cat, source=rel, usually_parameterize=usually)
208+
_add_candidate(
209+
candidates, match.group(1), category=cat, source=rel, usually_parameterize=usually
210+
)
203211

204212

205213
def extract_urls(text: str, rel: str, candidates: dict[str, dict]) -> None:
@@ -232,7 +240,13 @@ def scan_candidates(root: Path) -> list[dict]:
232240
continue
233241
extract_urls(text, rel, candidates)
234242
for match in K8S_NAME.finditer(text):
235-
_add_candidate(candidates, match.group(1), category="name", source=rel, usually_parameterize="often")
243+
_add_candidate(
244+
candidates,
245+
match.group(1),
246+
category="name",
247+
source=rel,
248+
usually_parameterize="often",
249+
)
236250
for match in K8S_NAMESPACE.finditer(text):
237251
_add_candidate(
238252
candidates,

skills/rhdh-templates/scripts/fix_gotchas.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ def apply_fixes(content: str, rules: list[dict]) -> str:
312312

313313
def main() -> int:
314314
parser = argparse.ArgumentParser(description="Check and fix RHDH template gotchas.")
315-
parser.add_argument("--path", required=True, type=Path, help="template.yaml or template directory")
315+
parser.add_argument(
316+
"--path", required=True, type=Path, help="template.yaml or template directory"
317+
)
316318
parser.add_argument("--apply", action="store_true", help="Apply automatic fixes")
317319
parser.add_argument("--json", action="store_true", help="Emit JSON result")
318320
args = parser.parse_args()

skills/rhdh-templates/scripts/init.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ def probe_rhdh(url: str, timeout: int = 10) -> dict:
6868
data = json.loads(body) if body else []
6969
count = len(data) if isinstance(data, list) else 0
7070
return {"reachable": True, "endpoint": endpoint, "action_count": count}
71-
except (urllib.error.URLError, urllib.error.HTTPError, json.JSONDecodeError, TimeoutError) as exc:
71+
except (
72+
urllib.error.URLError,
73+
urllib.error.HTTPError,
74+
json.JSONDecodeError,
75+
TimeoutError,
76+
) as exc:
7277
return {"reachable": False, "endpoint": endpoint, "error": str(exc)}
7378

7479

skills/rhdh-templates/scripts/list_actions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
def main() -> int:
3131
parser = argparse.ArgumentParser(description="List Scaffolder actions from RHDH.")
32-
parser.add_argument("--rhdh-url", required=True, help="RHDH base URL (e.g. https://rhdh.example.com)")
32+
parser.add_argument(
33+
"--rhdh-url", required=True, help="RHDH base URL (e.g. https://rhdh.example.com)"
34+
)
3335
parser.add_argument("--token", help="Bearer token (default: RHDH_TOKEN or BACKSTAGE_TOKEN env)")
3436
parser.add_argument("--filter", help="Case-insensitive substring filter on action id")
3537
parser.add_argument("--json", action="store_true", help="Emit JSON result")

skills/rhdh-templates/scripts/list_examples.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ def filter_examples(
8585
examples = [e for e in examples if tag in e.get("tags", [])]
8686
if stack:
8787
examples = [
88-
e
89-
for e in examples
90-
if stack in e.get("stack", []) or stack in e.get("tags", [])
88+
e for e in examples if stack in e.get("stack", []) or stack in e.get("tags", [])
9189
]
9290
if recommended:
9391
examples = [e for e in examples if e.get("recommended")]

skills/rhdh-templates/scripts/schema_validate.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
STEP_REF_BRACKET = re.compile(r"steps\[['\"]([^'\"]+)['\"]\]")
2222
STEP_REF_DOT = re.compile(r"steps\.([a-zA-Z0-9_-]+)\.output")
2323

24-
VALID_PARAM_TYPES = frozenset(
25-
{"string", "number", "integer", "boolean", "array", "object", "null"}
26-
)
24+
VALID_PARAM_TYPES = frozenset({"string", "number", "integer", "boolean", "array", "object", "null"})
2725
RESERVED_PARAM_KEYS = frozenset(
2826
{
2927
"properties",
@@ -262,9 +260,7 @@ def validate_parameter_forms(parameters: Any) -> list[dict]:
262260
for name, prop in props.items():
263261
if name in RESERVED_PARAM_KEYS:
264262
continue
265-
findings.extend(
266-
validate_parameter_property(name, prop, f"{base}.properties.{name}")
267-
)
263+
findings.extend(validate_parameter_property(name, prop, f"{base}.properties.{name}"))
268264

269265
return findings
270266

skills/rhdh-templates/scripts/validate.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,15 @@ def run_djlint(skeleton_dir: Path) -> list[dict]:
212212
return findings
213213

214214

215-
def validate_template(path: Path, *, check_repo: bool, lint_skeleton: bool, use_jsonschema: bool = True) -> dict:
215+
def validate_template(
216+
path: Path, *, check_repo: bool, lint_skeleton: bool, use_jsonschema: bool = True
217+
) -> dict:
216218
template_path = resolve_template_path(path)
217219
content = template_path.read_text(encoding="utf-8")
218220
template_dir = template_path.parent
219-
repo_root = template_dir.parent.parent if template_dir.parent.name == "templates" else template_dir
221+
repo_root = (
222+
template_dir.parent.parent if template_dir.parent.name == "templates" else template_dir
223+
)
220224

221225
findings: list[dict] = []
222226

@@ -278,7 +282,9 @@ def validate_template(path: Path, *, check_repo: bool, lint_skeleton: bool, use_
278282

279283
def main() -> int:
280284
parser = argparse.ArgumentParser(description="Validate RHDH Software Template locally.")
281-
parser.add_argument("--path", required=True, type=Path, help="template.yaml or template directory")
285+
parser.add_argument(
286+
"--path", required=True, type=Path, help="template.yaml or template directory"
287+
)
282288
parser.add_argument(
283289
"--repo",
284290
action="store_true",

tests/unit/test_rhdh_templates.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ def test_detects_nodejs_project(self, tmp_path: Path) -> None:
144144
)
145145
wf_dir = tmp_path / ".github" / "workflows"
146146
wf_dir.mkdir(parents=True)
147-
(wf_dir / "ci.yaml").write_text("jobs:\n build:\n steps:\n - run: echo ${{ github.ref }}\n")
147+
(wf_dir / "ci.yaml").write_text(
148+
"jobs:\n build:\n steps:\n - run: echo ${{ github.ref }}\n"
149+
)
148150

149151
result = run_script("analyze.py", "--path", str(tmp_path), "--json")
150152
assert result.returncode == 0
@@ -421,9 +423,7 @@ def test_repo_flag_checks_location(self, tmp_path: Path) -> None:
421423
template_dir = tmp_path / "templates" / "demo"
422424
template_dir.mkdir(parents=True)
423425
(template_dir / "template.yaml").write_text(
424-
(BUNDLED_EXAMPLES / "minimal-template" / "template.yaml").read_text(
425-
encoding="utf-8"
426-
),
426+
(BUNDLED_EXAMPLES / "minimal-template" / "template.yaml").read_text(encoding="utf-8"),
427427
encoding="utf-8",
428428
)
429429
result = run_script("validate.py", "--path", str(template_dir), "--repo", "--json")

0 commit comments

Comments
 (0)