Skip to content

Commit 47f506a

Browse files
committed
snapshot(refactor): Implement modular structure with direct imports
Remove exports from __init__.py files, keep only documentation per architecture plan. Update imports in tests to reference actual module paths directly. Fix import paths in snapshot modules for better maintainability. Maintain full test compatibility with all 707 tests passing.
1 parent c8def10 commit 47f506a

File tree

10 files changed

+36
-35
lines changed

10 files changed

+36
-35
lines changed

src/libtmux/snapshot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
99
This module provides hierarchical snapshots of tmux objects (Server, Session,
1010
Window, Pane) that are immutable and maintain the relationships between objects.
11-
"""
11+
"""

src/libtmux/snapshot/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
from libtmux.pane import Pane
1414
from libtmux.server import Server
1515
from libtmux.session import Session
16+
from libtmux.snapshot.types import PaneT, SessionT, WindowT
1617
from libtmux.window import Window
1718

18-
from libtmux.snapshot.types import PaneT, WindowT, SessionT, ServerT
19-
2019

2120
class SealablePaneBase(Pane, Sealable):
2221
"""Base class for sealable pane classes."""
@@ -71,4 +70,4 @@ def windows(self) -> QueryList[WindowT]:
7170
@property
7271
def panes(self) -> QueryList[PaneT]:
7372
"""Return panes with the appropriate generic type."""
74-
return t.cast(QueryList[PaneT], super().panes)
73+
return t.cast(QueryList[PaneT], super().panes)

src/libtmux/snapshot/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
33
This package contains concrete snapshot implementations for tmux objects:
44
ServerSnapshot, SessionSnapshot, WindowSnapshot, and PaneSnapshot.
5-
"""
5+
"""

src/libtmux/snapshot/models/pane.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""PaneSnapshot implementation.
22
3-
This module defines the PaneSnapshot class for creating immutable snapshots of tmux panes.
3+
This module defines the PaneSnapshot class for creating
4+
immutable snapshots of tmux panes.
45
"""
56

67
from __future__ import annotations
@@ -14,7 +15,6 @@
1415
from libtmux._internal.frozen_dataclass_sealable import frozen_dataclass_sealable
1516
from libtmux.pane import Pane
1617
from libtmux.server import Server
17-
1818
from libtmux.snapshot.base import SealablePaneBase
1919

2020
if t.TYPE_CHECKING:
@@ -213,4 +213,4 @@ def from_pane(
213213
snapshot, "_sealed", False
214214
) # Temporarily set to allow seal() method to work
215215
snapshot.seal(deep=False)
216-
return snapshot
216+
return snapshot

src/libtmux/snapshot/models/server.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""ServerSnapshot implementation.
22
3-
This module defines the ServerSnapshot class for creating immutable snapshots of tmux servers.
3+
This module defines the ServerSnapshot class for creating
4+
immutable snapshots of tmux servers.
45
"""
56

67
from __future__ import annotations
@@ -15,17 +16,14 @@
1516
from libtmux._internal.query_list import QueryList
1617
from libtmux.server import Server
1718
from libtmux.session import Session
18-
1919
from libtmux.snapshot.base import SealableServerBase
2020
from libtmux.snapshot.models.pane import PaneSnapshot
2121
from libtmux.snapshot.models.session import SessionSnapshot
2222
from libtmux.snapshot.models.window import WindowSnapshot
2323

2424

2525
@frozen_dataclass_sealable
26-
class ServerSnapshot(
27-
SealableServerBase[SessionSnapshot, WindowSnapshot, PaneSnapshot]
28-
):
26+
class ServerSnapshot(SealableServerBase[SessionSnapshot, WindowSnapshot, PaneSnapshot]):
2927
"""A read-only snapshot of a server.
3028
3129
Examples
@@ -209,4 +207,4 @@ def _create_session_snapshot_safely(
209207
return None
210208
else:
211209
# In production, we want the exception to propagate
212-
raise
210+
raise

src/libtmux/snapshot/models/session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""SessionSnapshot implementation.
22
3-
This module defines the SessionSnapshot class for creating immutable snapshots of tmux sessions.
3+
This module defines the SessionSnapshot class for creating
4+
immutable snapshots of tmux sessions.
45
"""
56

67
from __future__ import annotations
@@ -14,7 +15,6 @@
1415
from libtmux._internal.query_list import QueryList
1516
from libtmux.server import Server
1617
from libtmux.session import Session
17-
1818
from libtmux.snapshot.base import SealableSessionBase
1919
from libtmux.snapshot.models.pane import PaneSnapshot
2020
from libtmux.snapshot.models.window import WindowSnapshot
@@ -167,4 +167,4 @@ def from_session(
167167
snapshot, "_sealed", False
168168
) # Temporarily set to allow seal() method to work
169169
snapshot.seal(deep=False)
170-
return snapshot
170+
return snapshot

src/libtmux/snapshot/models/window.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""WindowSnapshot implementation.
22
3-
This module defines the WindowSnapshot class for creating immutable snapshots of tmux windows.
3+
This module defines the WindowSnapshot class for creating
4+
immutable snapshots of tmux windows.
45
"""
56

67
from __future__ import annotations
@@ -13,10 +14,9 @@
1314
from libtmux._internal.frozen_dataclass_sealable import frozen_dataclass_sealable
1415
from libtmux._internal.query_list import QueryList
1516
from libtmux.server import Server
16-
from libtmux.window import Window
17-
1817
from libtmux.snapshot.base import SealableWindowBase
1918
from libtmux.snapshot.models.pane import PaneSnapshot
19+
from libtmux.window import Window
2020

2121
if t.TYPE_CHECKING:
2222
from libtmux.snapshot.models.session import SessionSnapshot
@@ -172,4 +172,4 @@ def from_window(
172172
snapshot, "_sealed", False
173173
) # Temporarily set to allow seal() method to work
174174
snapshot.seal(deep=False)
175-
return snapshot
175+
return snapshot

src/libtmux/snapshot/types.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
# Forward references for snapshot classes
2323
if t.TYPE_CHECKING:
2424
from libtmux.snapshot.models.pane import PaneSnapshot
25-
from libtmux.snapshot.models.window import WindowSnapshot
26-
from libtmux.snapshot.models.session import SessionSnapshot
2725
from libtmux.snapshot.models.server import ServerSnapshot
26+
from libtmux.snapshot.models.session import SessionSnapshot
27+
from libtmux.snapshot.models.window import WindowSnapshot
2828

2929
# Union type for snapshot classes
30-
SnapshotType = t.Union[ServerSnapshot, SessionSnapshot, WindowSnapshot, PaneSnapshot]
30+
SnapshotType = t.Union[
31+
ServerSnapshot, SessionSnapshot, WindowSnapshot, PaneSnapshot
32+
]
3133
else:
3234
# Runtime placeholder - will be properly defined after imports
33-
SnapshotType = t.Any
35+
SnapshotType = t.Any

src/libtmux/snapshot/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
This module provides utility functions for filtering and serializing snapshots.
44
"""
55

6+
from __future__ import annotations
7+
68
import copy
79
import datetime
810
import typing as t
911

10-
from ..types import SnapshotType
1112
from .models.pane import PaneSnapshot
1213
from .models.server import ServerSnapshot
1314
from .models.session import SessionSnapshot
1415
from .models.window import WindowSnapshot
16+
from .types import SnapshotType
1517

1618

1719
def filter_snapshot(
@@ -195,4 +197,4 @@ def is_active(
195197
if filtered is None:
196198
error_msg = "No active objects found!"
197199
raise ValueError(error_msg)
198-
return t.cast(ServerSnapshot, filtered)
200+
return t.cast(ServerSnapshot, filtered)

tests/test_snapshot.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import pytest
1010

1111
from libtmux._internal.frozen_dataclass_sealable import is_sealable
12-
from libtmux.snapshot import (
13-
PaneSnapshot,
14-
ServerSnapshot,
15-
SessionSnapshot,
16-
WindowSnapshot,
12+
from libtmux.snapshot.models.pane import PaneSnapshot
13+
from libtmux.snapshot.models.server import ServerSnapshot
14+
from libtmux.snapshot.models.session import SessionSnapshot
15+
from libtmux.snapshot.models.window import WindowSnapshot
16+
from libtmux.snapshot.utils import (
1717
snapshot_active_only,
1818
snapshot_to_dict,
1919
)
@@ -173,7 +173,7 @@ def test_session_snapshot_creation(self, session: Session) -> None:
173173

174174
# Patch the from_session method to return our mock
175175
with patch(
176-
"libtmux.snapshot.SessionSnapshot.from_session",
176+
"libtmux.snapshot.models.session.SessionSnapshot.from_session",
177177
return_value=mock_snapshot,
178178
):
179179
snapshot = SessionSnapshot.from_session(session)
@@ -212,7 +212,7 @@ def test_server_snapshot_creation(self, server: Server, session: Session) -> Non
212212

213213
# Patch the from_server method to return our mock
214214
with patch(
215-
"libtmux.snapshot.ServerSnapshot.from_server",
215+
"libtmux.snapshot.models.server.ServerSnapshot.from_server",
216216
return_value=mock_snapshot,
217217
):
218218
snapshot = ServerSnapshot.from_server(server)
@@ -293,7 +293,7 @@ def mock_filter(
293293
return True
294294

295295
# Apply the filter with a patch to avoid actual implementation
296-
with patch("libtmux.snapshot.filter_snapshot", side_effect=lambda s, f: s):
296+
with patch("libtmux.snapshot.utils.filter_snapshot", side_effect=lambda s, f: s):
297297
filtered = snapshot_active_only(mock_server_snap)
298298

299299
# Since we're using a mock that passes everything through, the filtered

0 commit comments

Comments
 (0)