Skip to content

types(workspace-imports) Example typings via NotRequried #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
!squash wip
  • Loading branch information
tony committed Jun 14, 2025
commit a4a60104970bfe41296fadc3ba19ed443ca7b1d3
5 changes: 4 additions & 1 deletion src/tmuxp/_internal/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ class PaneConfig(TypedDict, total=False):
environment: NotRequired[dict[str, str]]
focus: NotRequired[str | bool]
suppress_history: NotRequired[bool]
target: NotRequired[str]


PaneValue = t.Union[str, PaneConfig]
PaneValue = t.Union[str, PaneConfig, None]


class WindowConfig(TypedDict, total=False):
Expand All @@ -70,7 +71,9 @@ class WindowConfig(TypedDict, total=False):
window_name: str
start_directory: NotRequired[str]
shell_command_before: NotRequired[ShellCommandValue]
shell_command_after: NotRequired[ShellCommandValue]
layout: NotRequired[str]
clear: NotRequired[bool]
options: NotRequired[dict[str, t.Any]]
options_after: NotRequired[dict[str, t.Any]]
environment: NotRequired[dict[str, str]]
Expand Down
6 changes: 4 additions & 2 deletions src/tmuxp/cli/import_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def create_import_subparser(
class ImportConfigFn(t.Protocol):
"""Typing for import configuration callback function."""

def __call__(self, workspace_dict: dict[str, t.Any]) -> dict[str, t.Any]:
def __call__(self, workspace_dict: dict[str, t.Any]) -> WorkspaceConfig:
"""Execute tmuxp import function."""
...

Expand All @@ -146,7 +146,9 @@ def import_config(
) -> None:
"""Import a configuration from a workspace_file."""
existing_workspace_file = ConfigReader._from_file(pathlib.Path(workspace_file))
cfg_reader = ConfigReader(importfunc(existing_workspace_file))
cfg_reader = ConfigReader(
t.cast(dict[t.Any, t.Any], importfunc(existing_workspace_file))
)

workspace_file_format = prompt_choices(
"Convert to",
Expand Down
14 changes: 3 additions & 11 deletions src/tmuxp/workspace/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def import_tmuxinator(workspace_dict: dict[str, t.Any]) -> WorkspaceConfig:
if "socket_name" in workspace_dict:
tmuxp_workspace["socket_name"] = workspace_dict["socket_name"]


if "tabs" in workspace_dict:
workspace_dict["windows"] = workspace_dict.pop("tabs")

Expand Down Expand Up @@ -92,14 +91,10 @@ def import_tmuxinator(workspace_dict: dict[str, t.Any]) -> WorkspaceConfig:
for k, v in window_item.items():
new_window: WindowConfig = {"window_name": k}

if isinstance(v, str):
if isinstance(v, str) or v is None:
new_window["panes"] = [v]
tmuxp_workspace["windows"].append(new_window)
continue
if v is None:
new_window["panes"] = [""] # Empty pane
tmuxp_workspace["windows"].append(new_window)
continue
if isinstance(v, list):
new_window["panes"] = v
tmuxp_workspace["windows"].append(new_window)
Expand Down Expand Up @@ -153,20 +148,17 @@ def import_teamocil(workspace_dict: dict[str, t.Any]) -> WorkspaceConfig:
if "root" in workspace_dict:
tmuxp_workspace["start_directory"] = workspace_dict.pop("root")


for w in workspace_dict["windows"]:
window_dict: WindowConfig = {"window_name": w["name"]}

if "clear" in w:
# TODO: handle clear attribute
pass
window_dict["clear"] = w["clear"]

if "filters" in w:
if "before" in w["filters"]:
window_dict["shell_command_before"] = w["filters"]["before"]
if "after" in w["filters"]:
# TODO: handle shell_command_after
pass
window_dict["shell_command_after"] = w["filters"]["after"]

if "root" in w:
window_dict["start_directory"] = w.pop("root")
Expand Down
Loading