Skip to content

Commit d08fcbb

Browse files
committed
style: pre-commit
1 parent aaea820 commit d08fcbb

File tree

1 file changed

+56
-35
lines changed

1 file changed

+56
-35
lines changed

scripts/systems_reference.py

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ def parse_system_header(self, header_file: Path):
365365
self._parse_quantities(content, system, str(header_file))
366366
# Detect inline subnamespaces early so other parsers can use this information
367367
self._detect_inline_subnamespaces(content, system)
368-
self._parse_constants(content, system, str(header_file)) # Parse constants before units so using declarations can find them
368+
self._parse_constants(
369+
content, system, str(header_file)
370+
) # Parse constants before units so using declarations can find them
369371
self._parse_units(content, system, str(header_file))
370372
self._parse_point_origins(content, system, str(header_file))
371373
self._parse_prefixes(content, system, str(header_file))
@@ -494,10 +496,14 @@ def _detect_origin_namespace(
494496
return None
495497

496498
def _get_nested_namespace(
497-
self, content: str, match_pos: int, system_namespace: str, include_inline: bool = False
499+
self,
500+
content: str,
501+
match_pos: int,
502+
system_namespace: str,
503+
include_inline: bool = False,
498504
) -> Optional[str]:
499505
"""Detect if a match is inside a nested namespace and return the nested namespace name
500-
506+
501507
Args:
502508
content: The content to search
503509
match_pos: Position of the match
@@ -1004,7 +1010,7 @@ def _parse_units(
10041010
)
10051011
system.constants.append(alias_constant)
10061012
break
1007-
1013+
10081014
if not is_constant:
10091015
# Create a unit alias
10101016
unit = Unit(
@@ -1170,11 +1176,13 @@ def _parse_prefixes(self, content: str, system: SystemInfo, file: str):
11701176

11711177
def _parse_constants(self, content: str, system: SystemInfo, file: str):
11721178
"""Parse named_constant definitions"""
1173-
# Pattern 1: (inline constexpr)? struct NAME final : named_constant<symbol_text{u8"unicode", "ascii"}, ...> {} NAME;
1179+
# Pattern 1: (inline constexpr)? struct NAME final :
1180+
# named_constant<symbol_text{u8"unicode", "ascii"}, ...> {} NAME;
11741181
constant_pattern_text = (
11751182
r"(?:inline\s+constexpr\s+)?struct\s+(\w+)\s+final\s*:\s*"
1176-
r'named_constant<symbol_text\{u8"([^"]+)"(?:\s*/\*[^*]*\*/)?\s*,\s*'
1177-
r'"([^"]+)"\},\s*(.+?)>\s*\{\}\s*(\w+)\s*;'
1183+
r'named_constant<symbol_text\{u8"([^"]+)"'
1184+
r'(?:\s*/\*[^*]*\*/)?\s*,\s*"([^"]+)"\},\s*(.+?)>\s*\{\}\s*'
1185+
r"(\w+)\s*;"
11781186
)
11791187

11801188
# Pattern 2: (inline constexpr)? struct NAME final : named_constant<"symbol", ...> {} NAME;
@@ -1199,14 +1207,15 @@ def _parse_constants(self, content: str, system: SystemInfo, file: str):
11991207
# Detect nested namespace (including inline namespaces for proper documentation)
12001208
match_pos = match.start()
12011209
nested_ns = self._get_nested_namespace(
1202-
content, match_pos, system.namespace if system.namespace else "", include_inline=True
1210+
content,
1211+
match_pos,
1212+
system.namespace if system.namespace else "",
1213+
include_inline=True,
12031214
)
12041215
full_namespace = (
12051216
f"mp_units::{system.namespace}::{nested_ns}"
12061217
if nested_ns and system.namespace
1207-
else f"mp_units::{system.namespace}"
1208-
if system.namespace
1209-
else "mp_units"
1218+
else f"mp_units::{system.namespace}" if system.namespace else "mp_units"
12101219
)
12111220

12121221
constant = Constant(
@@ -1230,14 +1239,15 @@ def _parse_constants(self, content: str, system: SystemInfo, file: str):
12301239
# Detect nested namespace (including inline namespaces for proper documentation)
12311240
match_pos = match.start()
12321241
nested_ns = self._get_nested_namespace(
1233-
content, match_pos, system.namespace if system.namespace else "", include_inline=True
1242+
content,
1243+
match_pos,
1244+
system.namespace if system.namespace else "",
1245+
include_inline=True,
12341246
)
12351247
full_namespace = (
12361248
f"mp_units::{system.namespace}::{nested_ns}"
12371249
if nested_ns and system.namespace
1238-
else f"mp_units::{system.namespace}"
1239-
if system.namespace
1240-
else "mp_units"
1250+
else f"mp_units::{system.namespace}" if system.namespace else "mp_units"
12411251
)
12421252

12431253
constant = Constant(
@@ -1313,7 +1323,7 @@ def _parse_aliases(self, content: str, system: SystemInfo, file: str):
13131323
# Handle core system where namespace is just "mp_units"
13141324
if target_system_name == "mp_units":
13151325
target_system_name = ""
1316-
1326+
13171327
if target_system_name == system.namespace:
13181328
alias_target_display = target_origin.name
13191329
else:
@@ -1358,7 +1368,7 @@ def _parse_aliases(self, content: str, system: SystemInfo, file: str):
13581368
# Handle core system where namespace is just "mp_units"
13591369
if target_system_name == "mp_units":
13601370
target_system_name = ""
1361-
1371+
13621372
if target_system_name == system.namespace:
13631373
alias_target_display = target_quantity.name
13641374
else:
@@ -1405,7 +1415,7 @@ def _parse_aliases(self, content: str, system: SystemInfo, file: str):
14051415
# Handle core system where namespace is just "mp_units"
14061416
if target_system_name == "mp_units":
14071417
target_system_name = ""
1408-
1418+
14091419
if target_system_name == system.namespace:
14101420
alias_target_display = target_constant.name
14111421
else:
@@ -1448,7 +1458,7 @@ def _parse_aliases(self, content: str, system: SystemInfo, file: str):
14481458
# Handle core system where namespace is just "mp_units"
14491459
if target_system_name == "mp_units":
14501460
target_system_name = ""
1451-
1461+
14521462
if target_system_name == system.namespace:
14531463
alias_target_display = target_unit.name
14541464
else:
@@ -1510,7 +1520,10 @@ def _parse_unit_symbols(self, content: str, system: SystemInfo):
15101520
for constant in system.constants:
15111521
if constant.name == entity_name:
15121522
# Only match if this constant is in an inline subnamespace or has no subnamespace
1513-
if not constant.subnamespace or constant.subnamespace in system.inline_subnamespaces:
1523+
if (
1524+
not constant.subnamespace
1525+
or constant.subnamespace in system.inline_subnamespaces
1526+
):
15141527
if symbol_name not in constant.unit_symbols:
15151528
constant.unit_symbols.append(symbol_name)
15161529
break # Only match the first eligible constant
@@ -2389,11 +2402,15 @@ def generate_constants_index(self):
23892402
# For inline namespaces, only show the qualified version (not the parent namespace access)
23902403
if constant.subnamespace:
23912404
if system.namespace:
2392-
display_namespace = f"{system.namespace}::{constant.subnamespace}"
2405+
display_namespace = (
2406+
f"{system.namespace}::{constant.subnamespace}"
2407+
)
23932408
else:
23942409
display_namespace = f"mp_units::{constant.subnamespace}"
23952410
else:
2396-
display_namespace = system.namespace if system.namespace else "mp_units"
2411+
display_namespace = (
2412+
system.namespace if system.namespace else "mp_units"
2413+
)
23972414

23982415
all_constants.append(
23992416
(constant.name, sys_key, display_namespace, constant)
@@ -2410,13 +2427,9 @@ def generate_constants_index(self):
24102427
):
24112428
# Determine anchor - include subnamespace prefix if present
24122429
anchor = (
2413-
f"{constant.subnamespace}-{name}"
2414-
if constant.subnamespace
2415-
else name
2416-
)
2417-
f.write(
2418-
f"- [`{name}` ({display_ns})](systems/{sys_key}.md#{anchor})\n"
2430+
f"{constant.subnamespace}-{name}" if constant.subnamespace else name
24192431
)
2432+
f.write(f"- [`{name}` ({display_ns})](systems/{sys_key}.md#{anchor})\n")
24202433

24212434
f.write(f"\n**Total constants:** {len(all_constants)}\n")
24222435

@@ -2834,10 +2847,14 @@ def get_constant_display_name(constant):
28342847
return f"{constant.subnamespace}::{constant.name}"
28352848
return constant.name
28362849

2837-
for constant in sorted(system.constants, key=get_constant_display_name):
2850+
for constant in sorted(
2851+
system.constants, key=get_constant_display_name
2852+
):
28382853
# Determine display name with subnamespace prefix if present
28392854
if constant.subnamespace:
2840-
constant_display = f"{constant.subnamespace}::{constant.name}"
2855+
constant_display = (
2856+
f"{constant.subnamespace}::{constant.name}"
2857+
)
28412858
anchor_id = f"{constant.subnamespace}-{constant.name}"
28422859
else:
28432860
constant_display = constant.name
@@ -2851,7 +2868,8 @@ def get_constant_display_name(constant):
28512868
constant.alias_target, system
28522869
)
28532870
f.write(
2854-
f'| <span id="{anchor_id}"></span><code>{constant_display_with_breaks}</code> | — | — | '
2871+
f'| <span id="{anchor_id}"></span><code>'
2872+
f"{constant_display_with_breaks}</code> | — | — | "
28552873
f"alias to {alias_target_linked} |\n"
28562874
)
28572875
else:
@@ -2875,7 +2893,7 @@ def get_constant_display_name(constant):
28752893

28762894
# Collect inline subnamespaces used by both units and constants
28772895
inline_subns_used = set()
2878-
2896+
28792897
# Check units for inline namespaces
28802898
for unit in regular_units:
28812899
if unit.origin_namespace:
@@ -2886,12 +2904,15 @@ def get_constant_display_name(constant):
28862904
subns = parts[-1]
28872905
if subns in system.inline_subnamespaces:
28882906
inline_subns_used.add(subns)
2889-
2907+
28902908
# Check constants for inline namespaces
28912909
for constant in system.constants:
2892-
if constant.subnamespace and constant.subnamespace in system.inline_subnamespaces:
2910+
if (
2911+
constant.subnamespace
2912+
and constant.subnamespace in system.inline_subnamespaces
2913+
):
28932914
inline_subns_used.add(constant.subnamespace)
2894-
2915+
28952916
# Write admonition if any inline namespaces are used
28962917
if inline_subns_used:
28972918
f.write("\n")

0 commit comments

Comments
 (0)