fix: address self-review findings
This commit is contained in:
@@ -218,7 +218,7 @@ def normalize_tabler(raw: str) -> str:
|
||||
body = re.sub(r'<path\s+stroke="none"[^/]*?/>', "", body)
|
||||
body = re.sub(r"\s+", " ", body).strip()
|
||||
return (
|
||||
'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" '
|
||||
'<svg aria-hidden="true" width="24" height="24" viewBox="0 0 24 24" fill="none" '
|
||||
'stroke="currentColor" stroke-width="1.5" stroke-linecap="round" '
|
||||
f'stroke-linejoin="round">{body}</svg>'
|
||||
)
|
||||
@@ -232,7 +232,7 @@ def normalize_simple(raw: str) -> str:
|
||||
body = inner.group(1).strip()
|
||||
body = re.sub(r"\s+", " ", body).strip()
|
||||
return (
|
||||
'<svg width="24" height="24" viewBox="0 0 24 24" '
|
||||
'<svg aria-hidden="true" width="24" height="24" viewBox="0 0 24 24" '
|
||||
f'fill="currentColor">{body}</svg>'
|
||||
)
|
||||
|
||||
@@ -284,7 +284,7 @@ def normalize_url(raw: str) -> str:
|
||||
body = re.sub(r'\bfill="none"', '', body)
|
||||
body = re.sub(r"\s+", " ", body).strip()
|
||||
return (
|
||||
f'<svg width="24" height="24" viewBox="{viewbox}" '
|
||||
f'<svg aria-hidden="true" width="24" height="24" viewBox="{viewbox}" '
|
||||
f'fill="currentColor">{body}</svg>'
|
||||
)
|
||||
|
||||
@@ -303,7 +303,7 @@ def normalize_devicon(raw: str) -> str:
|
||||
body = re.sub(r'\bclass="[^"]*"', 'fill="currentColor"', body)
|
||||
body = re.sub(r"\s+", " ", body).strip()
|
||||
return (
|
||||
'<svg width="24" height="24" viewBox="0 0 128 128" '
|
||||
'<svg aria-hidden="true" width="24" height="24" viewBox="0 0 128 128" '
|
||||
f'fill="currentColor">{body}</svg>'
|
||||
)
|
||||
|
||||
@@ -320,7 +320,7 @@ def normalize_logz(raw: str) -> str:
|
||||
body = re.sub(r'\bfill="#[0-9a-fA-F]{3,8}"', 'fill="currentColor"', body)
|
||||
body = re.sub(r"\s+", " ", body).strip()
|
||||
return (
|
||||
'<svg width="24" height="24" viewBox="0 0 100 100" '
|
||||
'<svg aria-hidden="true" width="24" height="24" viewBox="0 0 100 100" '
|
||||
f'fill="currentColor">{body}</svg>'
|
||||
)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -12,6 +13,7 @@ from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
LINTER = ROOT / "scripts/lint-skin.py"
|
||||
BUILD_ICONS = ROOT / "scripts/build-icons.py"
|
||||
|
||||
VALID_SVG = """\
|
||||
<svg xmlns="http://www.w3.org/2000/svg" role="img"
|
||||
@@ -139,6 +141,32 @@ def main() -> int:
|
||||
directory,
|
||||
)
|
||||
|
||||
spec = importlib.util.spec_from_file_location("build_icons", BUILD_ICONS)
|
||||
if spec is None or spec.loader is None:
|
||||
raise AssertionError("generated-icons: could not load build-icons.py")
|
||||
build_icons = importlib.util.module_from_spec(spec)
|
||||
previous_bytecode_setting = sys.dont_write_bytecode
|
||||
sys.dont_write_bytecode = True
|
||||
try:
|
||||
spec.loader.exec_module(build_icons)
|
||||
finally:
|
||||
sys.dont_write_bytecode = previous_bytecode_setting
|
||||
generated_icons = {
|
||||
"tabler": build_icons.normalize_tabler("<svg><path/></svg>"),
|
||||
"simple": build_icons.normalize_simple("<svg><path/></svg>"),
|
||||
"url": build_icons.normalize_url(
|
||||
'<svg viewBox="0 0 24 24"><path/></svg>'
|
||||
),
|
||||
"devicon": build_icons.normalize_devicon("<svg><path/></svg>"),
|
||||
"logz": build_icons.normalize_logz("<svg><path/></svg>"),
|
||||
}
|
||||
for source, icon in generated_icons.items():
|
||||
require_pass(
|
||||
f"generated-{source}-icon",
|
||||
VALID_SVG.replace("</svg>", f" {icon}\n</svg>"),
|
||||
directory,
|
||||
)
|
||||
|
||||
project = directory / "baseline-project"
|
||||
(project / "scripts").mkdir(parents=True)
|
||||
(project / "skills/diagram-design/assets").mkdir(parents=True)
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user