Skip to content

Decouple shell helpers, shell tweaks #641

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 11 commits into from
Nov 7, 2020
22 changes: 22 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ Here you can find the recent changes to tmuxp
current
-------
- *Insert changes/features/fixes for next release here*
- :issue:`641` Improvements to ``shell``

Thanks `django-extensions`_ (licensed MIT) for the shell detection abstraction.

- Deprecate ``shell_plus``
- ``tmuxp shell`` now detects the best shell available by default
- Python 3.7+ with ``PYTHONBREAKPOINT`` set in env will drop into ``pdb`` by
default
- Drop into ``code.interact`` by default instead of ``pdb`` if no third
party shells found
- New options, override:

- ``--pdb``: Use plain old ``breakpoint()`` (python 3.7+) or
``pdb.set_trace``
- ``--code``: Drop into ``code.interact``, accepts ``--use-pythonrc``
- ``--bpython``: Drop into bpython
- ``--ipython``: Drop into ipython
- ``--ptpython``: Drop into ptpython, accepts ``--use-vi-mode``
- ``--ptipython``: Drop into ipython + ptpython, accepts
``--use-vi-mode``

.. _django-extensions: https://github.com/django-extensions/django-extensions

tmuxp 1.6.0 (2020-11-06)
------------------------
Expand Down
12 changes: 12 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ Internals

.. automethod:: tmuxp.util.run_before_script

.. automethod:: tmuxp.util.oh_my_zsh_auto_title

.. automethod:: tmuxp.util.raise_if_tmux_not_running

.. automethod:: tmuxp.util.get_current_pane

.. automethod:: tmuxp.util.get_session

.. automethod:: tmuxp.util.get_window

.. automethod:: tmuxp.util.get_pane

CLI
---

Expand Down
14 changes: 14 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ this via ``tmuxp -c``:
.. _ipdb: https://pypi.org/project/ipdb/
.. _libtmux: https://libtmux.git-pull.com

Shell detection
~~~~~~~~~~~~~~~

``tmuxp shell`` detects the richest shell available in your *site packages*, you can also pick your shell via args:

- ``--pdb``: Use plain old ``breakpoint()`` (python 3.7+) or
``pdb.set_trace``
- ``--code``: Drop into ``code.interact``, accepts ``--use-pythonrc``
- ``--bpython``: Drop into bpython
- ``--ipython``: Drop into ipython
- ``--ptpython``: Drop into ptpython, accepts ``--use-vi-mode``
- ``--ptipython``: Drop into ipython + ptpython, accepts
``--use-vi-mode``

.. _cli_freeze:

Freeze sessions
Expand Down
41 changes: 31 additions & 10 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import libtmux
from libtmux.common import has_lt_version
from libtmux.exc import LibTmuxException
from tmuxp import cli, config
from tmuxp import cli, config, exc
from tmuxp.cli import (
command_ls,
get_config_dir,
Expand Down Expand Up @@ -407,7 +407,7 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
assert 'Please set' not in result.output


@pytest.mark.parametrize("cli_cmd", ['shell', 'shell_plus'])
@pytest.mark.parametrize("cli_cmd", ['shell', ('shell', '--pdb')])
@pytest.mark.parametrize(
"cli_args,inputs,env,expected_output",
[
Expand Down Expand Up @@ -501,7 +501,8 @@ def test_shell(
SERVER_SOCKET_NAME=server.socket_name,
)

cli_args = [cli_cmd] + [cli_arg.format(**template_ctx) for cli_arg in cli_args]
cli_cmd = list(cli_cmd) if isinstance(cli_cmd, (list, tuple)) else [cli_cmd]
cli_args = cli_cmd + [cli_arg.format(**template_ctx) for cli_arg in cli_args]

for k, v in env.items():
monkeypatch.setenv(k, v.format(**template_ctx))
Expand All @@ -515,7 +516,13 @@ def test_shell(
assert expected_output.format(**template_ctx) in result.output


@pytest.mark.parametrize("cli_cmd", ['shell', 'shell_plus'])
@pytest.mark.parametrize(
"cli_cmd",
[
'shell',
('shell', '--pdb'),
],
)
@pytest.mark.parametrize(
"cli_args,inputs,env,template_ctx,exception,message",
[
Expand All @@ -537,7 +544,7 @@ def test_shell(
[],
{},
{'session_name': 'nonexistant_session'},
None,
exc.TmuxpException,
'Session not found: nonexistant_session',
),
(
Expand All @@ -551,7 +558,7 @@ def test_shell(
[],
{},
{'window_name': 'nonexistant_window'},
None,
exc.TmuxpException,
'Window not found: {WINDOW_NAME}',
),
],
Expand Down Expand Up @@ -583,7 +590,8 @@ def test_shell_target_missing(
PANE_ID=template_ctx.get('pane_id'),
SERVER_SOCKET_NAME=server.socket_name,
)
cli_args = [cli_cmd] + [cli_arg.format(**template_ctx) for cli_arg in cli_args]
cli_cmd = list(cli_cmd) if isinstance(cli_cmd, (list, tuple)) else [cli_cmd]
cli_args = cli_cmd + [cli_arg.format(**template_ctx) for cli_arg in cli_args]

for k, v in env.items():
monkeypatch.setenv(k, v.format(**template_ctx))
Expand All @@ -603,12 +611,23 @@ def test_shell_target_missing(
assert message.format(**template_ctx) in result.output


@pytest.mark.parametrize(
"cli_cmd",
[
# 'shell',
# ('shell', '--pdb'),
('shell', '--code'),
# ('shell', '--bpython'),
# ('shell', '--ptipython'),
# ('shell', '--ptpython'),
# ('shell', '--ipython'),
],
)
@pytest.mark.parametrize(
"cli_args,inputs,env,message",
[
(
[
'shell_plus',
'-L{SOCKET_NAME}',
],
[],
Expand All @@ -617,7 +636,6 @@ def test_shell_target_missing(
),
(
[
'shell_plus',
'-L{SOCKET_NAME}',
],
[],
Expand All @@ -627,6 +645,7 @@ def test_shell_target_missing(
],
)
def test_shell_plus(
cli_cmd,
cli_args,
inputs,
env,
Expand All @@ -650,7 +669,9 @@ def test_shell_plus(
SERVER_SOCKET_NAME=server.socket_name,
)

cli_args[:] = [cli_arg.format(**template_ctx) for cli_arg in cli_args]
cli_cmd = list(cli_cmd) if isinstance(cli_cmd, (list, tuple)) else [cli_cmd]
cli_args = cli_cmd + [cli_arg.format(**template_ctx) for cli_arg in cli_args]

for k, v in env.items():
monkeypatch.setenv(k, v.format(**template_ctx))

Expand Down
14 changes: 14 additions & 0 deletions tests/test_shell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from tmuxp import shell
from tmuxp._compat import string_types


def test_detect_best_shell():
result = shell.detect_best_shell()
assert isinstance(result, string_types)


def test_shell_detect():
assert isinstance(shell.has_bpython(), bool)
assert isinstance(shell.has_ipython(), bool)
assert isinstance(shell.has_ptpython(), bool)
assert isinstance(shell.has_ptipython(), bool)
Loading