From 0656eb3d3e464edf003034c49465f1c5c0e8cf32 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Thu, 4 Jul 2024 17:24:04 +0200 Subject: [PATCH] refactoring: deprecation warnings and revert shell moving for backwards compatibility (#5575) * deprecation warnings * deprecation warnings * deprecation warnings * restore shell * restore shell * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: a <1@1.1> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- tests/shell/test_base_shell.py | 2 +- tests/shell/test_ptk_shell.py | 8 ++++---- tests/shell/test_shell.py | 2 +- xonsh/lazyasd.py | 11 +++++++++++ xonsh/lazyimps.py | 11 +++++++++++ xonsh/lazyjson.py | 11 +++++++++++ xonsh/lib/os.py | 9 +++++++++ xonsh/lib/subprocess.py | 11 +++++++++++ xonsh/main.py | 2 +- xonsh/{shells => }/shell.py | 0 xonsh/shells/base_shell.py | 2 +- xonsh/shells/ptk_shell/__init__.py | 2 +- xonsh/shells/ptk_shell/key_bindings.py | 2 +- 13 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 xonsh/lazyasd.py create mode 100644 xonsh/lazyimps.py create mode 100644 xonsh/lazyjson.py create mode 100644 xonsh/lib/os.py create mode 100644 xonsh/lib/subprocess.py rename xonsh/{shells => }/shell.py (100%) diff --git a/tests/shell/test_base_shell.py b/tests/shell/test_base_shell.py index 139c2d6f7..db3d1e20d 100644 --- a/tests/shell/test_base_shell.py +++ b/tests/shell/test_base_shell.py @@ -4,8 +4,8 @@ import os import pytest +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/shell/test_ptk_shell.py b/tests/shell/test_ptk_shell.py index 0edd76c70..101090f93 100644 --- a/tests/shell/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.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.shells.shell.warnings.warn", mock_warning + "xonsh.shell.warnings.warn", mock_warning ) # hardwon: patch the caller! monkeypatch.setattr( - "xonsh.shells.shell.ptk_above_min_supported", mock_ptk_above_min_supported + "xonsh.shell.ptk_above_min_supported", mock_ptk_above_min_supported ) # have to patch both callers monkeypatch.setattr( - "xonsh.shells.shell.ptk_above_min_supported", mock_ptk_above_min_supported + "xonsh.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/shell/test_shell.py b/tests/shell/test_shell.py index a15c480f1..74e7f8870 100644 --- a/tests/shell/test_shell.py +++ b/tests/shell/test_shell.py @@ -5,7 +5,7 @@ import os from xonsh.history.dummy import DummyHistory from xonsh.history.json import JsonHistory from xonsh.history.sqlite import SqliteHistory -from xonsh.shells.shell import Shell +from xonsh.shell import Shell def test_shell_with_json_history(xession, xonsh_execer, tmpdir_factory): diff --git a/xonsh/lazyasd.py b/xonsh/lazyasd.py new file mode 100644 index 000000000..83ab18bae --- /dev/null +++ b/xonsh/lazyasd.py @@ -0,0 +1,11 @@ +"""DEPRECATED: Use `xonsh.lib.lazyasd` instead of `xonsh.lazyasd`.""" + +import warnings + +warnings.warn( + "Use `xonsh.lib.lazyasd` instead of `xonsh.lazyasd`.", + DeprecationWarning, + stacklevel=2, +) + +from xonsh.lib.lazyasd import * # noqa diff --git a/xonsh/lazyimps.py b/xonsh/lazyimps.py new file mode 100644 index 000000000..d39942034 --- /dev/null +++ b/xonsh/lazyimps.py @@ -0,0 +1,11 @@ +"""DEPRECATED: Use `xonsh.lib.lazyasd` instead of `xonsh.lazyimps`.""" + +import warnings + +warnings.warn( + "Use `xonsh.lib.lazyimps` instead of `xonsh.lazyimps`.", + DeprecationWarning, + stacklevel=2, +) + +from xonsh.lib.lazyimps import * # noqa diff --git a/xonsh/lazyjson.py b/xonsh/lazyjson.py new file mode 100644 index 000000000..ff1e78f85 --- /dev/null +++ b/xonsh/lazyjson.py @@ -0,0 +1,11 @@ +"""DEPRECATED: Use `xonsh.lib.lazyjson` instead of `xonsh.lazyjson`.""" + +import warnings + +warnings.warn( + "Use `xonsh.lib.lazyjson` instead of `xonsh.lazyjson`.", + DeprecationWarning, + stacklevel=2, +) + +from xonsh.lib.lazyjson import * # noqa diff --git a/xonsh/lib/os.py b/xonsh/lib/os.py new file mode 100644 index 000000000..d9b8e6071 --- /dev/null +++ b/xonsh/lib/os.py @@ -0,0 +1,9 @@ +"""DEPRECATED: Use `xonsh.lib.lazyasd` instead of `xonsh.lazyasd`.""" + +import warnings + +warnings.warn( + "Use `xonsh.api.os` instead of `xonsh.lib.os`.", DeprecationWarning, stacklevel=2 +) + +from xonsh.api.os import * # noqa diff --git a/xonsh/lib/subprocess.py b/xonsh/lib/subprocess.py new file mode 100644 index 000000000..d68116b67 --- /dev/null +++ b/xonsh/lib/subprocess.py @@ -0,0 +1,11 @@ +"""DEPRECATED: Use `xonsh.lib.lazyasd` instead of `xonsh.lazyasd`.""" + +import warnings + +warnings.warn( + "Use `xonsh.api.subprocess` instead of `xonsh.lib.subprocess`.", + DeprecationWarning, + stacklevel=2, +) + +from xonsh.api.subprocess import * # noqa diff --git a/xonsh/main.py b/xonsh/main.py index 4de0d3cd3..594033dbd 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -22,7 +22,7 @@ from xonsh.lib.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.shells.shell import Shell +from xonsh.shell import Shell from xonsh.timings import setup_timings from xonsh.tools import ( display_error_message, diff --git a/xonsh/shells/shell.py b/xonsh/shell.py similarity index 100% rename from xonsh/shells/shell.py rename to xonsh/shell.py diff --git a/xonsh/shells/base_shell.py b/xonsh/shells/base_shell.py index 5d26da6c7..732f366dd 100644 --- a/xonsh/shells/base_shell.py +++ b/xonsh/shells/base_shell.py @@ -20,7 +20,7 @@ from xonsh.events import events 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.shells.shell import transform_command +from xonsh.shell import transform_command from xonsh.tools import ( DefaultNotGiven, XonshError, diff --git a/xonsh/shells/ptk_shell/__init__.py b/xonsh/shells/ptk_shell/__init__.py index 5ee5d770a..bd9fb612a 100644 --- a/xonsh/shells/ptk_shell/__init__.py +++ b/xonsh/shells/ptk_shell/__init__.py @@ -29,12 +29,12 @@ from xonsh.events import events from xonsh.lib.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.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/shells/ptk_shell/key_bindings.py b/xonsh/shells/ptk_shell/key_bindings.py index a199c7b5c..96f29411f 100644 --- a/xonsh/shells/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.shells.shell import transform_command +from xonsh.shell import transform_command from xonsh.tools import ( check_for_partial_string, ends_with_colon_token,