mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
Some checks failed
CI and Release / Docker / Build and test / amd64 (push) Has been cancelled
CI and Release / Docker / Build and test / arm64 (push) Has been cancelled
Security / CodeQL / Analyze python (push) Has been cancelled
CI / Python quality / Pre-commit (push) Has been cancelled
CI / Python tests / Unit Tests - py3.12 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.13 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.14 (push) Has been cancelled
CI / Python packages / Build and verify distributions (push) Has been cancelled
CI / Python quality / GitHub Actions (push) Has been cancelled
CI / Python tests / Hermes embedded - ubuntu-latest (push) Has been cancelled
CI / Python tests / Hermes embedded - windows-latest (push) Has been cancelled
CI / Python tests / Unit Tests - py3.11 (push) Has been cancelled
CI / ReMe Studio / Studio checks (push) Has been cancelled
Deploy / Documentation / Build documentation (push) Has been cancelled
CI / Windows / CLI smoke - py3.11 (push) Has been cancelled
Security / CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI and Release / Docker / Publish multi-platform tags (push) Has been cancelled
Deploy / Documentation / deploy (push) Has been cancelled
* refactor(core): reorganize the ReMe runtime and shared helpers * test(status): import the base component from its canonical module * test: remove redundant unit checks * refactor(core): use canonical runtime imports and shared CLI discovery Restore evolve behavior to the base branch and update its imports. Use Application as the runtime entry point and encode SSE in the HTTP service. * fix(cli): honor caller config when service replay is incomplete Use partial startup overrides for port probes and resolve named configs before requesting the service process working directory.
43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
"""Parse and format GitHub-style 1-based line-anchor strings."""
|
|
|
|
import re
|
|
|
|
_LINE_ANCHOR_RE = re.compile(r"L[0-9]+(?:-L[0-9]+)?(?:,L[0-9]+(?:-L[0-9]+)?)*")
|
|
|
|
|
|
def parse_line_anchor(anchor: str | None) -> list[tuple[int, int]] | None:
|
|
"""Return normalized inclusive ranges, or ``None`` for a non-line anchor.
|
|
|
|
Supported forms are ``L9``, ``L9-L10`` and
|
|
``L9-L10,L15-L20``. Overlapping and adjacent ranges are merged.
|
|
Anchors beginning with ``L<digit>`` are treated as line anchors and raise
|
|
``ValueError`` when malformed, zero-based, or reversed.
|
|
"""
|
|
if not anchor or not re.match(r"L[0-9]", anchor):
|
|
return None
|
|
if not _LINE_ANCHOR_RE.fullmatch(anchor):
|
|
raise ValueError(f"invalid line anchor: #{anchor}")
|
|
|
|
ranges: list[tuple[int, int]] = []
|
|
for item in anchor.split(","):
|
|
start_text, separator, end_text = item.partition("-L")
|
|
start = int(start_text[1:])
|
|
end = int(end_text) if separator else start
|
|
if start < 1 or end < 1:
|
|
raise ValueError("line numbers must be at least 1")
|
|
if start > end:
|
|
raise ValueError(f"line range start ({start}) exceeds end ({end})")
|
|
ranges.append((start, end))
|
|
|
|
merged: list[tuple[int, int]] = []
|
|
for start, end in sorted(ranges):
|
|
if merged and start <= merged[-1][1] + 1:
|
|
merged[-1] = (merged[-1][0], max(merged[-1][1], end))
|
|
else:
|
|
merged.append((start, end))
|
|
return merged
|
|
|
|
|
|
def format_line_anchor(ranges: list[tuple[int, int]]) -> str:
|
|
"""Render normalized ranges without the leading ``#``."""
|
|
return ",".join(f"L{start}" if start == end else f"L{start}-L{end}" for start, end in ranges)
|