Skip to content

libtmux v0.15 #805

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

Merged
merged 4 commits into from
Sep 10, 2022
Merged
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
44 changes: 37 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tmuxp = 'tmuxp:cli.cli'
python = "^3.7"
click = "~8"
kaptan = ">=0.5.10"
libtmux = "~0.14.0"
libtmux = "~0.15.0"
colorama = ">=0.3.9"

[tool.poetry.dev-dependencies]
Expand Down
5 changes: 3 additions & 2 deletions tmuxp/cli/debug_info.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import pathlib
import platform
import shutil
import sys

import click

from libtmux import __version__ as libtmux_version
from libtmux.common import get_version, tmux_cmd, which
from libtmux.common import get_version, tmux_cmd

from ..__about__ import __version__
from .utils import tmuxp_echo
Expand Down Expand Up @@ -62,7 +63,7 @@ def format_tmux_resp(std_resp):
"tmux version: %s" % get_version(),
"libtmux version: %s" % libtmux_version,
"tmuxp version: %s" % __version__,
"tmux path: %s" % which("tmux"),
"tmux path: %s" % shutil.which("tmux"),
"tmuxp path: %s" % tmuxp_path,
"shell: %s" % os.environ["SHELL"],
output_break(),
Expand Down
5 changes: 3 additions & 2 deletions tmuxp/cli/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import logging
import os
import pathlib
import shutil
import sys
from typing import List

import click
import kaptan

from libtmux.common import has_gte_version, which
from libtmux.common import has_gte_version
from libtmux.server import Server

from .. import config, exc, log, util
Expand Down Expand Up @@ -357,7 +358,7 @@ def load_workspace(
colors=colors,
)

which("tmux") # raise exception if tmux not found
shutil.which("tmux") # raise exception if tmux not found

try: # load WorkspaceBuilder object for tmuxp config / tmux server
builder = WorkspaceBuilder(
Expand Down
93 changes: 6 additions & 87 deletions tmuxp/conftest.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import getpass
import logging
import os
import pathlib
import shutil
import typing as t

import pytest

from _pytest.doctest import DoctestItem
from _pytest.fixtures import SubRequest

from libtmux import exc
from libtmux.common import which
from libtmux.server import Server
from libtmux.test import TEST_SESSION_PREFIX, get_test_session_name, namer
from libtmux.test import namer
from tests.fixtures import utils as test_utils

if t.TYPE_CHECKING:
Expand All @@ -22,18 +18,6 @@
USING_ZSH = "zsh" in os.getenv("SHELL", "")


@pytest.fixture(autouse=True, scope="session")
def home_path(tmp_path_factory: pytest.TempPathFactory):
return tmp_path_factory.mktemp("home")


@pytest.fixture(autouse=True, scope="session")
def user_path(home_path: pathlib.Path):
p = home_path / getpass.getuser()
p.mkdir()
return p


@pytest.mark.skipif(USING_ZSH, reason="Using ZSH")
@pytest.fixture(autouse=USING_ZSH, scope="session")
def zshrc(user_path: pathlib.Path):
Expand All @@ -47,8 +31,8 @@ def zshrc(user_path: pathlib.Path):


@pytest.fixture(autouse=True)
def home_path_default(user_path: pathlib.Path):
os.environ["HOME"] = str(user_path)
def home_path_default(monkeypatch: pytest.MonkeyPatch, user_path: pathlib.Path) -> None:
monkeypatch.setenv("HOME", str(user_path))


@pytest.fixture(scope="function")
Expand All @@ -70,77 +54,12 @@ def socket_name(request) -> str:
return "tmuxp_test%s" % next(namer)


@pytest.fixture(scope="function")
def server(
request: SubRequest, monkeypatch: pytest.MonkeyPatch, socket_name: str
) -> Server:
tmux = Server(socket_name=socket_name)

def fin() -> None:
tmux.kill_server()

request.addfinalizer(fin)

return tmux


@pytest.fixture(scope="function")
def session(server):
session_name = "tmuxp"

if not server.has_session(session_name):
server.cmd(
"-f",
"/dev/null", # use a blank config to reduce side effects
"new-session",
"-d", # detached
"-s",
session_name,
"/bin/sh", # use /bin/sh as a shell to reduce side effects
# normally, it'd be -c, but new-session is special
)

# find current sessions prefixed with tmuxp
old_test_sessions = [
s.get("session_name")
for s in server._sessions
if s.get("session_name").startswith(TEST_SESSION_PREFIX)
]

TEST_SESSION_NAME = get_test_session_name(server=server)

try:
session = server.new_session(session_name=TEST_SESSION_NAME)
except exc.LibTmuxException as e:
raise e

"""
Make sure that tmuxp can :ref:`test_builder_visually` and switches to
the newly created session for that testcase.
"""
session_id = session.get("session_id")
assert session_id is not None
try:
server.switch_client(target_session=session_id)
except exc.LibTmuxException:
# server.attach_session(session.get('session_id'))
pass

for old_test_session in old_test_sessions:
logger.debug("Old test test session %s found. Killing it." % old_test_session)
server.kill_session(old_test_session)
assert TEST_SESSION_NAME == session.get("session_name")
assert TEST_SESSION_NAME != "tmuxp"

return session


@pytest.fixture(autouse=True)
def add_doctest_fixtures(
request: SubRequest,
request: pytest.FixtureRequest,
doctest_namespace: t.Dict[str, t.Any],
) -> None:
if isinstance(request._pyfuncitem, DoctestItem) and which("tmux"):
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):
doctest_namespace["server"] = request.getfixturevalue("server")
session: "Session" = request.getfixturevalue("session")
doctest_namespace["session"] = session
Expand Down