Skip to content

Commit e719f71

Browse files
committed
Remove shell_plus: Update tests
1 parent 663fcaa commit e719f71

File tree

2 files changed

+20
-114
lines changed

2 files changed

+20
-114
lines changed

tests/test_cli.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
407407
assert 'Please set' not in result.output
408408

409409

410-
@pytest.mark.parametrize("cli_cmd", ['shell', 'shell_plus'])
410+
@pytest.mark.parametrize("cli_cmd", ['shell', ('shell', '--use-pdb')])
411411
@pytest.mark.parametrize(
412412
"cli_args,inputs,env,expected_output",
413413
[
@@ -515,7 +515,7 @@ def test_shell(
515515
assert expected_output.format(**template_ctx) in result.output
516516

517517

518-
@pytest.mark.parametrize("cli_cmd", ['shell', 'shell_plus'])
518+
@pytest.mark.parametrize("cli_cmd", ['shell', ('shell', '--use-pdb')])
519519
@pytest.mark.parametrize(
520520
"cli_args,inputs,env,template_ctx,exception,message",
521521
[
@@ -583,7 +583,8 @@ def test_shell_target_missing(
583583
PANE_ID=template_ctx.get('pane_id'),
584584
SERVER_SOCKET_NAME=server.socket_name,
585585
)
586-
cli_args = [cli_cmd] + [cli_arg.format(**template_ctx) for cli_arg in cli_args]
586+
cli_cmd = list(cli_cmd) if isinstance(cli_cmd, tuple) else [cli_cmd]
587+
cli_args = cli_cmd + [cli_arg.format(**template_ctx) for cli_arg in cli_args]
587588

588589
for k, v in env.items():
589590
monkeypatch.setenv(k, v.format(**template_ctx))
@@ -608,7 +609,7 @@ def test_shell_target_missing(
608609
[
609610
(
610611
[
611-
'shell_plus',
612+
'shell',
612613
'-L{SOCKET_NAME}',
613614
],
614615
[],
@@ -617,7 +618,7 @@ def test_shell_target_missing(
617618
),
618619
(
619620
[
620-
'shell_plus',
621+
'shell',
621622
'-L{SOCKET_NAME}',
622623
],
623624
[],

tmuxp/cli.py

+14-109
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,14 @@ def startup(config_dir):
677677
help='Use pdb / breakpoint() instead of code.interact()',
678678
default=False,
679679
)
680+
@click.option(
681+
'--use-pythonrc/--no-startup',
682+
'use_pythonrc',
683+
help='Load the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.',
684+
default=False,
685+
)
680686
def command_shell(
681-
session_name, window_name, socket_name, socket_path, command, use_pdb
687+
session_name, window_name, socket_name, socket_path, command, use_pdb, use_pythonrc
682688
):
683689
"""Launch python shell for tmux server, session, window and pane.
684690
@@ -715,114 +721,13 @@ def command_shell(
715721
else:
716722
from .shell import launch
717723

718-
launch(server=server, session=session, window=window, pane=pane)
719-
720-
721-
@cli.command(name='shell_plus')
722-
@click.argument('session_name', nargs=1, required=False)
723-
@click.argument('window_name', nargs=1, required=False)
724-
@click.option('-S', 'socket_path', help='pass-through for tmux -S')
725-
@click.option('-L', 'socket_name', help='pass-through for tmux -L')
726-
@click.option(
727-
'-c',
728-
'command',
729-
help='Instead of opening shell, execute python code in libtmux and exit',
730-
)
731-
@click.option(
732-
'--use-pythonrc/--no-startup',
733-
'use_pythonrc',
734-
help='Load the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.',
735-
default=False,
736-
)
737-
def command_shell_plus(
738-
session_name,
739-
window_name,
740-
socket_name,
741-
socket_path,
742-
command,
743-
use_pythonrc,
744-
):
745-
"""shell w/ tab completion.
746-
747-
Credits: django-extensions shell_plus.py 51fef74 (MIT License)
748-
"""
749-
server = Server(socket_name=socket_name, socket_path=socket_path)
750-
751-
util.raise_if_tmux_not_running(server=server)
752-
753-
current_pane = util.get_current_pane(server=server)
754-
755-
session = util.get_session(
756-
server=server, session_name=session_name, current_pane=current_pane
757-
)
758-
759-
window = util.get_window(
760-
session=session, window_name=window_name, current_pane=current_pane
761-
)
762-
763-
pane = util.get_pane(window=window, current_pane=current_pane) # NOQA: F841
764-
765-
if command is not None:
766-
exec(command)
767-
else:
768-
# Using normal Python shell
769-
import code
770-
771-
import libtmux
772-
773-
imported_objects = {
774-
'libtmux': libtmux,
775-
'Server': libtmux.Server,
776-
'Session': libtmux.Session,
777-
'Window': libtmux.Window,
778-
'Pane': libtmux.Pane,
779-
'server': server,
780-
'session': session,
781-
'window': window,
782-
'pane': pane,
783-
}
784-
785-
try:
786-
# Try activating rlcompleter, because it's handy.
787-
import readline
788-
except ImportError:
789-
pass
790-
else:
791-
# We don't have to wrap the following import in a 'try', because
792-
# we already know 'readline' was imported successfully.
793-
import rlcompleter
794-
795-
readline.set_completer(rlcompleter.Completer(imported_objects).complete)
796-
# Enable tab completion on systems using libedit (e.g. macOS).
797-
# These lines are copied from Lib/site.py on Python 3.4.
798-
readline_doc = getattr(readline, '__doc__', '')
799-
if readline_doc is not None and 'libedit' in readline_doc:
800-
readline.parse_and_bind("bind ^I rl_complete")
801-
else:
802-
readline.parse_and_bind("tab:complete")
803-
804-
# We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
805-
# conventions and get $PYTHONSTARTUP first then .pythonrc.py.
806-
if use_pythonrc:
807-
for pythonrc in set(
808-
[os.environ.get("PYTHONSTARTUP"), os.path.expanduser('~/.pythonrc.py')]
809-
):
810-
if not pythonrc:
811-
continue
812-
if not os.path.isfile(pythonrc):
813-
continue
814-
with open(pythonrc) as handle:
815-
pythonrc_code = handle.read()
816-
# Match the behavior of the cpython shell where an error in
817-
# PYTHONSTARTUP prints an exception and continues.
818-
try:
819-
exec(compile(pythonrc_code, pythonrc, 'exec'), imported_objects)
820-
except Exception:
821-
import traceback
822-
823-
traceback.print_exc()
824-
825-
code.interact(local=imported_objects)
724+
launch(
725+
server=server,
726+
session=session,
727+
window=window,
728+
pane=pane,
729+
use_pythonrc=use_pythonrc,
730+
)
826731

827732

828733
@cli.command(name='freeze')

0 commit comments

Comments
 (0)