Skip to content

Commit d007bd4

Browse files
SimonHeybrockclaude
andcommitted
Address PR review comments for nexus_helpers
- Move `import re` to module-level imports instead of inside functions - Update docstring to mention that generated dict includes topic info - Include 'topic' key in generated f144_log_streams dictionary entries - Update test assertions to match new output format with topic Addresses review comments from PR #589. Original prompt: Please use a new worktree to address comments in a #589. Commit and push, then cleanup worktree. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent bbd7a5c commit d007bd4

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/ess/livedata/nexus_helpers.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from __future__ import annotations
99

10+
import re
1011
from dataclasses import dataclass
1112
from pathlib import Path
1213

@@ -134,8 +135,6 @@ def suggest_internal_name(info: StreamInfo) -> str:
134135
if i > 0:
135136
name = parts[i - 1]
136137
# Remove common suffixes like '_r0', '_01' etc.
137-
import re
138-
139138
name = re.sub(r'_[rt]\d+$', '', name)
140139
return name
141140
# Fallback: use last non-value component
@@ -159,8 +158,6 @@ def filter_f144_streams(
159158
exclude_patterns:
160159
List of regex patterns to exclude from results (matched against group_path).
161160
"""
162-
import re
163-
164161
exclude_patterns = exclude_patterns or []
165162
exclude_regexes = [re.compile(p) for p in exclude_patterns]
166163

@@ -184,7 +181,7 @@ def generate_f144_log_streams_code(
184181
) -> str:
185182
"""Generate Python code for f144_log_streams dictionary.
186183
187-
The generated dictionary maps internal names to source and units info,
184+
The generated dictionary maps internal names to source, units, and topic info,
188185
which can be used to derive both f144_attribute_registry and StreamLUT.
189186
190187
Parameters
@@ -215,9 +212,11 @@ def generate_f144_log_streams_code(
215212
for name in sorted(by_name.keys()):
216213
info = by_name[name]
217214
units = info.units or 'dimensionless'
218-
lines.append(
219-
f" '{name}': {{'source': '{info.source}', 'units': '{units}'}},"
215+
entry = (
216+
f" '{name}': {{'source': '{info.source}', 'units': '{units}', "
217+
f"'topic': '{topic}'}}"
220218
)
219+
lines.append(f"{entry},")
221220

222221
lines.append("}")
223222
return '\n'.join(lines)

tests/nexus_helpers_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,10 @@ def test_generates_valid_python_dict(self) -> None:
510510
]
511511
code = generate_f144_log_streams_code(infos, topic='motion')
512512
assert "f144_log_streams: dict[str, dict[str, str]] = {" in code
513-
assert "'motor': {'source': 'MOTOR:PV:RBV', 'units': 'degrees'}" in code
513+
assert (
514+
"'motor': {'source': 'MOTOR:PV:RBV', 'units': 'degrees', 'topic': 'motion'}"
515+
in code
516+
)
514517

515518
def test_uses_dimensionless_for_empty_units(self) -> None:
516519
infos = [
@@ -525,7 +528,7 @@ def test_uses_dimensionless_for_empty_units(self) -> None:
525528
),
526529
]
527530
code = generate_f144_log_streams_code(infos, topic='motion')
528-
assert "'units': 'dimensionless'" in code
531+
assert "'units': 'dimensionless', 'topic': 'motion'" in code
529532

530533
def test_prefers_value_over_idle_flag(self) -> None:
531534
infos = [

0 commit comments

Comments
 (0)