diff --git a/.coveragerc b/.coveragerc index 7f6cbab4c..41fbb87e6 100644 --- a/.coveragerc +++ b/.coveragerc @@ -8,7 +8,7 @@ omit = xonsh/lazyasd.py xonsh/parser_table.py xonsh/completion_parser_table.py - xonsh/ply/* + xonsh/parsers/ply/* # keep all cache files in one place data_file = .cache/coverage diff --git a/.gitattributes b/.gitattributes index 5043410c0..63eccdaf0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -22,7 +22,7 @@ Makefile text README text # Files in the lazyjson format require LF line endings -tests/histories/*.json text eol=lf +tests/history/histories/*.json text eol=lf # Binary files *.ico binary diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1160072fa..6cfeb2fe6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2488,7 +2488,7 @@ v0.8.10 terminal to close. This was problematic for certain command pipelines. For example, ``pv /dev/urandom | head`` now works. * Prevents recursive errors from being raised when there is no child process - in ``xonsh.jobs.wait_for_active_job()``. + in ``xonsh.procs.jobs.wait_for_active_job()``. * Tweaked ``xonsh.completers.commands.complete_skipper()`` to insert a space following certain tokens (``&&``, ``||``, ``|``, ``and``, ``or``) to avoid overwriting existing tokens with completer output. diff --git a/docs/api/index.rst b/docs/api/index.rst index 4b7aaa092..475bd2564 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -31,14 +31,13 @@ For those of you who want the gritty details. xonsh.environ xonsh.aliases xonsh.dirstack - xonsh.jobs xonsh.procs xonsh.inspectors xonsh.history xonsh.completer xonsh.completers xonsh.prompt - xonsh.shell + xonsh.shells xonsh.base_shell xonsh.readline_shell xonsh.ptk_shell diff --git a/docs/conf.py b/docs/conf.py index 9abb83c7b..308a69f73 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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.ptk_shell.shell import events + from xonsh.shells.ptk_shell import events else: from xonsh.events import events diff --git a/news/xonsh_refactoring.rst b/news/xonsh_refactoring.rst new file mode 100644 index 000000000..c9b61d190 --- /dev/null +++ b/news/xonsh_refactoring.rst @@ -0,0 +1,25 @@ +**Added:** + +* Starting form ``xonsh.api`` (#5383 #5538). + +**Changed:** + +* Big refactoring of internal modules structure to give clear understanding of internal xonsh components (#5538). + +**Deprecated:** + +* Starting from this release we notify that in the future we will not recommend to use ``xonsh.procs.run_subproc`` + and ``xonsh.built_ins.subproc_*`` functions for downstream projects because of #5383. + We will develop ``xonsh.api`` as alternative. + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/pyproject.toml b/pyproject.toml index d4e462987..d6c9a91d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,8 +26,10 @@ readme = {file = ["README.rst"]} [tool.setuptools] packages = [ "xonsh", - "xonsh.ply.ply", - "xonsh.ptk_shell", + "xonsh.api", + "xonsh.shells", + "xonsh.shells.ptk_shell", + "xonsh.parsers.ply", "xonsh.procs", "xonsh.platform", "xonsh.parsers", @@ -222,7 +224,7 @@ convention = "numpy" [tool.ruff.lint.per-file-ignores] "xonsh/timings.py" = ["F401"] "xonsh/history.py" = ["F821"] -"xonsh/lexer.py" = ["E741"] +"xonsh/parsers/lexer.py" = ["E741"] "xonsh/parsers/completion_context.py" = ["B018"] "xonsh/lib/tokenize.py" = [ "F821", @@ -242,20 +244,20 @@ convention = "numpy" "xonsh/style_tools.py" = ["F821"] "xonsh/xoreutils/*.py" = ["E722"] "xonsh/completers/python.py" = ["E722"] -"xonsh/ptk/shell.py" = ["E731"] -"xonsh/ast.py" = ["F401"] -"xonsh/readline_shell.py" = ["F401"] +"xonsh/parsers/ast.py" = ["F401"] +"xonsh/shells/ptk_shell/__init__.py" = ["E731"] +"xonsh/shells/readline_shell.py" = ["F401"] "xonsh/commands_cache.py" = ["F841"] -"xonsh/ptk/key_bindings.py" = ["F841"] +"xonsh/shells/ptk_shell/key_bindings.py" = ["F841"] "xonsh/tools.py" = [ "E731", ] "xonsh/xonfig.py" = ["E731"] "xontrib/vox.py" = ["F821"] "xonsh/inspectors.py" = ["E722"] -"xonsh/platform/__init__.py" = ["F401"] +"xonsh/platform.py" = ["F401"] "xonsh/parsers/*.py" = [ - "E741", # E741 Ambiguous variable name + "E741", # E741 Ambiguous variable name ] "tests/test*.py" = [ "E741", # E741 Ambiguous variable name diff --git a/setup.cfg b/setup.cfg index fb396157b..7d159b84e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,7 +9,7 @@ warn_no_return = False packages=xonsh,xontrib,xompletions ; a regex to exclude certain directories -exclude = ((xonsh/ply)|(xontrib/(mpl.*py|distributed.py|jedi.py))) +exclude = ((xonsh/parsers/ply)|(xontrib/(mpl.*py|distributed.py|jedi.py))) ;match dmypy semantics - https://github.com/python/mypy/issues/8046 local_partial_types = True @@ -30,7 +30,7 @@ pretty = True ignore_errors = True # 3rd party libraries that we dont have control over -[mypy-zmq.*,setproctitle,xonsh.ply.*,winreg.*,pygments.*,importlib_resources.*,nt.*,prompt_toolkit.*,distro.*,conda_suggest.*,_winreg.*] +[mypy-zmq.*,setproctitle,xonsh.parsers.ply.*,winreg.*,pygments.*,importlib_resources.*,nt.*,prompt_toolkit.*,distro.*,conda_suggest.*,_winreg.*] ignore_missing_imports = True ignore_errors = True diff --git a/setup.py b/setup.py index 22b5ab561..f5f0e1797 100755 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ def build_tables(): print("Building lexer and parser tables.", file=sys.stderr) root_dir = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, root_dir) - from xonsh.parser import Parser + from xonsh.parsers import Parser from xonsh.parsers.completion_context import CompletionContextParser Parser( diff --git a/tests/test_lib/test_os.xsh b/tests/api/test_os.xsh similarity index 96% rename from tests/test_lib/test_os.xsh rename to tests/api/test_os.xsh index eec425a62..51354d1a9 100644 --- a/tests/test_lib/test_os.xsh +++ b/tests/api/test_os.xsh @@ -1,7 +1,7 @@ import os import tempfile -from xonsh.lib.os import indir, rmtree +from xonsh.api.os import indir, rmtree import pytest diff --git a/tests/test_lib/test_subprocess.xsh b/tests/api/test_subprocess.xsh similarity index 94% rename from tests/test_lib/test_subprocess.xsh rename to tests/api/test_subprocess.xsh index aa099c6b3..96f372605 100644 --- a/tests/test_lib/test_subprocess.xsh +++ b/tests/api/test_subprocess.xsh @@ -2,8 +2,8 @@ import tempfile from subprocess import CalledProcessError -from xonsh.lib.os import indir -from xonsh.lib.subprocess import run, check_call, check_output +from xonsh.api.os import indir +from xonsh.api.subprocess import run, check_call, check_output import pytest diff --git a/tests/test_tracer.py b/tests/built_ins/test_tracer.py similarity index 100% rename from tests/test_tracer.py rename to tests/built_ins/test_tracer.py diff --git a/tests/test_wizard.py b/tests/built_ins/test_wizard.py similarity index 100% rename from tests/test_wizard.py rename to tests/built_ins/test_wizard.py diff --git a/tests/test_xonfig.py b/tests/built_ins/test_xonfig.py similarity index 100% rename from tests/test_xonfig.py rename to tests/built_ins/test_xonfig.py diff --git a/tests/test_xontribs.py b/tests/built_ins/test_xontribs.py similarity index 100% rename from tests/test_xontribs.py rename to tests/built_ins/test_xontribs.py diff --git a/tests/histories/echo.json b/tests/history/histories/echo.json similarity index 100% rename from tests/histories/echo.json rename to tests/history/histories/echo.json diff --git a/tests/histories/simple-python.json b/tests/history/histories/simple-python.json similarity index 100% rename from tests/histories/simple-python.json rename to tests/history/histories/simple-python.json diff --git a/tests/test_history_dummy.py b/tests/history/test_history_dummy.py similarity index 100% rename from tests/test_history_dummy.py rename to tests/history/test_history_dummy.py diff --git a/tests/test_history_json.py b/tests/history/test_history_json.py similarity index 99% rename from tests/test_history_json.py rename to tests/history/test_history_json.py index 1ab622a09..fed2eb298 100644 --- a/tests/test_history_json.py +++ b/tests/history/test_history_json.py @@ -14,7 +14,7 @@ from xonsh.history.json import ( _xhj_gc_seconds_to_rmfiles, ) from xonsh.history.main import HistoryAlias, history_main -from xonsh.lazyjson import LazyJSON +from xonsh.lib.lazyjson import LazyJSON CMDS = ["ls", "cat hello kitty", "abc", "def", "touch me", "grep from me"] IGNORE_OPTS = ",".join(["ignoredups", "ignoreerr", "ignorespace"]) diff --git a/tests/test_history_sqlite.py b/tests/history/test_history_sqlite.py similarity index 100% rename from tests/test_history_sqlite.py rename to tests/history/test_history_sqlite.py diff --git a/tests/test_lib/test_collections.py b/tests/lib/test_collections.py similarity index 100% rename from tests/test_lib/test_collections.py rename to tests/lib/test_collections.py diff --git a/tests/test_lib/test_itertools.py b/tests/lib/test_itertools.py similarity index 100% rename from tests/test_lib/test_itertools.py rename to tests/lib/test_itertools.py diff --git a/tests/test_lazyasd.py b/tests/lib/test_lazyasd.py similarity index 81% rename from tests/test_lazyasd.py rename to tests/lib/test_lazyasd.py index c1594ee65..3220ed1fe 100644 --- a/tests/test_lazyasd.py +++ b/tests/lib/test_lazyasd.py @@ -1,6 +1,6 @@ """Tests lazy and self destruictive objects.""" -from xonsh.lazyasd import LazyObject +from xonsh.lib.lazyasd import LazyObject # # LazyObject Tests diff --git a/tests/test_lazyjson.py b/tests/lib/test_lazyjson.py similarity index 98% rename from tests/test_lazyjson.py rename to tests/lib/test_lazyjson.py index ec2d571c1..0b1815127 100644 --- a/tests/test_lazyjson.py +++ b/tests/lib/test_lazyjson.py @@ -2,7 +2,7 @@ from io import StringIO -from xonsh.lazyjson import LazyJSON, LJNode, index, ljdump +from xonsh.lib.lazyjson import LazyJSON, LJNode, index, ljdump def test_index_int(): diff --git a/tests/test_ast.py b/tests/parsers/test_ast.py similarity index 96% rename from tests/test_ast.py rename to tests/parsers/test_ast.py index bee999729..a44040bdf 100644 --- a/tests/test_ast.py +++ b/tests/parsers/test_ast.py @@ -4,8 +4,8 @@ import ast as pyast import pytest -from xonsh import ast -from xonsh.ast import BinOp, Call, Name, Store, Tuple, isexpression, min_line +from xonsh.parsers import ast +from xonsh.parsers.ast import BinOp, Call, Name, Store, Tuple, isexpression, min_line from xonsh.pytest.tools import nodes_equal diff --git a/tests/test_lexer.py b/tests/parsers/test_lexer.py similarity index 98% rename from tests/test_lexer.py rename to tests/parsers/test_lexer.py index ad2096550..21c3a01c4 100644 --- a/tests/test_lexer.py +++ b/tests/parsers/test_lexer.py @@ -4,13 +4,13 @@ import os import sys from collections.abc import Sequence -sys.path.insert(0, os.path.abspath("..")) # FIXME +sys.path.insert(0, os.path.abspath("../..")) # FIXME from pprint import pformat import pytest -from xonsh.lexer import Lexer -from xonsh.ply.ply.lex import LexToken +from xonsh.parsers.lexer import Lexer +from xonsh.parsers.ply.lex import LexToken LEXER_ARGS = {"lextab": "lexer_test_table", "debug": 0} diff --git a/tests/test_parser.py b/tests/parsers/test_parser.py similarity index 99% rename from tests/test_parser.py rename to tests/parsers/test_parser.py index ee131ed8e..7131f9363 100644 --- a/tests/test_parser.py +++ b/tests/parsers/test_parser.py @@ -6,8 +6,8 @@ import textwrap import pytest -from xonsh.ast import AST, Call, Pass, With, is_const_str -from xonsh.parser import Parser +from xonsh.parsers import Parser +from xonsh.parsers.ast import AST, Call, Pass, With, is_const_str from xonsh.parsers.fstring_adaptor import FStringAdaptor from xonsh.pytest.tools import ( VER_MAJOR_MINOR, diff --git a/tests/test_jobs.py b/tests/procs/test_jobs.py similarity index 96% rename from tests/test_jobs.py rename to tests/procs/test_jobs.py index 71da0826f..aa374ed95 100644 --- a/tests/test_jobs.py +++ b/tests/procs/test_jobs.py @@ -1,6 +1,6 @@ import pytest -from xonsh import jobs +from xonsh.procs import jobs @pytest.mark.parametrize( diff --git a/tests/test_pipelines.py b/tests/procs/test_pipelines.py similarity index 98% rename from tests/test_pipelines.py rename to tests/procs/test_pipelines.py index 1cf35d965..089760ecb 100644 --- a/tests/test_pipelines.py +++ b/tests/procs/test_pipelines.py @@ -13,7 +13,7 @@ from xonsh.pytest.tools import skip_if_on_unix, skip_if_on_windows @pytest.fixture(autouse=True) def patched_events(monkeypatch, xonsh_events, xonsh_session): - from xonsh.jobs import get_tasks + from xonsh.procs.jobs import get_tasks get_tasks().clear() # needed for ci tests diff --git a/tests/test_base_shell.py b/tests/shell/test_base_shell.py similarity index 90% rename from tests/test_base_shell.py rename to tests/shell/test_base_shell.py index 24dc29898..139c2d6f7 100644 --- a/tests/test_base_shell.py +++ b/tests/shell/test_base_shell.py @@ -1,11 +1,11 @@ -"""(A down payment on) Testing for ``xonsh.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.base_shell import BaseShell -from xonsh.shell import transform_command +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): diff --git a/tests/test_ptk_completer.py b/tests/shell/test_ptk_completer.py similarity index 98% rename from tests/test_ptk_completer.py rename to tests/shell/test_ptk_completer.py index 4b122825c..75e66e3ab 100644 --- a/tests/test_ptk_completer.py +++ b/tests/shell/test_ptk_completer.py @@ -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.ptk_shell.completer import PromptToolkitCompleter +from xonsh.shells.ptk_shell.completer import PromptToolkitCompleter @pytest.mark.parametrize( diff --git a/tests/test_ptk_highlight.py b/tests/shell/test_ptk_highlight.py similarity index 100% rename from tests/test_ptk_highlight.py rename to tests/shell/test_ptk_highlight.py diff --git a/tests/test_ptk_history.py b/tests/shell/test_ptk_history.py similarity index 88% rename from tests/test_ptk_history.py rename to tests/shell/test_ptk_history.py index e3a974639..664219ab4 100644 --- a/tests/test_ptk_history.py +++ b/tests/shell/test_ptk_history.py @@ -9,7 +9,7 @@ except ImportError: @pytest.fixture def history_obj(): """Instantiate `PromptToolkitHistory` and append a line string""" - from xonsh.ptk_shell.history import PromptToolkitHistory + from xonsh.shells.ptk_shell.history import PromptToolkitHistory hist = PromptToolkitHistory(load_prev=False) hist.append_string("line10") diff --git a/tests/test_ptk_multiline.py b/tests/shell/test_ptk_multiline.py similarity index 87% rename from tests/test_ptk_multiline.py rename to tests/shell/test_ptk_multiline.py index a42edd47d..ba629f5ac 100644 --- a/tests/test_ptk_multiline.py +++ b/tests/shell/test_ptk_multiline.py @@ -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.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.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.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.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.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.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) diff --git a/tests/test_ptk_shell.py b/tests/shell/test_ptk_shell.py similarity index 92% rename from tests/test_ptk_shell.py rename to tests/shell/test_ptk_shell.py index 8e2aeabf5..0edd76c70 100644 --- a/tests/test_ptk_shell.py +++ b/tests/shell/test_ptk_shell.py @@ -6,8 +6,8 @@ import pyte import pytest from xonsh.platform import minimum_required_ptk_version -from xonsh.ptk_shell.shell import tokenize_ansi -from xonsh.shell import Shell +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) diff --git a/tests/test_readline_shell.py b/tests/shell/test_readline_shell.py similarity index 95% rename from tests/test_readline_shell.py rename to tests/shell/test_readline_shell.py index 896185310..ece2ec3bc 100644 --- a/tests/test_readline_shell.py +++ b/tests/shell/test_readline_shell.py @@ -1,7 +1,7 @@ import pytest from xonsh.completers.tools import RichCompletion -from xonsh.readline_shell import _render_completions +from xonsh.shells.readline_shell import _render_completions @pytest.mark.parametrize( diff --git a/tests/test_shell.py b/tests/shell/test_shell.py similarity index 96% rename from tests/test_shell.py rename to tests/shell/test_shell.py index 98a6a176d..a15c480f1 100644 --- a/tests/test_shell.py +++ b/tests/shell/test_shell.py @@ -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): diff --git a/tests/test_integrations.py b/tests/test_integrations.py index b3b033564..dad6860e1 100644 --- a/tests/test_integrations.py +++ b/tests/test_integrations.py @@ -462,7 +462,7 @@ def _echo(args): print(' '.join(args)) aliases['echo'] = _echo -from xonsh.lib.subprocess import check_output +from xonsh.api.subprocess import check_output print(check_output(["echo", "hello"]).decode("utf8")) """, diff --git a/tests/test_pyghooks.py b/tests/test_pyghooks.py index 2e0658479..0f6bead0a 100644 --- a/tests/test_pyghooks.py +++ b/tests/test_pyghooks.py @@ -328,7 +328,7 @@ def test_colorize_file_symlink(key, file_path, colorizable_files, xs_LS_COLORS): assert color_key == tar_color_key, "File classified as expected kind, via symlink" -import xonsh.lazyimps +import xonsh.lib.lazyimps def test_colorize_file_ca(xs_LS_COLORS, monkeypatch): diff --git a/tests/test_tools.py b/tests/test_tools.py index eee08cd65..725bbad4c 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -12,7 +12,7 @@ from tempfile import TemporaryDirectory import pytest from xonsh import __version__ -from xonsh.lexer import Lexer +from xonsh.parsers.lexer import Lexer from xonsh.platform import HAS_PYGMENTS, ON_WINDOWS, PYTHON_VERSION_INFO from xonsh.pytest.tools import skip_if_on_windows from xonsh.tools import ( diff --git a/xonsh/aliases.py b/xonsh/aliases.py index 416ca36ad..a4ed9f805 100644 --- a/xonsh/aliases.py +++ b/xonsh/aliases.py @@ -14,14 +14,13 @@ import typing as tp import xonsh.completers._aliases as xca import xonsh.history.main as xhm import xonsh.xoreutils.which as xxw -from xonsh.ast import isexpression from xonsh.built_ins import XSH from xonsh.cli_utils import Annotated, Arg, ArgParserAlias from xonsh.dirstack import _get_cwd, cd, dirs, popd, pushd from xonsh.environ import locate_binary, make_args_env from xonsh.foreign_shells import foreign_shell_data -from xonsh.jobs import bg, clean_jobs, disown, fg, jobs -from xonsh.lazyasd import lazyobject +from xonsh.lib.lazyasd import lazyobject +from xonsh.parsers.ast import isexpression from xonsh.platform import ( IN_APPIMAGE, ON_ANACONDA, @@ -32,6 +31,7 @@ from xonsh.platform import ( ON_OPENBSD, ON_WINDOWS, ) +from xonsh.procs.jobs import bg, clean_jobs, disown, fg, jobs from xonsh.procs.specs import SpecAttrModifierAlias, SpecModifierAlias from xonsh.timings import timeit_alias from xonsh.tools import ( diff --git a/xonsh/ansi_colors.py b/xonsh/ansi_colors.py index d0b4c402e..6f001d614 100644 --- a/xonsh/ansi_colors.py +++ b/xonsh/ansi_colors.py @@ -16,7 +16,7 @@ from xonsh.color_tools import ( short_to_ints, warn_deprecated_no_color, ) -from xonsh.lazyasd import LazyDict, lazyobject +from xonsh.lib.lazyasd import LazyDict, lazyobject from xonsh.platform import HAS_PYGMENTS from xonsh.tools import FORMATTER diff --git a/xonsh/api/__init__.py b/xonsh/api/__init__.py new file mode 100644 index 000000000..26083fe66 --- /dev/null +++ b/xonsh/api/__init__.py @@ -0,0 +1,8 @@ +""" +Originally posted in https://github.com/xonsh/xonsh/issues/2726#issuecomment-406447196 : + Recently @CJ-Wright has started up a ``xonsh.lib`` (``xonsh.api``) sub-package, which is usable from pure Python. + This is meant as a standard library for xonsh and downstream tools. + Currently there are some xonsh-ish wrappers around ``os`` and ``subprocess``. + We'd love to see more contributions to this effort! So if there is something + like ``sh()`` that you'd like to see, by all means please help us add it! +""" diff --git a/xonsh/lib/os.py b/xonsh/api/os.py similarity index 100% rename from xonsh/lib/os.py rename to xonsh/api/os.py diff --git a/xonsh/lib/subprocess.py b/xonsh/api/subprocess.py similarity index 97% rename from xonsh/lib/subprocess.py rename to xonsh/api/subprocess.py index a557fa11a..4c6bd32a3 100644 --- a/xonsh/lib/subprocess.py +++ b/xonsh/api/subprocess.py @@ -1,8 +1,8 @@ """Xonsh extension of the standard library subprocess module, using xonsh for subprocess calls""" +from xonsh.api.os import indir from xonsh.built_ins import XSH, subproc_captured_hiddenobject, subproc_captured_stdout -from xonsh.lib.os import indir def run(cmd, cwd=None, check=False): diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py index c12984a62..4a9262a90 100644 --- a/xonsh/built_ins.py +++ b/xonsh/built_ins.py @@ -19,8 +19,8 @@ import types import warnings from ast import AST -from xonsh.lazyasd import lazyobject from xonsh.lib.inspectors import Inspector +from xonsh.lib.lazyasd import lazyobject from xonsh.platform import ON_POSIX from xonsh.tools import ( XonshCalledProcessError, diff --git a/xonsh/codecache.py b/xonsh/codecache.py index be163eac5..d9698768c 100644 --- a/xonsh/codecache.py +++ b/xonsh/codecache.py @@ -7,7 +7,7 @@ import sys from xonsh import __version__ as XONSH_VERSION from xonsh.built_ins import XSH -from xonsh.lazyasd import lazyobject +from xonsh.lib.lazyasd import lazyobject from xonsh.platform import PYTHON_VERSION_INFO_BYTES from xonsh.tools import is_writable_file, print_warning diff --git a/xonsh/color_tools.py b/xonsh/color_tools.py index 1c61fa0ee..beee7b0f6 100644 --- a/xonsh/color_tools.py +++ b/xonsh/color_tools.py @@ -9,7 +9,7 @@ WTFPL http://sam.zoy.org/wtfpl/ import math import re -from xonsh.lazyasd import LazyObject, lazyobject +from xonsh.lib.lazyasd import LazyObject, lazyobject from xonsh.tools import print_warning _NO_COLOR_WARNING_SHOWN = False diff --git a/xonsh/commands_cache.py b/xonsh/commands_cache.py index 8abdfb330..cfa32d16e 100644 --- a/xonsh/commands_cache.py +++ b/xonsh/commands_cache.py @@ -14,7 +14,7 @@ import time import typing as tp from pathlib import Path -from xonsh.lazyasd import lazyobject +from xonsh.lib.lazyasd import lazyobject from xonsh.platform import ON_POSIX, ON_WINDOWS, pathbasename from xonsh.tools import executables_in diff --git a/xonsh/completers/imports.py b/xonsh/completers/imports.py index 3c82c2afe..a7e8f89c2 100644 --- a/xonsh/completers/imports.py +++ b/xonsh/completers/imports.py @@ -21,7 +21,7 @@ from xonsh.completers.tools import ( contextual_completer, get_filter_function, ) -from xonsh.lazyasd import lazyobject +from xonsh.lib.lazyasd import lazyobject from xonsh.parsers.completion_context import CompletionContext _suffixes = all_suffixes() diff --git a/xonsh/completers/path.py b/xonsh/completers/path.py index da275d97c..7e1a3559f 100644 --- a/xonsh/completers/path.py +++ b/xonsh/completers/path.py @@ -3,7 +3,7 @@ import glob import os import re -import xonsh.lazyasd as xl +import xonsh.lib.lazyasd as xl import xonsh.platform as xp import xonsh.tools as xt from xonsh.built_ins import XSH diff --git a/xonsh/completers/python.py b/xonsh/completers/python.py index 467d58876..42b9a0952 100644 --- a/xonsh/completers/python.py +++ b/xonsh/completers/python.py @@ -6,7 +6,7 @@ import inspect import re import warnings -import xonsh.lazyasd as xl +import xonsh.lib.lazyasd as xl import xonsh.tools as xt from xonsh.built_ins import XSH from xonsh.completers.tools import ( diff --git a/xonsh/completers/tools.py b/xonsh/completers/tools.py index f686f0adc..48ddeb908 100644 --- a/xonsh/completers/tools.py +++ b/xonsh/completers/tools.py @@ -10,7 +10,7 @@ from functools import wraps import xonsh.tools as xt from xonsh.built_ins import XSH -from xonsh.lazyasd import lazyobject +from xonsh.lib.lazyasd import lazyobject from xonsh.parsers.completion_context import CommandContext, CompletionContext diff --git a/xonsh/environ.py b/xonsh/environ.py index 35e8f6cd5..87c29e8a5 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -29,7 +29,7 @@ from xonsh.built_ins import XSH from xonsh.codecache import run_script_with_cache from xonsh.dirstack import _get_cwd from xonsh.events import events -from xonsh.lazyasd import LazyBool, lazyobject +from xonsh.lib.lazyasd import LazyBool, lazyobject from xonsh.platform import ( BASH_COMPLETIONS_DEFAULT, DEFAULT_ENCODING, @@ -1535,7 +1535,7 @@ class PromptSetting(Xettings): "`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.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( diff --git a/xonsh/execer.py b/xonsh/execer.py index 741f06212..9ec9608f9 100644 --- a/xonsh/execer.py +++ b/xonsh/execer.py @@ -6,8 +6,8 @@ import inspect import sys import types -from xonsh.ast import CtxAwareTransformer -from xonsh.parser import Parser +from xonsh.parsers import Parser +from xonsh.parsers.ast import CtxAwareTransformer from xonsh.tools import ( balanced_parens, ends_with_colon_token, diff --git a/xonsh/foreign_shells.py b/xonsh/foreign_shells.py index c85ee6c5a..ea72d92fe 100644 --- a/xonsh/foreign_shells.py +++ b/xonsh/foreign_shells.py @@ -11,7 +11,7 @@ import tempfile import warnings from xonsh.built_ins import XSH -from xonsh.lazyasd import lazyobject +from xonsh.lib.lazyasd import lazyobject from xonsh.platform import ON_CYGWIN, ON_MSYS, ON_WINDOWS from xonsh.tools import ensure_string, to_bool diff --git a/xonsh/history/diff_history.py b/xonsh/history/diff_history.py index 6093b5543..2be9ed3b4 100644 --- a/xonsh/history/diff_history.py +++ b/xonsh/history/diff_history.py @@ -5,7 +5,7 @@ import difflib import itertools from xonsh.color_tools import COLORS -from xonsh.lazyjson import LazyJSON +from xonsh.lib.lazyjson import LazyJSON # intern some strings REPLACE_S = "replace" diff --git a/xonsh/history/json.py b/xonsh/history/json.py index b72f3de40..f64983757 100644 --- a/xonsh/history/json.py +++ b/xonsh/history/json.py @@ -19,7 +19,7 @@ except ImportError: JSONDecodeError = json.decoder.JSONDecodeError # type: ignore -import xonsh.lazyjson as xlj +import xonsh.lib.lazyjson as xlj import xonsh.tools as xt import xonsh.xoreutils.uptime as uptime from xonsh.history.base import History diff --git a/xonsh/imphooks.py b/xonsh/imphooks.py index c61f577d8..9fe0efda8 100644 --- a/xonsh/imphooks.py +++ b/xonsh/imphooks.py @@ -15,7 +15,7 @@ from importlib.machinery import ModuleSpec from xonsh.built_ins import XSH from xonsh.events import events from xonsh.execer import Execer -from xonsh.lazyasd import lazyobject +from xonsh.lib.lazyasd import lazyobject from xonsh.platform import ON_WINDOWS from xonsh.tools import print_warning diff --git a/xonsh/lib/__init__.py b/xonsh/lib/__init__.py index 327fb4ced..9d378eb6a 100644 --- a/xonsh/lib/__init__.py +++ b/xonsh/lib/__init__.py @@ -1,9 +1 @@ -""" -Originally posted by @scopatz in https://github.com/xonsh/xonsh/issues/2726#issuecomment-406447196 : - - Recently @CJ-Wright has started up a ``xonsh.lib`` sub-package, which is usable from pure Python. - This is meant as a standard library for xonsh and downstream tools. - Currently there are some xonsh-ish wrappers around ``os`` and ``subprocess``. - We'd love to see more contributions to this effort! So if there is something - like ``sh()`` that you'd like to see, by all means please help us add it! -""" +"""Libraries of common functions that used in xonsh components as well as modules borrowed from other projects.""" diff --git a/xonsh/lib/inspectors.py b/xonsh/lib/inspectors.py index cb2b24a81..aeb21b7fe 100644 --- a/xonsh/lib/inspectors.py +++ b/xonsh/lib/inspectors.py @@ -15,8 +15,8 @@ import os import sys import types -from xonsh.lazyasd import LazyObject -from xonsh.lazyimps import pyghooks, pygments +from xonsh.lib.lazyasd import LazyObject +from xonsh.lib.lazyimps import pyghooks, pygments from xonsh.lib.openpy import read_py_file from xonsh.lib.tokenize import detect_encoding from xonsh.platform import HAS_PYGMENTS diff --git a/xonsh/lazyasd.py b/xonsh/lib/lazyasd.py similarity index 100% rename from xonsh/lazyasd.py rename to xonsh/lib/lazyasd.py diff --git a/xonsh/lazyimps.py b/xonsh/lib/lazyimps.py similarity index 96% rename from xonsh/lazyimps.py rename to xonsh/lib/lazyimps.py index 3ef390884..9d0fa27d6 100644 --- a/xonsh/lazyimps.py +++ b/xonsh/lib/lazyimps.py @@ -3,7 +3,7 @@ import importlib import os -from xonsh.lazyasd import LazyObject, lazyobject +from xonsh.lib.lazyasd import LazyObject, lazyobject from xonsh.platform import ON_DARWIN, ON_WINDOWS pygments = LazyObject( diff --git a/xonsh/lazyjson.py b/xonsh/lib/lazyjson.py similarity index 100% rename from xonsh/lazyjson.py rename to xonsh/lib/lazyjson.py diff --git a/xonsh/lib/openpy.py b/xonsh/lib/openpy.py index 98edd0570..dab87a7a1 100644 --- a/xonsh/lib/openpy.py +++ b/xonsh/lib/openpy.py @@ -15,7 +15,7 @@ This file was forked from the IPython project: import io import re -from xonsh.lazyasd import LazyObject +from xonsh.lib.lazyasd import LazyObject from xonsh.lib.tokenize import detect_encoding, tokopen cookie_comment_re = LazyObject( diff --git a/xonsh/lib/pretty.py b/xonsh/lib/pretty.py index 3406d4c76..b3126547a 100644 --- a/xonsh/lib/pretty.py +++ b/xonsh/lib/pretty.py @@ -86,7 +86,7 @@ import re import sys import types -from xonsh.lazyasd import LazyObject, lazyobject +from xonsh.lib.lazyasd import LazyObject, lazyobject __all__ = [ "pretty", diff --git a/xonsh/lib/tokenize.py b/xonsh/lib/tokenize.py index b2fdc1f1b..7a11aa17a 100644 --- a/xonsh/lib/tokenize.py +++ b/xonsh/lib/tokenize.py @@ -81,7 +81,7 @@ from token import ( tok_name, ) -from xonsh.lazyasd import LazyObject +from xonsh.lib.lazyasd import LazyObject from xonsh.platform import PYTHON_VERSION_INFO cookie_re = LazyObject( diff --git a/xonsh/main.py b/xonsh/main.py index 3037a0edf..7585ca6c6 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -17,12 +17,12 @@ from xonsh.environ import get_home_xonshrc_path, make_args_env, xonshrc_context from xonsh.events import events from xonsh.execer import Execer from xonsh.imphooks import install_import_hooks -from xonsh.jobs import ignore_sigtstp -from xonsh.lazyasd import lazyobject -from xonsh.lazyimps import pyghooks, pygments +from xonsh.lib.lazyasd import lazyobject +from xonsh.lib.lazyimps import pyghooks, pygments from xonsh.lib.pretty import pretty from xonsh.platform import HAS_PYGMENTS, ON_WINDOWS -from xonsh.shell import Shell +from xonsh.procs.jobs import ignore_sigtstp +from xonsh.shells.shell import Shell from xonsh.timings import setup_timings from xonsh.tools import ( display_error_message, diff --git a/xonsh/parser.py b/xonsh/parser.py deleted file mode 100644 index 3916b0d73..000000000 --- a/xonsh/parser.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Implements the xonsh parser.""" - -from xonsh.lazyasd import lazyobject -from xonsh.platform import PYTHON_VERSION_INFO - - -@lazyobject -def Parser(): - if PYTHON_VERSION_INFO > (3, 10): - from xonsh.parsers.v310 import Parser as p - elif PYTHON_VERSION_INFO > (3, 9): - from xonsh.parsers.v39 import Parser as p - elif PYTHON_VERSION_INFO > (3, 8): - from xonsh.parsers.v38 import Parser as p - else: - from xonsh.parsers.v36 import Parser as p - return p diff --git a/xonsh/parsers/__init__.py b/xonsh/parsers/__init__.py index e69de29bb..8d6b0f24c 100644 --- a/xonsh/parsers/__init__.py +++ b/xonsh/parsers/__init__.py @@ -0,0 +1,17 @@ +"""Implements the xonsh parser.""" + +from xonsh.lib.lazyasd import lazyobject +from xonsh.platform import PYTHON_VERSION_INFO + + +@lazyobject +def Parser(): + if PYTHON_VERSION_INFO > (3, 10): + from xonsh.parsers.v310 import Parser as p + elif PYTHON_VERSION_INFO > (3, 9): + from xonsh.parsers.v39 import Parser as p + elif PYTHON_VERSION_INFO > (3, 8): + from xonsh.parsers.v38 import Parser as p + else: + from xonsh.parsers.v36 import Parser as p + return p diff --git a/xonsh/ast.py b/xonsh/parsers/ast.py similarity index 99% rename from xonsh/ast.py rename to xonsh/parsers/ast.py index 22fefc161..bd5833737 100644 --- a/xonsh/ast.py +++ b/xonsh/parsers/ast.py @@ -4,10 +4,8 @@ # pylint: disable=unused-import import itertools import sys - -# pylint: enable=unused-import import textwrap -from ast import ( +from ast import ( # noqa # pylint: disable=unused-import AST, Add, And, diff --git a/xonsh/parsers/base.py b/xonsh/parsers/base.py index 7a034334d..f519b0d90 100644 --- a/xonsh/parsers/base.py +++ b/xonsh/parsers/base.py @@ -10,15 +10,15 @@ from ast import parse as pyparse from collections.abc import Iterable, Mapping, Sequence from threading import Thread -from xonsh import ast -from xonsh.ast import has_elts, load_attribute_chain, xonsh_call -from xonsh.lazyasd import LazyObject -from xonsh.lexer import Lexer, LexToken +from xonsh.lib.lazyasd import LazyObject from xonsh.lib.tokenize import SearchPath, StringPrefix +from xonsh.parsers import ast +from xonsh.parsers.ast import has_elts, load_attribute_chain, xonsh_call from xonsh.parsers.context_check import check_contexts from xonsh.parsers.fstring_adaptor import FStringAdaptor +from xonsh.parsers.lexer import Lexer, LexToken +from xonsh.parsers.ply import yacc from xonsh.platform import PYTHON_VERSION_INFO -from xonsh.ply.ply import yacc RE_SEARCHPATH = LazyObject(lambda: re.compile(SearchPath), globals(), "RE_SEARCHPATH") RE_STRINGPREFIX = LazyObject( diff --git a/xonsh/parsers/completion_context.py b/xonsh/parsers/completion_context.py index c31593c80..f296d37a8 100644 --- a/xonsh/parsers/completion_context.py +++ b/xonsh/parsers/completion_context.py @@ -17,10 +17,10 @@ from typing import ( overload, ) -from xonsh.lazyasd import lazyobject -from xonsh.lexer import Lexer +from xonsh.lib.lazyasd import lazyobject from xonsh.parsers.base import Location, raise_parse_error -from xonsh.ply.ply import yacc +from xonsh.parsers.lexer import Lexer +from xonsh.parsers.ply import yacc from xonsh.tools import check_for_partial_string, get_line_continuation diff --git a/xonsh/parsers/context_check.py b/xonsh/parsers/context_check.py index d8b35f12a..b678ecc7f 100644 --- a/xonsh/parsers/context_check.py +++ b/xonsh/parsers/context_check.py @@ -2,7 +2,7 @@ import ast import collections import keyword -from xonsh import ast as xast +from xonsh.parsers import ast as xast _all_keywords = frozenset(keyword.kwlist) diff --git a/xonsh/parsers/fstring_adaptor.py b/xonsh/parsers/fstring_adaptor.py index c4fb1da32..f9768eb1d 100644 --- a/xonsh/parsers/fstring_adaptor.py +++ b/xonsh/parsers/fstring_adaptor.py @@ -3,8 +3,8 @@ import re from ast import parse as pyparse -from xonsh import ast -from xonsh.lazyasd import lazyobject +from xonsh.lib.lazyasd import lazyobject +from xonsh.parsers import ast from xonsh.platform import PYTHON_VERSION_INFO diff --git a/xonsh/lexer.py b/xonsh/parsers/lexer.py similarity index 99% rename from xonsh/lexer.py rename to xonsh/parsers/lexer.py index 60fe33c15..3b3ed1fda 100644 --- a/xonsh/lexer.py +++ b/xonsh/parsers/lexer.py @@ -10,7 +10,7 @@ import keyword as kwmod import re import typing as tp -from xonsh.lazyasd import lazyobject +from xonsh.lib.lazyasd import lazyobject from xonsh.lib.tokenize import ( CASE, COMMENT, @@ -36,8 +36,8 @@ from xonsh.lib.tokenize import ( TokenError, tokenize, ) +from xonsh.parsers.ply.lex import LexToken from xonsh.platform import PYTHON_VERSION_INFO -from xonsh.ply.ply.lex import LexToken @lazyobject diff --git a/xonsh/ply/ply/__init__.py b/xonsh/parsers/ply/__init__.py similarity index 100% rename from xonsh/ply/ply/__init__.py rename to xonsh/parsers/ply/__init__.py diff --git a/xonsh/ply/ply/cpp.py b/xonsh/parsers/ply/cpp.py similarity index 100% rename from xonsh/ply/ply/cpp.py rename to xonsh/parsers/ply/cpp.py diff --git a/xonsh/ply/ply/ctokens.py b/xonsh/parsers/ply/ctokens.py similarity index 100% rename from xonsh/ply/ply/ctokens.py rename to xonsh/parsers/ply/ctokens.py diff --git a/xonsh/ply/ply/lex.py b/xonsh/parsers/ply/lex.py similarity index 100% rename from xonsh/ply/ply/lex.py rename to xonsh/parsers/ply/lex.py diff --git a/xonsh/ply/ply/yacc.py b/xonsh/parsers/ply/yacc.py similarity index 100% rename from xonsh/ply/ply/yacc.py rename to xonsh/parsers/ply/yacc.py diff --git a/xonsh/ply/ply/ygen.py b/xonsh/parsers/ply/ygen.py similarity index 100% rename from xonsh/ply/ply/ygen.py rename to xonsh/parsers/ply/ygen.py diff --git a/xonsh/parsers/v310.py b/xonsh/parsers/v310.py index eabdd3e93..b5ac4ce48 100644 --- a/xonsh/parsers/v310.py +++ b/xonsh/parsers/v310.py @@ -10,8 +10,8 @@ handle import ast +from xonsh.parsers.ply import yacc from xonsh.parsers.v39 import Parser as ThreeNineParser -from xonsh.ply.ply import yacc class Parser(ThreeNineParser): diff --git a/xonsh/parsers/v36.py b/xonsh/parsers/v36.py index 7319ea3e2..871d2f99e 100644 --- a/xonsh/parsers/v36.py +++ b/xonsh/parsers/v36.py @@ -1,6 +1,6 @@ """Implements the xonsh parser for Python v3.6.""" -import xonsh.ast as ast +import xonsh.parsers.ast as ast from xonsh.parsers.base import BaseParser, lopen_loc, store_ctx diff --git a/xonsh/parsers/v38.py b/xonsh/parsers/v38.py index afec88c70..55ab765a6 100644 --- a/xonsh/parsers/v38.py +++ b/xonsh/parsers/v38.py @@ -1,6 +1,6 @@ """Implements the xonsh parser for Python v3.8.""" -import xonsh.ast as ast +import xonsh.parsers.ast as ast from xonsh.parsers.base import store_ctx from xonsh.parsers.v36 import Parser as ThreeSixParser diff --git a/xonsh/platform/__init__.py b/xonsh/platform/__init__.py index b57ac9407..1fecfe451 100644 --- a/xonsh/platform/__init__.py +++ b/xonsh/platform/__init__.py @@ -14,7 +14,7 @@ import signal import subprocess import sys -from xonsh.lazyasd import LazyBool, lazybool, lazyobject +from xonsh.lib.lazyasd import LazyBool, lazybool, lazyobject # do not import any xonsh-modules here to avoid circular dependencies diff --git a/xonsh/platform/winutils.py b/xonsh/platform/winutils.py index 438b4324c..ddaff5eaf 100644 --- a/xonsh/platform/winutils.py +++ b/xonsh/platform/winutils.py @@ -40,8 +40,9 @@ from ctypes.wintypes import ( WORD, ) -from xonsh import lazyimps, platform -from xonsh.lazyasd import lazyobject +from xonsh import platform +from xonsh.lib import lazyimps +from xonsh.lib.lazyasd import lazyobject __all__ = ("sudo",) diff --git a/xonsh/jobs.py b/xonsh/procs/jobs.py similarity index 99% rename from xonsh/jobs.py rename to xonsh/procs/jobs.py index 2f490b175..3c7433392 100644 --- a/xonsh/jobs.py +++ b/xonsh/procs/jobs.py @@ -14,7 +14,7 @@ import typing as tp from xonsh.built_ins import XSH from xonsh.cli_utils import Annotated, Arg, ArgParserAlias from xonsh.completers.tools import RichCompletion -from xonsh.lazyasd import LazyObject +from xonsh.lib.lazyasd import LazyObject from xonsh.platform import FD_STDERR, LIBC, ON_CYGWIN, ON_DARWIN, ON_MSYS, ON_WINDOWS from xonsh.tools import get_signal_name, on_main_thread, unthreadable diff --git a/xonsh/procs/pipelines.py b/xonsh/procs/pipelines.py index 6262c5c06..80f22f87b 100644 --- a/xonsh/procs/pipelines.py +++ b/xonsh/procs/pipelines.py @@ -9,9 +9,9 @@ import sys import threading import time -import xonsh.jobs as xj -import xonsh.lazyasd as xl +import xonsh.lib.lazyasd as xl import xonsh.platform as xp +import xonsh.procs.jobs as xj import xonsh.tools as xt from xonsh.built_ins import XSH from xonsh.procs.readers import ConsoleParallelReader, NonBlockingFDReader, safe_fdclose diff --git a/xonsh/procs/posix.py b/xonsh/procs/posix.py index 209d4d2a4..93b9fce63 100644 --- a/xonsh/procs/posix.py +++ b/xonsh/procs/posix.py @@ -9,12 +9,12 @@ import sys import threading import time -import xonsh.lazyasd as xl -import xonsh.lazyimps as xli +import xonsh.lib.lazyasd as xl +import xonsh.lib.lazyimps as xli import xonsh.platform as xp import xonsh.tools as xt from xonsh.built_ins import XSH -from xonsh.jobs import proc_untraced_waitpid +from xonsh.procs.jobs import proc_untraced_waitpid from xonsh.procs.readers import ( BufferedFDParallelReader, NonBlockingFDReader, diff --git a/xonsh/procs/proxies.py b/xonsh/procs/proxies.py index 37243285c..6add535ab 100644 --- a/xonsh/procs/proxies.py +++ b/xonsh/procs/proxies.py @@ -16,7 +16,7 @@ import sys import threading import time -import xonsh.lazyimps as xli +import xonsh.lib.lazyimps as xli import xonsh.platform as xp import xonsh.tools as xt from xonsh.built_ins import XSH diff --git a/xonsh/procs/readers.py b/xonsh/procs/readers.py index 75eb570e9..16bd8bf0d 100644 --- a/xonsh/procs/readers.py +++ b/xonsh/procs/readers.py @@ -8,7 +8,7 @@ import sys import threading import time -import xonsh.lazyimps as xli +import xonsh.lib.lazyimps as xli from xonsh.built_ins import XSH diff --git a/xonsh/procs/specs.py b/xonsh/procs/specs.py index b3fd6bccc..d16c6d3ce 100644 --- a/xonsh/procs/specs.py +++ b/xonsh/procs/specs.py @@ -13,10 +13,10 @@ import subprocess import sys import xonsh.environ as xenv -import xonsh.jobs as xj -import xonsh.lazyasd as xl -import xonsh.lazyimps as xli +import xonsh.lib.lazyasd as xl +import xonsh.lib.lazyimps as xli import xonsh.platform as xp +import xonsh.procs.jobs as xj import xonsh.tools as xt from xonsh.built_ins import XSH from xonsh.procs.pipelines import ( diff --git a/xonsh/prompt/vc.py b/xonsh/prompt/vc.py index f1b16fab7..7bf145d29 100644 --- a/xonsh/prompt/vc.py +++ b/xonsh/prompt/vc.py @@ -12,7 +12,7 @@ import threading import xonsh.tools as xt from xonsh.built_ins import XSH -from xonsh.lazyasd import LazyObject +from xonsh.lib.lazyasd import LazyObject RE_REMOVE_ANSI = LazyObject( lambda: re.compile(r"(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]"), diff --git a/xonsh/ptk_shell/__init__.py b/xonsh/ptk_shell/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/xonsh/pyghooks.py b/xonsh/pyghooks.py index eae403127..13e3882e3 100644 --- a/xonsh/pyghooks.py +++ b/xonsh/pyghooks.py @@ -40,8 +40,8 @@ from xonsh.color_tools import ( ) from xonsh.commands_cache import CommandsCache from xonsh.events import events -from xonsh.lazyasd import LazyDict, LazyObject, lazyobject -from xonsh.lazyimps import html, os_listxattr, terminal256 +from xonsh.lib.lazyasd import LazyDict, LazyObject, lazyobject +from xonsh.lib.lazyimps import html, os_listxattr, terminal256 from xonsh.platform import ( os_environ, ptk_version_info, diff --git a/xonsh/pytest/plugin.py b/xonsh/pytest/plugin.py index 08aff1798..91be2de2f 100644 --- a/xonsh/pytest/plugin.py +++ b/xonsh/pytest/plugin.py @@ -19,9 +19,9 @@ from xonsh.built_ins import XSH, XonshSession from xonsh.completer import Completer from xonsh.events import events from xonsh.execer import Execer -from xonsh.jobs import get_tasks from xonsh.main import setup from xonsh.parsers.completion_context import CompletionContextParser +from xonsh.procs.jobs import get_tasks from .tools import DummyHistory, DummyShell, copy_env, sp @@ -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.ptk_shell.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.readline_shell import ReadlineShell + from xonsh.shells.readline_shell import ReadlineShell inp_path = tmpdir / "in" inp = inp_path.open("w+") diff --git a/xonsh/pytest/tools.py b/xonsh/pytest/tools.py index 9b8d82d6c..63caa19a8 100644 --- a/xonsh/pytest/tools.py +++ b/xonsh/pytest/tools.py @@ -12,7 +12,7 @@ from collections import defaultdict import pytest -from xonsh.base_shell import BaseShell +from xonsh.shells.base_shell import BaseShell VER_MAJOR_MINOR = sys.version_info[:2] VER_FULL = sys.version_info[:3] diff --git a/xonsh/shells/__init__.py b/xonsh/shells/__init__.py new file mode 100644 index 000000000..007bcc2fd --- /dev/null +++ b/xonsh/shells/__init__.py @@ -0,0 +1 @@ +"""The xonsh interactive shells""" diff --git a/xonsh/base_shell.py b/xonsh/shells/base_shell.py similarity index 99% rename from xonsh/base_shell.py rename to xonsh/shells/base_shell.py index 23659a342..5d26da6c7 100644 --- a/xonsh/base_shell.py +++ b/xonsh/shells/base_shell.py @@ -17,10 +17,10 @@ from xonsh.codecache import ( ) from xonsh.completer import Completer from xonsh.events import events -from xonsh.lazyimps import pyghooks, pygments +from xonsh.lib.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, diff --git a/xonsh/dumb_shell.py b/xonsh/shells/dumb_shell.py similarity index 86% rename from xonsh/dumb_shell.py rename to xonsh/shells/dumb_shell.py index 840a050b0..514126417 100644 --- a/xonsh/dumb_shell.py +++ b/xonsh/shells/dumb_shell.py @@ -1,7 +1,7 @@ """A dumb shell for when $TERM == 'dumb', which usually happens in emacs.""" from xonsh.built_ins import XSH -from xonsh.readline_shell import ReadlineShell +from xonsh.shells.readline_shell import ReadlineShell class DumbShell(ReadlineShell): diff --git a/xonsh/ptk_shell/shell.py b/xonsh/shells/ptk_shell/__init__.py similarity index 98% rename from xonsh/ptk_shell/shell.py rename to xonsh/shells/ptk_shell/__init__.py index c50afbd57..5ee5d770a 100644 --- a/xonsh/ptk_shell/shell.py +++ b/xonsh/shells/ptk_shell/__init__.py @@ -24,17 +24,17 @@ from prompt_toolkit.shortcuts.prompt import PromptSession from prompt_toolkit.styles import Style, merge_styles from prompt_toolkit.styles.pygments import pygments_token_to_classname -from xonsh.base_shell import BaseShell from xonsh.built_ins import XSH from xonsh.events import events -from xonsh.lazyimps import pyghooks, pygments, winutils +from xonsh.lib.lazyimps import pyghooks, pygments, winutils from xonsh.platform import HAS_PYGMENTS, ON_POSIX, ON_WINDOWS -from xonsh.ptk_shell.completer import PromptToolkitCompleter -from xonsh.ptk_shell.formatter import PTKPromptFormatter -from xonsh.ptk_shell.history import PromptToolkitHistory, _cust_history_matches -from xonsh.ptk_shell.key_bindings import load_xonsh_bindings from xonsh.pygments_cache import get_all_styles -from xonsh.shell import transform_command +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 diff --git a/xonsh/ptk_shell/completer.py b/xonsh/shells/ptk_shell/completer.py similarity index 100% rename from xonsh/ptk_shell/completer.py rename to xonsh/shells/ptk_shell/completer.py diff --git a/xonsh/ptk_shell/formatter.py b/xonsh/shells/ptk_shell/formatter.py similarity index 96% rename from xonsh/ptk_shell/formatter.py rename to xonsh/shells/ptk_shell/formatter.py index 2d40a4eee..adfac08f6 100644 --- a/xonsh/ptk_shell/formatter.py +++ b/xonsh/shells/ptk_shell/formatter.py @@ -4,7 +4,7 @@ import functools import typing as tp from xonsh.prompt.base import DEFAULT_PROMPT, PromptFormatter -from xonsh.ptk_shell.updator import AsyncPrompt, PromptUpdator +from xonsh.shells.ptk_shell.updator import AsyncPrompt, PromptUpdator class PTKPromptFormatter(PromptFormatter): diff --git a/xonsh/ptk_shell/history.py b/xonsh/shells/ptk_shell/history.py similarity index 100% rename from xonsh/ptk_shell/history.py rename to xonsh/shells/ptk_shell/history.py diff --git a/xonsh/ptk_shell/key_bindings.py b/xonsh/shells/ptk_shell/key_bindings.py similarity index 99% rename from xonsh/ptk_shell/key_bindings.py rename to xonsh/shells/ptk_shell/key_bindings.py index 96f29411f..a199c7b5c 100644 --- a/xonsh/ptk_shell/key_bindings.py +++ b/xonsh/shells/ptk_shell/key_bindings.py @@ -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, diff --git a/xonsh/ptk_shell/updator.py b/xonsh/shells/ptk_shell/updator.py similarity index 98% rename from xonsh/ptk_shell/updator.py rename to xonsh/shells/ptk_shell/updator.py index 1f2a321aa..272fa8bc3 100644 --- a/xonsh/ptk_shell/updator.py +++ b/xonsh/shells/ptk_shell/updator.py @@ -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.ptk_shell.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.ptk_shell.shell import PromptToolkitShell + from xonsh.shells.ptk_shell import PromptToolkitShell self.prompts: dict[str, AsyncPrompt] = {} self.shell: PromptToolkitShell = shell diff --git a/xonsh/readline_shell.py b/xonsh/shells/readline_shell.py similarity index 99% rename from xonsh/readline_shell.py rename to xonsh/shells/readline_shell.py index 4cb15d474..c685baf3e 100644 --- a/xonsh/readline_shell.py +++ b/xonsh/shells/readline_shell.py @@ -26,11 +26,10 @@ from xonsh.ansi_colors import ( ansi_color_style_names, ansi_partial_color_format, ) -from xonsh.base_shell import BaseShell from xonsh.built_ins import XSH from xonsh.events import events -from xonsh.lazyasd import LazyObject, lazyobject -from xonsh.lazyimps import pyghooks, pygments, winutils +from xonsh.lib.lazyasd import LazyObject, lazyobject +from xonsh.lib.lazyimps import pyghooks, pygments, winutils from xonsh.platform import ( ON_CYGWIN, ON_DARWIN, @@ -40,6 +39,7 @@ from xonsh.platform import ( os_environ, ) from xonsh.prompt.base import multiline_prompt +from xonsh.shells.base_shell import BaseShell from xonsh.tools import ( carriage_return, columnize, @@ -91,7 +91,6 @@ def setup_readline(): ) return - import ctypes import ctypes.util uses_libedit = readline.__doc__ and "libedit" in readline.__doc__ diff --git a/xonsh/shell.py b/xonsh/shells/shell.py similarity index 96% rename from xonsh/shell.py rename to xonsh/shells/shell.py index 2bab837ee..bb8117f94 100644 --- a/xonsh/shell.py +++ b/xonsh/shells/shell.py @@ -213,13 +213,13 @@ class Shell: ) if backend == "none": - from xonsh.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.ptk_shell.shell import PromptToolkitShell as cls + from xonsh.shells.ptk_shell import PromptToolkitShell as cls elif backend == "readline": - from xonsh.readline_shell import ReadlineShell as cls + from xonsh.shells.readline_shell import ReadlineShell as cls elif backend == "dumb": - from xonsh.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) diff --git a/xonsh/style_tools.py b/xonsh/style_tools.py index c49bc358b..73ebb8610 100644 --- a/xonsh/style_tools.py +++ b/xonsh/style_tools.py @@ -3,7 +3,7 @@ from collections import defaultdict from xonsh.color_tools import RE_BACKGROUND, iscolor, warn_deprecated_no_color -from xonsh.lazyasd import LazyObject +from xonsh.lib.lazyasd import LazyObject from xonsh.platform import HAS_PYGMENTS from xonsh.tools import FORMATTER diff --git a/xonsh/timings.py b/xonsh/timings.py index cdb7484a4..fe72a96fa 100644 --- a/xonsh/timings.py +++ b/xonsh/timings.py @@ -17,8 +17,7 @@ import timeit from xonsh.built_ins import XSH from xonsh.events import events -from xonsh.lazyasd import lazybool, lazyobject -from xonsh.platform import ON_WINDOWS +from xonsh.lib.lazyasd import lazybool, lazyobject @lazybool diff --git a/xonsh/tools.py b/xonsh/tools.py index aa6eacd0d..c8bff91a4 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -44,7 +44,7 @@ from contextlib import contextmanager # adding imports from further xonsh modules is discouraged to avoid circular # dependencies from xonsh import __version__ -from xonsh.lazyasd import LazyDict, LazyObject, lazyobject +from xonsh.lib.lazyasd import LazyDict, LazyObject, lazyobject from xonsh.platform import ( DEFAULT_ENCODING, HAS_PYGMENTS, @@ -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.ptk_shell.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): diff --git a/xonsh/tracer.py b/xonsh/tracer.py index 74ffdf6a9..e7d88703e 100644 --- a/xonsh/tracer.py +++ b/xonsh/tracer.py @@ -11,9 +11,9 @@ import typing as tp import xonsh.procs.pipelines as xpp import xonsh.prompt.cwd as prompt from xonsh.cli_utils import Annotated, Arg, ArgParserAlias -from xonsh.lazyasd import LazyObject -from xonsh.lazyimps import pyghooks, pygments from xonsh.lib.inspectors import find_file +from xonsh.lib.lazyasd import LazyObject +from xonsh.lib.lazyimps import pyghooks, pygments from xonsh.platform import HAS_PYGMENTS from xonsh.tools import DefaultNotGiven, normabspath, print_color, to_bool diff --git a/xonsh/xonfig.py b/xonsh/xonfig.py index 5e83c5a40..22e99e85c 100644 --- a/xonsh/xonfig.py +++ b/xonsh/xonfig.py @@ -19,7 +19,8 @@ from xonsh.built_ins import XSH from xonsh.cli_utils import Arg, ArgParserAlias from xonsh.events import events from xonsh.foreign_shells import CANON_SHELL_NAMES -from xonsh.lazyasd import lazyobject +from xonsh.lib.lazyasd import lazyobject +from xonsh.parsers import ply from xonsh.platform import ( DEFAULT_ENCODING, ON_CYGWIN, @@ -37,7 +38,6 @@ from xonsh.platform import ( ptk_version, pygments_version, ) -from xonsh.ply import ply from xonsh.prompt.base import is_template_string from xonsh.tools import ( color_style, diff --git a/xonsh/xoreutils/umask.py b/xonsh/xoreutils/umask.py index 5104e8047..b996ccbaa 100644 --- a/xonsh/xoreutils/umask.py +++ b/xonsh/xoreutils/umask.py @@ -3,7 +3,7 @@ import os import re -import xonsh.lazyasd as xl +import xonsh.lib.lazyasd as xl @xl.lazyobject diff --git a/xonsh/xoreutils/uptime.py b/xonsh/xoreutils/uptime.py index 3af800598..95ac123d3 100644 --- a/xonsh/xoreutils/uptime.py +++ b/xonsh/xoreutils/uptime.py @@ -19,7 +19,7 @@ import struct import sys import time -import xonsh.lazyimps as xlimps +import xonsh.lib.lazyimps as xlimps import xonsh.platform as xp