refactoring: move shell to shells.shell to avoid unwanted init (#5556)

Continue #5550 for https://github.com/xonsh/xonsh/issues/5538 

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Noorhteen Raja NJ <jnoortheen@gmail.com>
This commit is contained in:
Andy Kipp 2024-06-29 10:56:50 +02:00 committed by GitHub
parent 7ffce23d29
commit 1d7cc00962
Failed to generate hash of commit
26 changed files with 50 additions and 49 deletions

View file

@ -37,7 +37,7 @@ For those of you who want the gritty details.
xonsh.completer
xonsh.completers
xonsh.prompt
xonsh.shell
xonsh.shells
xonsh.base_shell
xonsh.readline_shell
xonsh.ptk_shell

View file

@ -35,7 +35,7 @@ xmain.setup()
spec = importlib.util.find_spec("prompt_toolkit")
if spec is not None:
# hacky runaround to import PTK-specific events
from xonsh.shell.ptk_shell import events
from xonsh.shells.ptk_shell import events
else:
from xonsh.events import events

View file

@ -26,9 +26,9 @@ readme = {file = ["README.rst"]}
[tool.setuptools]
packages = [
"xonsh",
"xonsh.shells",
"xonsh.shells.ptk_shell",
"xonsh.parsers.ply",
"xonsh.shell",
"xonsh.shell.ptk_shell",
"xonsh.procs",
"xonsh.platform",
"xonsh.parsers",
@ -243,11 +243,11 @@ convention = "numpy"
"xonsh/style_tools.py" = ["F821"]
"xonsh/xoreutils/*.py" = ["E722"]
"xonsh/completers/python.py" = ["E722"]
"xonsh/shells/ptk_shell/__init__.py" = ["E731"]
"xonsh/shells/readline_shell.py" = ["F401"]
"xonsh/parsers/ast.py" = ["F401"]
"xonsh/shell/ptk_shell/__init__.py" = ["E731"]
"xonsh/shell/readline_shell.py" = ["F401"]
"xonsh/commands_cache.py" = ["F841"]
"xonsh/shell/ptk_shell/key_bindings.py" = ["F841"]
"xonsh/shells/ptk_shell/key_bindings.py" = ["F841"]
"xonsh/tools.py" = [
"E731",
]

View file

@ -1,11 +1,11 @@
"""(A down payment on) Testing for ``xonsh.shell.base_shell.BaseShell`` and associated classes"""
"""(A down payment on) Testing for ``xonsh.shells.base_shell.BaseShell`` and associated classes"""
import os
import pytest
from xonsh.shell import transform_command
from xonsh.shell.base_shell import BaseShell
from xonsh.shells.base_shell import BaseShell
from xonsh.shells.shell import transform_command
def test_pwd_tracks_cwd(xession, xonsh_execer, tmpdir_factory, monkeypatch):

View file

@ -8,7 +8,7 @@ from prompt_toolkit.document import Document
from xonsh.aliases import Aliases
from xonsh.completer import Completer
from xonsh.completers.tools import RichCompletion
from xonsh.shell.ptk_shell.completer import PromptToolkitCompleter
from xonsh.shells.ptk_shell.completer import PromptToolkitCompleter
@pytest.mark.parametrize(

View file

@ -9,7 +9,7 @@ except ImportError:
@pytest.fixture
def history_obj():
"""Instantiate `PromptToolkitHistory` and append a line string"""
from xonsh.shell.ptk_shell.history import PromptToolkitHistory
from xonsh.shells.ptk_shell.history import PromptToolkitHistory
hist = PromptToolkitHistory(load_prev=False)
hist.append_string("line10")

View file

@ -17,7 +17,7 @@ Context = namedtuple("Context", ["indent", "buffer", "accept", "cli", "cr"])
def ctx(xession):
"""Context in which the ptk multiline functionality will be tested."""
xession.env["INDENT"] = " "
from xonsh.shell.ptk_shell.key_bindings import carriage_return
from xonsh.shells.ptk_shell.key_bindings import carriage_return
ptk_buffer = Buffer()
ptk_buffer.accept_action = MagicMock(name="accept")
@ -53,14 +53,14 @@ def test_dedent(ctx):
def test_nodedent(ctx):
"""don't dedent if first line of ctx.buffer"""
mock = MagicMock(return_value=True)
with patch("xonsh.shell.ptk_shell.key_bindings.can_compile", mock):
with patch("xonsh.shells.ptk_shell.key_bindings.can_compile", mock):
document = Document("pass")
ctx.buffer.set_document(document)
ctx.cr(ctx.buffer, ctx.cli)
assert ctx.accept.mock_calls is not None
mock = MagicMock(return_value=True)
with patch("xonsh.shell.ptk_shell.key_bindings.can_compile", mock):
with patch("xonsh.shells.ptk_shell.key_bindings.can_compile", mock):
document = Document(ctx.indent + "pass")
ctx.buffer.set_document(document)
ctx.cr(ctx.buffer, ctx.cli)
@ -76,7 +76,7 @@ def test_continuation_line(ctx):
def test_trailing_slash(ctx):
mock = MagicMock(return_value=True)
with patch("xonsh.shell.ptk_shell.key_bindings.can_compile", mock):
with patch("xonsh.shells.ptk_shell.key_bindings.can_compile", mock):
document = Document("this line will \\")
ctx.buffer.set_document(document)
ctx.cr(ctx.buffer, ctx.cli)
@ -88,7 +88,7 @@ def test_trailing_slash(ctx):
def test_cant_compile_newline(ctx):
mock = MagicMock(return_value=False)
with patch("xonsh.shell.ptk_shell.key_bindings.can_compile", mock):
with patch("xonsh.shells.ptk_shell.key_bindings.can_compile", mock):
document = Document("for i in (1, 2, ")
ctx.buffer.set_document(document)
ctx.cr(ctx.buffer, ctx.cli)
@ -97,7 +97,7 @@ def test_cant_compile_newline(ctx):
def test_can_compile_and_executes(ctx):
mock = MagicMock(return_value=True)
with patch("xonsh.shell.ptk_shell.key_bindings.can_compile", mock):
with patch("xonsh.shells.ptk_shell.key_bindings.can_compile", mock):
document = Document("ls")
ctx.buffer.set_document(document)
ctx.cr(ctx.buffer, ctx.cli)

View file

@ -6,8 +6,8 @@ import pyte
import pytest
from xonsh.platform import minimum_required_ptk_version
from xonsh.shell import Shell
from xonsh.shell.ptk_shell import tokenize_ansi
from xonsh.shells.ptk_shell import tokenize_ansi
from xonsh.shells.shell import Shell
# verify error if ptk not installed or below min
@ -51,13 +51,13 @@ def test_prompt_toolkit_version_checks(
return ptk_ver is not None
monkeypatch.setattr(
"xonsh.shell.warnings.warn", mock_warning
"xonsh.shells.shell.warnings.warn", mock_warning
) # hardwon: patch the caller!
monkeypatch.setattr(
"xonsh.shell.ptk_above_min_supported", mock_ptk_above_min_supported
"xonsh.shells.shell.ptk_above_min_supported", mock_ptk_above_min_supported
) # have to patch both callers
monkeypatch.setattr(
"xonsh.platform.ptk_above_min_supported", mock_ptk_above_min_supported
"xonsh.shells.shell.ptk_above_min_supported", mock_ptk_above_min_supported
)
monkeypatch.setattr("xonsh.platform.has_prompt_toolkit", mock_has_prompt_toolkit)

View file

@ -1,7 +1,7 @@
import pytest
from xonsh.completers.tools import RichCompletion
from xonsh.shell.readline_shell import _render_completions
from xonsh.shells.readline_shell import _render_completions
@pytest.mark.parametrize(

View file

@ -1,11 +1,11 @@
"""Testing for ``xonsh.shell.Shell``"""
"""Testing for ``xonsh.shells.Shell``"""
import os
from xonsh.history.dummy import DummyHistory
from xonsh.history.json import JsonHistory
from xonsh.history.sqlite import SqliteHistory
from xonsh.shell import Shell
from xonsh.shells.shell import Shell
def test_shell_with_json_history(xession, xonsh_execer, tmpdir_factory):

View file

@ -1535,7 +1535,7 @@ class PromptSetting(Xettings):
"`prompt_toolkit <https://github.com/jonathanslenders/python-prompt-toolkit>`_"
" library installed. To specify which shell should be used, do so in "
"the run control file. "
"It also accepts a class type that inherits from ``xonsh.shell.base_shell.BaseShell``",
"It also accepts a class type that inherits from ``xonsh.shells.base_shell.BaseShell``",
doc_default="``best``",
)
SUGGEST_COMMANDS = Var.with_default(

View file

@ -22,7 +22,7 @@ from xonsh.lazyimps import pyghooks, pygments
from xonsh.lib.pretty import pretty
from xonsh.platform import HAS_PYGMENTS, ON_WINDOWS
from xonsh.procs.jobs import ignore_sigtstp
from xonsh.shell import Shell
from xonsh.shells.shell import Shell
from xonsh.timings import setup_timings
from xonsh.tools import (
display_error_message,

View file

@ -363,7 +363,7 @@ def ptk_shell(xonsh_execer):
from prompt_toolkit.input import create_pipe_input
from prompt_toolkit.output import DummyOutput
from xonsh.shell.ptk_shell import PromptToolkitShell
from xonsh.shells.ptk_shell import PromptToolkitShell
out = DummyOutput()
with create_pipe_input() as inp:
@ -375,7 +375,7 @@ def ptk_shell(xonsh_execer):
@pytest.fixture
def readline_shell(xonsh_execer, tmpdir, mocker):
from xonsh.shell.readline_shell import ReadlineShell
from xonsh.shells.readline_shell import ReadlineShell
inp_path = tmpdir / "in"
inp = inp_path.open("w+")

View file

@ -12,7 +12,7 @@ from collections import defaultdict
import pytest
from xonsh.shell.base_shell import BaseShell
from xonsh.shells.base_shell import BaseShell
VER_MAJOR_MINOR = sys.version_info[:2]
VER_FULL = sys.version_info[:3]

1
xonsh/shells/__init__.py Normal file
View file

@ -0,0 +1 @@
"""The xonsh interactive shells"""

View file

@ -20,7 +20,7 @@ from xonsh.events import events
from xonsh.lazyimps import pyghooks, pygments
from xonsh.platform import HAS_PYGMENTS, ON_WINDOWS
from xonsh.prompt.base import PromptFormatter, multiline_prompt
from xonsh.shell import transform_command
from xonsh.shells.shell import transform_command
from xonsh.tools import (
DefaultNotGiven,
XonshError,

View file

@ -1,7 +1,7 @@
"""A dumb shell for when $TERM == 'dumb', which usually happens in emacs."""
from xonsh.built_ins import XSH
from xonsh.shell.readline_shell import ReadlineShell
from xonsh.shells.readline_shell import ReadlineShell
class DumbShell(ReadlineShell):

View file

@ -29,12 +29,12 @@ from xonsh.events import events
from xonsh.lazyimps import pyghooks, pygments, winutils
from xonsh.platform import HAS_PYGMENTS, ON_POSIX, ON_WINDOWS
from xonsh.pygments_cache import get_all_styles
from xonsh.shell import transform_command
from xonsh.shell.base_shell import BaseShell
from xonsh.shell.ptk_shell.completer import PromptToolkitCompleter
from xonsh.shell.ptk_shell.formatter import PTKPromptFormatter
from xonsh.shell.ptk_shell.history import PromptToolkitHistory, _cust_history_matches
from xonsh.shell.ptk_shell.key_bindings import load_xonsh_bindings
from xonsh.shells.base_shell import BaseShell
from xonsh.shells.ptk_shell.completer import PromptToolkitCompleter
from xonsh.shells.ptk_shell.formatter import PTKPromptFormatter
from xonsh.shells.ptk_shell.history import PromptToolkitHistory, _cust_history_matches
from xonsh.shells.ptk_shell.key_bindings import load_xonsh_bindings
from xonsh.shells.shell import transform_command
from xonsh.style_tools import DEFAULT_STYLE_DICT, _TokenType, partial_color_tokenize
from xonsh.tools import carriage_return, print_exception, print_warning

View file

@ -4,7 +4,7 @@ import functools
import typing as tp
from xonsh.prompt.base import DEFAULT_PROMPT, PromptFormatter
from xonsh.shell.ptk_shell.updator import AsyncPrompt, PromptUpdator
from xonsh.shells.ptk_shell.updator import AsyncPrompt, PromptUpdator
class PTKPromptFormatter(PromptFormatter):

View file

@ -19,7 +19,7 @@ from prompt_toolkit.keys import Keys
from xonsh.aliases import xonsh_exit
from xonsh.built_ins import XSH
from xonsh.platform import ON_WINDOWS
from xonsh.shell import transform_command
from xonsh.shells.shell import transform_command
from xonsh.tools import (
check_for_partial_string,
ends_with_colon_token,

View file

@ -119,7 +119,7 @@ class AsyncPrompt:
"""Create a timer to update the prompt. The timing can be configured through env variables.
threading.Timer is used to stop calling invalidate frequently.
"""
from xonsh.shell.ptk_shell import tokenize_ansi
from xonsh.shells.ptk_shell import tokenize_ansi
if self.timer:
self.timer.cancel()
@ -158,7 +158,7 @@ class PromptUpdator:
"""Handle updating multiple AsyncPrompt instances prompt/rprompt/bottom_toolbar"""
def __init__(self, shell):
from xonsh.shell.ptk_shell import PromptToolkitShell
from xonsh.shells.ptk_shell import PromptToolkitShell
self.prompts: dict[str, AsyncPrompt] = {}
self.shell: PromptToolkitShell = shell

View file

@ -39,7 +39,7 @@ from xonsh.platform import (
os_environ,
)
from xonsh.prompt.base import multiline_prompt
from xonsh.shell.base_shell import BaseShell
from xonsh.shells.base_shell import BaseShell
from xonsh.tools import (
carriage_return,
columnize,

View file

@ -213,13 +213,13 @@ class Shell:
)
if backend == "none":
from xonsh.shell.base_shell import BaseShell as cls
from xonsh.shells.base_shell import BaseShell as cls
elif backend == "prompt_toolkit" or is_stdin_to_interactive:
from xonsh.shell.ptk_shell import PromptToolkitShell as cls
from xonsh.shells.ptk_shell import PromptToolkitShell as cls
elif backend == "readline":
from xonsh.shell.readline_shell import ReadlineShell as cls
from xonsh.shells.readline_shell import ReadlineShell as cls
elif backend == "dumb":
from xonsh.shell.dumb_shell import DumbShell as cls
from xonsh.shells.dumb_shell import DumbShell as cls
else:
raise XonshError(f"{backend} is not recognized as a shell type")
return cls(**kwargs)

View file

@ -1824,7 +1824,7 @@ def to_completion_mode(x):
def is_tok_color_dict(x):
from pygments.token import _TokenType, string_to_tokentype
from xonsh.shell.ptk_shell import _style_from_pygments_dict
from xonsh.shells.ptk_shell import _style_from_pygments_dict
"""Tests if something is a Token:Style dictionary"""
if not isinstance(x, dict):