Skip to content

🧹 [Extract shared load_module_snapshot function]#172

Open
badMade wants to merge 4 commits into
mainfrom
extract-load-module-snapshot-15334275623421876991
Open

🧹 [Extract shared load_module_snapshot function]#172
badMade wants to merge 4 commits into
mainfrom
extract-load-module-snapshot-15334275623421876991

Conversation

@badMade
Copy link
Copy Markdown
Owner

@badMade badMade commented May 11, 2026

🎯 What:
Extracted duplicated JSON snapshot parsing logic into a shared _load_module_snapshot(path: Path) helper function in src/models.py. Both src/tools.py (load_tool_snapshot) and src/commands.py (load_command_snapshot) were updated to use this new helper.

💡 Why:
This eliminates redundant code duplication across the codebase, making it easier to maintain and read. It ensures that any future changes to how snapshots are loaded or how PortingModule instances are constructed only need to be made in one place.

Verification:

  • Ran the full python3 -m unittest discover tests suite.
  • Verified all 31 tests passed successfully.
  • Code review confirmed the refactoring is functionally equivalent to the original implementation.

Result:
Improved maintainability by reducing code duplication, leaving cleaner snapshot loading functions without changing any underlying application behavior.


PR created automatically by Jules for task 15334275623421876991 started by @badMade

Extracts the duplicated JSON parsing and PortingModule mapping logic
from load_tool_snapshot (src/tools.py) and load_command_snapshot (src/commands.py)
into a shared _load_module_snapshot helper in src/models.py.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings May 11, 2026 19:00
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the module snapshot loading logic by extracting it into a shared helper function, _load_module_snapshot, in src/models.py, which is now used by both src/commands.py and src/tools.py. The reviewer recommends renaming the function to remove the leading underscore to reflect its cross-module usage and suggests using json.load() with explicit UTF-8 encoding for improved efficiency and platform consistency.

Comment thread src/models.py
Comment on lines +62 to +72
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
)
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)

Comment thread src/commands.py
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

Comment thread src/commands.py
)
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)

Comment thread src/tools.py
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

Comment thread src/tools.py
)
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)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors duplicated JSON snapshot parsing logic for tool/command “mirrored module” metadata into a shared helper in src/models.py, and updates callers to use it.

Changes:

  • Added a shared _load_module_snapshot(path: Path) helper in src/models.py.
  • Updated load_tool_snapshot() and load_command_snapshot() to delegate to the shared helper.
  • Consolidated snapshot parsing/PortingModule construction to reduce duplication.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/models.py Introduces the shared snapshot-loading helper used by tool/command snapshot loaders.
src/tools.py Replaces inline snapshot parsing with a call to the shared helper.
src/commands.py Replaces inline snapshot parsing with a call to the shared helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/models.py
]


def _load_module_snapshot(path: Path) -> tuple[PortingModule, ...]:
Comment thread src/tools.py
from types import MappingProxyType

from .models import PortingBacklog, PortingModule
from .models import PortingBacklog, PortingModule, _load_module_snapshot
Comment thread src/commands.py
from types import MappingProxyType

from .models import PortingBacklog, PortingModule
from .models import PortingBacklog, PortingModule, _load_module_snapshot
Extracts the duplicated JSON parsing and PortingModule mapping logic
from load_tool_snapshot (src/tools.py) and load_command_snapshot (src/commands.py)
into a shared _load_module_snapshot helper in src/models.py.
Also fixes the auto-merge CI workflow by fully terminating the truncated js block and upgrading actions/github-script to v9 to fix the Unexpected end of input and Node.js 20 deprecation errors.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@badMade badMade marked this pull request as ready for review May 12, 2026 17:45
Copilot AI review requested due to automatic review settings May 12, 2026 17:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/tools.py
Comment on lines 3 to +10
import json
from collections.abc import Mapping
from dataclasses import dataclass
from functools import lru_cache
from pathlib import Path
from types import MappingProxyType

from .models import PortingBacklog, PortingModule
from .models import PortingBacklog, PortingModule, _load_module_snapshot
Comment thread src/commands.py
Comment on lines 3 to +10
import json
from collections.abc import Mapping
from dataclasses import dataclass
from functools import lru_cache
from pathlib import Path
from types import MappingProxyType

from .models import PortingBacklog, PortingModule
from .models import PortingBacklog, PortingModule, _load_module_snapshot
Comment on lines 24 to 26
- name: Wait for checks to complete
uses: actions/github-script@v7
uses: actions/github-script@v9
id: wait-checks
@badMade
Copy link
Copy Markdown
Owner Author

badMade commented May 15, 2026

@copilot, resolve the merge conflicts in this pull request.

Extracts the duplicated JSON parsing and PortingModule mapping logic
from load_tool_snapshot (src/tools.py) and load_command_snapshot (src/commands.py)
into a shared _load_module_snapshot helper in src/models.py.
Also fixes the auto-merge CI workflow by fully terminating the truncated js block and upgrading actions/github-script to v9 to fix the Unexpected end of input and Node.js 20 deprecation errors.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@badMade
Copy link
Copy Markdown
Owner Author

badMade commented May 25, 2026

@copilot, resolve the merge conflicts in this pull request.

Copilot AI review requested due to automatic review settings May 25, 2026 23:09
@badMade badMade review requested due to automatic review settings May 25, 2026 23:09
Copy link
Copy Markdown

Copilot AI commented May 25, 2026

@copilot, resolve the merge conflicts in this pull request.

Resolved and merged latest main into this branch with conflicts fixed in commit 0003ba1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants