Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path
from types import MappingProxyType

from .models import PortingBacklog, PortingModule
from .models import PortingBacklog, PortingModule, _load_module_snapshot
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the import to reflect the renamed load_module_snapshot function in models.py.

Suggested change
from .models import PortingBacklog, PortingModule, _load_module_snapshot
from .models import PortingBacklog, PortingModule, load_module_snapshot


SNAPSHOT_PATH = (
Path(__file__).resolve().parent / "reference_data" / "commands_snapshot.json"
Expand All @@ -25,16 +25,7 @@ class CommandExecution:

@lru_cache(maxsize=1)
def load_command_snapshot() -> tuple[PortingModule, ...]:
raw_entries = json.loads(SNAPSHOT_PATH.read_text())
return tuple(
PortingModule(
name=entry["name"],
responsibility=entry["responsibility"],
source_hint=entry["source_hint"],
status="mirrored",
)
for entry in raw_entries
)
return _load_module_snapshot(SNAPSHOT_PATH)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the call site to use the renamed load_module_snapshot function.

Suggested change
return _load_module_snapshot(SNAPSHOT_PATH)
return load_module_snapshot(SNAPSHOT_PATH)



PORTED_COMMANDS = load_command_snapshot()
Expand Down
15 changes: 15 additions & 0 deletions src/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import functools
import json
from pathlib import Path
from dataclasses import dataclass, field


Expand Down Expand Up @@ -55,3 +57,16 @@ def summary_lines(self) -> list[str]:
f'- {module.name} [{module.status}] — {module.responsibility} (from {module.source_hint})'
for module in self.modules
]


def _load_module_snapshot(path: Path) -> tuple[PortingModule, ...]:
raw_entries = json.loads(path.read_text())
return tuple(
PortingModule(
name=entry["name"],
responsibility=entry["responsibility"],
source_hint=entry["source_hint"],
status="mirrored",
)
for entry in raw_entries
)
Comment on lines +62 to +72
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The helper function _load_module_snapshot is used across multiple modules (commands.py and tools.py), so the leading underscore (which typically denotes a module-private function) is inconsistent with its usage and the PR title. Additionally, using json.load() with a file object is more memory-efficient than reading the entire file into a string, and explicitly specifying encoding='utf-8' ensures consistent behavior across different platforms (e.g., Windows).

Suggested change
def _load_module_snapshot(path: Path) -> tuple[PortingModule, ...]:
raw_entries = json.loads(path.read_text())
return tuple(
PortingModule(
name=entry["name"],
responsibility=entry["responsibility"],
source_hint=entry["source_hint"],
status="mirrored",
)
for entry in raw_entries
)
def load_module_snapshot(path: Path) -> tuple[PortingModule, ...]:
with path.open(encoding="utf-8") as f:
return tuple(
PortingModule(
name=entry["name"],
responsibility=entry["responsibility"],
source_hint=entry["source_hint"],
status="mirrored",
)
for entry in json.load(f)
)
References
  1. PEP 8: _single_leading_underscore is a weak 'internal use' indicator. Since this function is intended for use across modules in the package, the underscore should be removed. (link)

13 changes: 2 additions & 11 deletions src/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path
from types import MappingProxyType

from .models import PortingBacklog, PortingModule
from .models import PortingBacklog, PortingModule, _load_module_snapshot
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the import to reflect the renamed load_module_snapshot function in models.py.

Suggested change
from .models import PortingBacklog, PortingModule, _load_module_snapshot
from .models import PortingBacklog, PortingModule, load_module_snapshot

from .permissions import ToolPermissionContext

SNAPSHOT_PATH = (
Expand All @@ -26,16 +26,7 @@ class ToolExecution:

@lru_cache(maxsize=1)
def load_tool_snapshot() -> tuple[PortingModule, ...]:
raw_entries = json.loads(SNAPSHOT_PATH.read_text())
return tuple(
PortingModule(
name=entry["name"],
responsibility=entry["responsibility"],
source_hint=entry["source_hint"],
status="mirrored",
)
for entry in raw_entries
)
return _load_module_snapshot(SNAPSHOT_PATH)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the call site to use the renamed load_module_snapshot function.

Suggested change
return _load_module_snapshot(SNAPSHOT_PATH)
return load_module_snapshot(SNAPSHOT_PATH)



PORTED_TOOLS = load_tool_snapshot()
Expand Down