many test fixes

This commit is contained in:
Anthony Scopatz 2018-09-13 14:03:35 -04:00
parent 6aa7aba36b
commit 4c91df2abc
30 changed files with 186 additions and 157 deletions

View file

@ -4,7 +4,7 @@ import os
import pytest
from xonsh.built_ins import ensure_list_of_strs, enter_macro
from xonsh.built_ins import ensure_list_of_strs, enter_macro, XonshSession
from xonsh.execer import Execer
from xonsh.jobs import tasks
from xonsh.events import events
@ -27,8 +27,10 @@ def xonsh_execer(monkeypatch):
"xonsh.built_ins.load_builtins.__code__",
(lambda *args, **kwargs: None).__code__,
)
if not hasattr(builtins, "__xonsh__"):
builtins.__xonsh__ = XonshSession()
execer = Execer(unload=False)
builtins.__xonsh_execer__ = execer
builtins.__xonsh__.execer = execer
return execer
@ -46,27 +48,28 @@ def xonsh_events():
def xonsh_builtins(xonsh_events):
"""Mock out most of the builtins xonsh attributes."""
old_builtins = set(dir(builtins))
builtins.__xonsh_env__ = DummyEnv()
execer = getattr(getattr(builtins, "__xonsh__", None), "execer", None)
builtins.__xonsh__ = XonshSession(execer=execer, ctx={})
builtins.__xonsh__.env = DummyEnv()
if ON_WINDOWS:
builtins.__xonsh_env__["PATHEXT"] = [".EXE", ".BAT", ".CMD"]
builtins.__xonsh_ctx__ = {}
builtins.__xonsh_shell__ = DummyShell()
builtins.__xonsh_help__ = lambda x: x
builtins.__xonsh_glob__ = glob.glob
builtins.__xonsh_exit__ = False
builtins.__xonsh_superhelp__ = lambda x: x
builtins.__xonsh_regexpath__ = lambda x: []
builtins.__xonsh_expand_path__ = lambda x: x
builtins.__xonsh_subproc_captured__ = sp
builtins.__xonsh_subproc_uncaptured__ = sp
builtins.__xonsh_stdout_uncaptured__ = None
builtins.__xonsh_stderr_uncaptured__ = None
builtins.__xonsh_ensure_list_of_strs__ = ensure_list_of_strs
builtins.__xonsh_commands_cache__ = DummyCommandsCache()
builtins.__xonsh_all_jobs__ = {}
builtins.__xonsh_history__ = DummyHistory()
builtins.__xonsh_subproc_captured_hiddenobject__ = sp
builtins.__xonsh_enter_macro__ = enter_macro
builtins.__xonsh__.env["PATHEXT"] = [".EXE", ".BAT", ".CMD"]
builtins.__xonsh__.shell = DummyShell()
builtins.__xonsh__.help = lambda x: x
builtins.__xonsh__.glob = glob.glob
builtins.__xonsh__.exit = False
builtins.__xonsh__.superhelp = lambda x: x
builtins.__xonsh__.regexpath = lambda x: []
builtins.__xonsh__.expand_path = lambda x: x
builtins.__xonsh__.subproc_captured = sp
builtins.__xonsh__.subproc_uncaptured = sp
builtins.__xonsh__.stdout_uncaptured = None
builtins.__xonsh__.stderr_uncaptured = None
builtins.__xonsh__.ensure_list_of_strs = ensure_list_of_strs
builtins.__xonsh__.commands_cache = DummyCommandsCache()
builtins.__xonsh__.all_jobs = {}
builtins.__xonsh__.history = DummyHistory()
builtins.__xonsh__.subproc_captured_hiddenobject = sp
builtins.__xonsh__.enter_macro = enter_macro
builtins.evalx = eval
builtins.execx = None
builtins.compilex = None

View file

@ -52,5 +52,5 @@ def test_eval_recursive(xonsh_builtins):
@skip_if_on_windows
def test_eval_recursive_callable_partial(xonsh_builtins):
xonsh_builtins.__xonsh_env__ = Env(HOME=os.path.expanduser("~"))
xonsh_builtins.__xonsh__.env = Env(HOME=os.path.expanduser("~"))
assert ALIASES.get("indirect_cd")(["arg2", "arg3"]) == ["..", "arg2", "arg3"]

View file

@ -10,7 +10,7 @@ from xonsh.shell import transform_command
def test_pwd_tracks_cwd(xonsh_builtins, xonsh_execer, tmpdir_factory, monkeypatch):
asubdir = str(tmpdir_factory.mktemp("asubdir"))
cur_wd = os.getcwd()
xonsh_builtins.__xonsh_env__ = Env(
xonsh_builtins.__xonsh__.env = Env(
PWD=cur_wd, XONSH_CACHE_SCRIPTS=False, XONSH_CACHE_EVERYTHING=False
)
@ -23,11 +23,11 @@ def test_pwd_tracks_cwd(xonsh_builtins, xonsh_execer, tmpdir_factory, monkeypatc
assert os.path.abspath(os.getcwd()) == os.path.abspath(asubdir)
assert os.path.abspath(os.getcwd()) == os.path.abspath(
xonsh_builtins.__xonsh_env__["PWD"]
xonsh_builtins.__xonsh__.env["PWD"]
)
assert "OLDPWD" in xonsh_builtins.__xonsh_env__
assert "OLDPWD" in xonsh_builtins.__xonsh__.env
assert os.path.abspath(cur_wd) == os.path.abspath(
xonsh_builtins.__xonsh_env__["OLDPWD"]
xonsh_builtins.__xonsh__.env["OLDPWD"]
)

View file

@ -7,6 +7,6 @@ def test_preproc(inp, exp, xonsh_builtins):
"""Test the bash preprocessor."""
from xontrib.bashisms import bash_preproc
xonsh_builtins.__xonsh_history__.inps = ["ls\n"]
xonsh_builtins.__xonsh__.history.inps = ["ls\n"]
obs = bash_preproc(inp)
assert exp == obs

View file

@ -45,8 +45,8 @@ def test_reglob_tests(testfile):
@pytest.fixture
def home_env(xonsh_builtins):
"""Set `__xonsh_env__ ` to a new Env instance on `xonsh_builtins`"""
xonsh_builtins.__xonsh_env__ = Env(HOME=HOME_PATH)
"""Set `__xonsh__.env ` to a new Env instance on `xonsh_builtins`"""
xonsh_builtins.__xonsh__.env = Env(HOME=HOME_PATH)
return xonsh_builtins

View file

@ -106,14 +106,14 @@ def test_non_exist_is_only_functional_alias(xonsh_builtins):
@skip_if_on_windows
def test_bash_is_only_functional_alias(xonsh_builtins):
builtins.__xonsh_env__["PATH"] = os.environ["PATH"].split(os.pathsep)
builtins.__xonsh__.env["PATH"] = os.environ["PATH"].split(os.pathsep)
cc = CommandsCache()
assert not cc.is_only_functional_alias("bash")
@skip_if_on_windows
def test_bash_and_is_alias_is_only_functional_alias(xonsh_builtins):
builtins.__xonsh_env__["PATH"] = os.environ["PATH"].split(os.pathsep)
builtins.__xonsh__.env["PATH"] = os.environ["PATH"].split(os.pathsep)
cc = CommandsCache()
builtins.aliases["bash"] = lambda args: os.chdir(args[0])
assert not cc.is_only_functional_alias("bash")

View file

@ -27,7 +27,7 @@ def chdir(adir):
def test_simple(xonsh_builtins):
xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=PARENT)
xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=PARENT)
with chdir(PARENT):
assert os.getcwd() != HERE
dirstack.cd(["tests"])
@ -35,7 +35,7 @@ def test_simple(xonsh_builtins):
def test_cdpath_simple(xonsh_builtins):
xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE)
xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=HERE)
with chdir(os.path.normpath("/")):
assert os.getcwd() != HERE
dirstack.cd(["tests"])
@ -43,7 +43,7 @@ def test_cdpath_simple(xonsh_builtins):
def test_cdpath_collision(xonsh_builtins):
xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE)
xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=HERE)
sub_tests = os.path.join(HERE, "tests")
if not os.path.exists(sub_tests):
os.mkdir(sub_tests)
@ -54,7 +54,7 @@ def test_cdpath_collision(xonsh_builtins):
def test_cdpath_expansion(xonsh_builtins):
xonsh_builtins.__xonsh_env__ = Env(HERE=HERE, CDPATH=("~", "$HERE"))
xonsh_builtins.__xonsh__.env = Env(HERE=HERE, CDPATH=("~", "$HERE"))
test_dirs = (
os.path.join(HERE, "xonsh-test-cdpath-here"),
os.path.expanduser("~/xonsh-test-cdpath-home"),
@ -73,7 +73,7 @@ def test_cdpath_expansion(xonsh_builtins):
def test_cdpath_events(xonsh_builtins, tmpdir):
xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=os.getcwd())
xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=os.getcwd())
target = str(tmpdir)
ev = None
@ -96,7 +96,7 @@ def test_cdpath_events(xonsh_builtins, tmpdir):
def test_cd_autopush(xonsh_builtins, tmpdir):
xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=os.getcwd(), AUTO_PUSHD=True)
xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=os.getcwd(), AUTO_PUSHD=True)
target = str(tmpdir)
old_dir = os.getcwd()

View file

@ -94,11 +94,11 @@ def shares_setup(tmpdir_factory):
def test_pushdpopd(xonsh_builtins):
"""Simple non-UNC push/pop to verify we didn't break nonUNC case.
"""
xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE)
xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=HERE)
dirstack.cd([PARENT])
owd = os.getcwd()
assert owd.casefold() == xonsh_builtins.__xonsh_env__["PWD"].casefold()
assert owd.casefold() == xonsh_builtins.__xonsh__.env["PWD"].casefold()
dirstack.pushd([HERE])
wd = os.getcwd()
assert wd.casefold() == HERE.casefold()
@ -107,7 +107,7 @@ def test_pushdpopd(xonsh_builtins):
def test_cd_dot(xonsh_builtins):
xonsh_builtins.__xonsh_env__ = Env(PWD=os.getcwd())
xonsh_builtins.__xonsh__.env = Env(PWD=os.getcwd())
owd = os.getcwd().casefold()
dirstack.cd(["."])
@ -118,10 +118,10 @@ def test_cd_dot(xonsh_builtins):
def test_uncpushd_simple_push_pop(xonsh_builtins, shares_setup):
if shares_setup is None:
return
xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE)
xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=HERE)
dirstack.cd([PARENT])
owd = os.getcwd()
assert owd.casefold() == xonsh_builtins.__xonsh_env__["PWD"].casefold()
assert owd.casefold() == xonsh_builtins.__xonsh__.env["PWD"].casefold()
dirstack.pushd([r"\\localhost\uncpushd_test_HERE"])
wd = os.getcwd()
assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0]
@ -135,11 +135,11 @@ def test_uncpushd_simple_push_pop(xonsh_builtins, shares_setup):
def test_uncpushd_push_to_same_share(xonsh_builtins, shares_setup):
if shares_setup is None:
return
xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE)
xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=HERE)
dirstack.cd([PARENT])
owd = os.getcwd()
assert owd.casefold() == xonsh_builtins.__xonsh_env__["PWD"].casefold()
assert owd.casefold() == xonsh_builtins.__xonsh__.env["PWD"].casefold()
dirstack.pushd([r"\\localhost\uncpushd_test_HERE"])
wd = os.getcwd()
assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0]
@ -169,11 +169,11 @@ def test_uncpushd_push_other_push_same(xonsh_builtins, shares_setup):
Then push to a again. Pop (check b unmapped and a still mapped), pop, pop (check a is unmapped)"""
if shares_setup is None:
return
xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE)
xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=HERE)
dirstack.cd([PARENT])
owd = os.getcwd()
assert owd.casefold() == xonsh_builtins.__xonsh_env__["PWD"].casefold()
assert owd.casefold() == xonsh_builtins.__xonsh__.env["PWD"].casefold()
dirstack.pushd([r"\\localhost\uncpushd_test_HERE"])
assert os.getcwd().casefold() == TEMP_DRIVE[0] + "\\"
assert len(_unc_tempDrives) == 1
@ -285,15 +285,15 @@ def with_unc_check_disabled(): # just like the above, but value is 1 to *disabl
@pytest.fixture()
def xonsh_builtins_cd(xonsh_builtins):
xonsh_builtins.__xonsh_env__["CDPATH"] = PARENT
xonsh_builtins.__xonsh_env__["PWD"] = os.getcwd()
xonsh_builtins.__xonsh_env__["DIRSTACK_SIZE"] = 20
xonsh_builtins.__xonsh__.env["CDPATH"] = PARENT
xonsh_builtins.__xonsh__.env["PWD"] = os.getcwd()
xonsh_builtins.__xonsh__.env["DIRSTACK_SIZE"] = 20
return xonsh_builtins
@pytest.mark.skipif(not ON_WINDOWS, reason="Windows-only UNC functionality")
def test_uncpushd_cd_unc_auto_pushd(xonsh_builtins_cd, with_unc_check_enabled):
xonsh_builtins_cd.__xonsh_env__["AUTO_PUSHD"] = True
xonsh_builtins_cd.__xonsh__.env["AUTO_PUSHD"] = True
so, se, rc = dirstack.cd([r"\\localhost\uncpushd_test_PARENT"])
if rc != 0:
return

View file

@ -146,10 +146,10 @@ def test_locate_binary_on_windows(xonsh_builtins):
fpath = os.path.join(tmpdir, fname)
with open(fpath, "w") as f:
f.write(fpath)
xonsh_builtins.__xonsh_env__.update(
xonsh_builtins.__xonsh__.env.update(
{"PATH": [tmpdir], "PATHEXT": [".COM", ".EXE", ".BAT"]}
)
xonsh_builtins.__xonsh_commands_cache__ = CommandsCache()
xonsh_builtins.__xonsh__.commands_cache = CommandsCache()
assert locate_binary("file1") == os.path.join(tmpdir, "file1.exe")
assert locate_binary("file1.exe") == os.path.join(tmpdir, "file1.exe")
assert locate_binary("file2") == os.path.join(tmpdir, "FILE2.BAT")
@ -159,7 +159,7 @@ def test_locate_binary_on_windows(xonsh_builtins):
def test_event_on_envvar_change(xonsh_builtins):
env = Env(TEST=0)
xonsh_builtins.__xonsh_env__ = env
xonsh_builtins.__xonsh__.env = env
share = []
# register
@xonsh_builtins.events.on_envvar_change
@ -174,7 +174,7 @@ def test_event_on_envvar_change(xonsh_builtins):
def test_event_on_envvar_new(xonsh_builtins):
env = Env()
xonsh_builtins.__xonsh_env__ = env
xonsh_builtins.__xonsh__.env = env
share = []
# register
@xonsh_builtins.events.on_envvar_new
@ -189,7 +189,7 @@ def test_event_on_envvar_new(xonsh_builtins):
def test_event_on_envvar_change_from_none_value(xonsh_builtins):
env = Env(TEST=None)
xonsh_builtins.__xonsh_env__ = env
xonsh_builtins.__xonsh__.env = env
share = []
# register
@xonsh_builtins.events.on_envvar_change
@ -205,7 +205,7 @@ def test_event_on_envvar_change_from_none_value(xonsh_builtins):
@pytest.mark.parametrize("val", [1, None, True, "ok"])
def test_event_on_envvar_change_no_fire_when_value_is_same(val, xonsh_builtins):
env = Env(TEST=val)
xonsh_builtins.__xonsh_env__ = env
xonsh_builtins.__xonsh__.env = env
share = []
# register
@xonsh_builtins.events.on_envvar_change
@ -220,7 +220,7 @@ def test_event_on_envvar_change_no_fire_when_value_is_same(val, xonsh_builtins):
def test_events_on_envvar_called_in_right_order(xonsh_builtins):
env = Env()
xonsh_builtins.__xonsh_env__ = env
xonsh_builtins.__xonsh__.env = env
share = []
# register
@xonsh_builtins.events.on_envvar_new

View file

@ -33,7 +33,7 @@ def test_hist_init(hist):
def test_hist_append(hist, xonsh_builtins):
"""Verify appending to the history works."""
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = set()
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = set()
hf = hist.append({"inp": "still alive", "rtn": 0})
assert hf is None
assert "still alive" == hist.buffer[0]["inp"]
@ -53,7 +53,7 @@ def test_hist_flush(hist, xonsh_builtins):
"""Verify explicit flushing of the history works."""
hf = hist.flush()
assert hf is None
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = set()
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = set()
hist.append({"inp": "still alive?", "rtn": 0, "out": "yes"})
hf = hist.flush()
assert hf is not None
@ -70,8 +70,8 @@ def test_hist_flush_with_store_stdout(hist, xonsh_builtins):
"""Verify explicit flushing of the history works."""
hf = hist.flush()
assert hf is None
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = set()
xonsh_builtins.__xonsh_env__["XONSH_STORE_STDOUT"] = True
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = set()
xonsh_builtins.__xonsh__.env["XONSH_STORE_STDOUT"] = True
hist.append({"inp": "still alive?", "rtn": 0, "out": "yes"})
hf = hist.flush()
assert hf is not None
@ -87,7 +87,7 @@ def test_hist_flush_with_hist_control(hist, xonsh_builtins):
"""Verify explicit flushing of the history works."""
hf = hist.flush()
assert hf is None
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = "ignoredups,ignoreerr"
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = "ignoredups,ignoreerr"
hist.append({"inp": "ls foo1", "rtn": 0})
hist.append({"inp": "ls foo1", "rtn": 1})
hist.append({"inp": "ls foo1", "rtn": 0})
@ -107,7 +107,7 @@ def test_hist_flush_with_hist_control(hist, xonsh_builtins):
def test_cmd_field(hist, xonsh_builtins):
# in-memory
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = set()
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = set()
hf = hist.append({"inp": "ls foo", "rtn": 1})
assert hf is None
assert 1 == hist.rtns[0]
@ -139,8 +139,8 @@ def test_cmd_field(hist, xonsh_builtins):
def test_show_cmd_numerate(inp, commands, offset, hist, xonsh_builtins, capsys):
"""Verify that CLI history commands work."""
base_idx, step = offset
xonsh_builtins.__xonsh_history__ = hist
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = set()
xonsh_builtins.__xonsh__.history = hist
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = set()
for ts, cmd in enumerate(CMDS): # populate the shell history
hist.append({"inp": cmd, "rtn": 0, "ts": (ts + 1, ts + 1.5)})
@ -158,7 +158,7 @@ def test_show_cmd_numerate(inp, commands, offset, hist, xonsh_builtins, capsys):
def test_histcontrol(hist, xonsh_builtins):
"""Test HISTCONTROL=ignoredups,ignoreerr"""
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = "ignoredups,ignoreerr"
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = "ignoredups,ignoreerr"
assert len(hist.buffer) == 0
# An error, buffer remains empty
@ -281,7 +281,7 @@ def test_parser_show(args, exp):
],
)
def test_history_getitem(index, exp, hist, xonsh_builtins):
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = set()
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = set()
attrs = ("inp", "out", "rtn", "ts")
for ts, cmd in enumerate(CMDS): # populate the shell history
@ -296,15 +296,15 @@ def test_history_getitem(index, exp, hist, xonsh_builtins):
def test_construct_history_str(xonsh_builtins):
xonsh_builtins.__xonsh_env__["XONSH_HISTORY_BACKEND"] = "dummy"
xonsh_builtins.__xonsh__.env["XONSH_HISTORY_BACKEND"] = "dummy"
assert isinstance(construct_history(), DummyHistory)
def test_construct_history_class(xonsh_builtins):
xonsh_builtins.__xonsh_env__["XONSH_HISTORY_BACKEND"] = DummyHistory
xonsh_builtins.__xonsh__.env["XONSH_HISTORY_BACKEND"] = DummyHistory
assert isinstance(construct_history(), DummyHistory)
def test_construct_history_instance(xonsh_builtins):
xonsh_builtins.__xonsh_env__["XONSH_HISTORY_BACKEND"] = DummyHistory()
xonsh_builtins.__xonsh__.env["XONSH_HISTORY_BACKEND"] = DummyHistory()
assert isinstance(construct_history(), DummyHistory)

View file

@ -21,7 +21,7 @@ def hist():
def test_hist_append(hist, xonsh_builtins):
"""Verify appending to the history works."""
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = set()
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = set()
hf = hist.append({"inp": "still alive", "rtn": 1})
assert hf is None
items = list(hist.items())
@ -37,7 +37,7 @@ def test_hist_append(hist, xonsh_builtins):
def test_hist_attrs(hist, xonsh_builtins):
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = set()
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = set()
hf = hist.append({"inp": "ls foo", "rtn": 1})
assert hf is None
assert "ls foo" == hist.inps[0]
@ -76,8 +76,8 @@ CMDS = ["ls", "cat hello kitty", "abc", "def", "touch me", "grep from me"]
def test_show_cmd_numerate(inp, commands, offset, hist, xonsh_builtins, capsys):
"""Verify that CLI history commands work."""
base_idx, step = offset
xonsh_builtins.__xonsh_history__ = hist
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = set()
xonsh_builtins.__xonsh__.history = hist
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = set()
for ts, cmd in enumerate(CMDS): # populate the shell history
hist.append({"inp": cmd, "rtn": 0, "ts": (ts + 1, ts + 1.5)})
@ -95,7 +95,7 @@ def test_show_cmd_numerate(inp, commands, offset, hist, xonsh_builtins, capsys):
def test_histcontrol(hist, xonsh_builtins):
"""Test HISTCONTROL=ignoredups,ignoreerr"""
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = "ignoredups,ignoreerr"
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = "ignoredups,ignoreerr"
assert len(hist) == 0
# An error, items() remains empty
@ -181,8 +181,8 @@ def test_histcontrol(hist, xonsh_builtins):
],
)
def test_history_getitem(index, exp, hist, xonsh_builtins):
xonsh_builtins.__xonsh_env__["HISTCONTROL"] = set()
xonsh_builtins.__xonsh_env__["XONSH_STORE_STDOUT"] = True
xonsh_builtins.__xonsh__.env["HISTCONTROL"] = set()
xonsh_builtins.__xonsh__.env["XONSH_STORE_STDOUT"] = True
attrs = ("inp", "out", "rtn", "ts")
for ts, cmd in enumerate(CMDS): # populate the shell history

View file

@ -16,7 +16,7 @@ imphooks.install_import_hooks()
@pytest.yield_fixture(autouse=True)
def imp_env():
execer = Execer(unload=False)
builtins.__xonsh_env__ = Env({"PATH": [], "PATHEXT": []})
builtins.__xonsh__.env = Env({"PATH": [], "PATHEXT": []})
yield
unload_builtins()

View file

@ -28,38 +28,38 @@ def shell(xonsh_builtins, xonsh_execer, monkeypatch):
def test_premain_no_arg(shell, monkeypatch):
monkeypatch.setattr(sys.stdin, "isatty", lambda: True)
xonsh.main.premain([])
assert builtins.__xonsh_env__.get("XONSH_LOGIN")
assert builtins.__xonsh__.env.get("XONSH_LOGIN")
def test_premain_interactive(shell):
xonsh.main.premain(["-i"])
assert builtins.__xonsh_env__.get("XONSH_INTERACTIVE")
assert builtins.__xonsh__.env.get("XONSH_INTERACTIVE")
def test_premain_login_command(shell):
xonsh.main.premain(["-l", "-c", 'echo "hi"'])
assert builtins.__xonsh_env__.get("XONSH_LOGIN")
assert builtins.__xonsh__.env.get("XONSH_LOGIN")
def test_premain_login(shell):
xonsh.main.premain(["-l"])
assert builtins.__xonsh_env__.get("XONSH_LOGIN")
assert builtins.__xonsh__.env.get("XONSH_LOGIN")
def test_premain_D(shell):
xonsh.main.premain(["-DTEST1=1616", "-DTEST2=LOL"])
assert builtins.__xonsh_env__.get("TEST1") == "1616"
assert builtins.__xonsh_env__.get("TEST2") == "LOL"
assert builtins.__xonsh__.env.get("TEST1") == "1616"
assert builtins.__xonsh__.env.get("TEST2") == "LOL"
def test_premain_custom_rc(shell, tmpdir, monkeypatch):
monkeypatch.setattr(sys.stdin, "isatty", lambda: True)
builtins.__xonsh_env__ = Env(XONSH_CACHE_SCRIPTS=False)
builtins.__xonsh__.env = Env(XONSH_CACHE_SCRIPTS=False)
f = tmpdir.join("wakkawakka")
f.write("print('hi')")
args = xonsh.main.premain(["--rc", f.strpath])
assert args.mode == XonshMode.interactive
assert f.strpath in builtins.__xonsh_env__.get("XONSHRC")
assert f.strpath in builtins.__xonsh__.env.get("XONSHRC")
def test_no_rc_with_script(shell, tmpdir):
@ -69,19 +69,19 @@ def test_no_rc_with_script(shell, tmpdir):
def test_force_interactive_rc_with_script(shell, tmpdir):
args = xonsh.main.premain(["-i", "tests/sample.xsh"])
assert builtins.__xonsh_env__.get("XONSH_INTERACTIVE")
assert builtins.__xonsh__.env.get("XONSH_INTERACTIVE")
def test_force_interactive_custom_rc_with_script(shell, tmpdir):
"""Calling a custom RC file on a script-call with the interactive flag
should run interactively
"""
builtins.__xonsh_env__ = Env(XONSH_CACHE_SCRIPTS=False)
builtins.__xonsh__.env = Env(XONSH_CACHE_SCRIPTS=False)
f = tmpdir.join("wakkawakka")
f.write("print('hi')")
args = xonsh.main.premain(["-i", "--rc", f.strpath, "tests/sample.xsh"])
assert args.mode == XonshMode.interactive
assert f.strpath in builtins.__xonsh_env__.get("XONSHRC")
assert f.strpath in builtins.__xonsh__.env.get("XONSHRC")
def test_custom_rc_with_script(shell, tmpdir):
@ -96,7 +96,7 @@ def test_custom_rc_with_script(shell, tmpdir):
def test_premain_no_rc(shell, tmpdir):
xonsh.main.premain(["--no-rc"])
assert not builtins.__xonsh_env__.get("XONSHRC")
assert not builtins.__xonsh__.env.get("XONSHRC")
@pytest.mark.parametrize(
@ -104,12 +104,12 @@ def test_premain_no_rc(shell, tmpdir):
)
def test_premain_with_file_argument(arg, shell):
xonsh.main.premain(["tests/sample.xsh", arg])
assert not (builtins.__xonsh_env__.get("XONSH_INTERACTIVE"))
assert not (builtins.__xonsh__.env.get("XONSH_INTERACTIVE"))
def test_premain_interactive__with_file_argument(shell):
xonsh.main.premain(["-i", "tests/sample.xsh"])
assert builtins.__xonsh_env__.get("XONSH_INTERACTIVE")
assert builtins.__xonsh__.env.get("XONSH_INTERACTIVE")
@pytest.mark.parametrize("case", ["----", "--hep", "-TT", "--TTTT"])

View file

@ -12,7 +12,7 @@ def test_man_completion(monkeypatch, tmpdir, xonsh_builtins):
monkeypatch.setitem(
os.environ, "MANPATH", os.path.dirname(os.path.abspath(__file__))
)
xonsh_builtins.__xonsh_env__.update({"XONSH_DATA_DIR": str(tempdir)})
completions = complete_from_man("--", "yes --", 4, 6, xonsh_builtins.__xonsh_env__)
xonsh_builtins.__xonsh__.env.update({"XONSH_DATA_DIR": str(tempdir)})
completions = complete_from_man("--", "yes --", 4, 6, xonsh_builtins.__xonsh__.env)
assert "--version" in completions
assert "--help" in completions

View file

@ -46,7 +46,7 @@ def check_stmts(inp, run=True, mode="exec", debug_level=0):
def check_xonsh_ast(xenv, inp, run=True, mode="eval", debug_level=0, return_obs=False):
__tracebackhide__ = True
builtins.__xonsh_env__ = xenv
builtins.__xonsh__.env = xenv
obs = PARSER.parse(inp, debug_level=debug_level)
if obs is None:
return # comment only

View file

@ -18,7 +18,7 @@ def test_pattern_need_quotes():
def test_complete_path(xonsh_builtins):
xonsh_builtins.__xonsh_env__ = {
xonsh_builtins.__xonsh__.env = {
"CASE_SENSITIVE_COMPLETIONS": False,
"GLOB_SORTED": True,
"SUBSEQUENCE_PATH_COMPLETION": False,
@ -31,7 +31,7 @@ def test_complete_path(xonsh_builtins):
@patch("xonsh.completers.path._add_cdpaths")
def test_cd_path_no_cd(mock_add_cdpaths, xonsh_builtins):
xonsh_builtins.__xonsh_env__ = {
xonsh_builtins.__xonsh__.env = {
"CASE_SENSITIVE_COMPLETIONS": False,
"GLOB_SORTED": True,
"SUBSEQUENCE_PATH_COMPLETION": False,

View file

@ -77,7 +77,7 @@ def test_format_prompt_with_broken_template_in_func(inp, formatter):
def test_format_prompt_with_invalid_func(formatter, xonsh_builtins):
xonsh_builtins.__xonsh_env__ = Env()
xonsh_builtins.__xonsh__.env = Env()
def p():
foo = bar # raises exception # noqa
@ -87,7 +87,7 @@ def test_format_prompt_with_invalid_func(formatter, xonsh_builtins):
def test_format_prompt_with_func_that_raises(formatter, capsys, xonsh_builtins):
xonsh_builtins.__xonsh_env__ = Env()
xonsh_builtins.__xonsh__.env = Env()
template = "tt {zerodiv} tt"
exp = "tt (ERROR:zerodiv) tt"
fields = {"zerodiv": lambda: 1 / 0}
@ -156,7 +156,7 @@ def test_no_repo(xonsh_builtins):
import queue
temp_dir = tempfile.mkdtemp()
xonsh_builtins.__xonsh_env__ = Env(VC_BRANCH_TIMEOUT=2, PWD=temp_dir)
xonsh_builtins.__xonsh__.env = Env(VC_BRANCH_TIMEOUT=2, PWD=temp_dir)
q = queue.Queue()
try:
vc._get_hg_root(q)
@ -165,7 +165,7 @@ def test_no_repo(xonsh_builtins):
def test_vc_get_branch(test_repo, xonsh_builtins):
xonsh_builtins.__xonsh_env__ = Env(VC_BRANCH_TIMEOUT=2)
xonsh_builtins.__xonsh__.env = Env(VC_BRANCH_TIMEOUT=2)
# get corresponding function from vc module
fun = "get_{}_branch".format(test_repo["name"])
obs = getattr(vc, fun)()
@ -174,8 +174,8 @@ def test_vc_get_branch(test_repo, xonsh_builtins):
def test_current_branch_calls_locate_binary_for_empty_cmds_cache(xonsh_builtins):
cache = xonsh_builtins.__xonsh_commands_cache__
xonsh_builtins.__xonsh_env__ = DummyEnv(VC_BRANCH_TIMEOUT=1)
cache = xonsh_builtins.__xonsh__.commands_cache
xonsh_builtins.__xonsh__.env = DummyEnv(VC_BRANCH_TIMEOUT=1)
cache.is_empty = Mock(return_value=True)
cache.locate_binary = Mock(return_value="")
vc.current_branch()
@ -185,8 +185,8 @@ def test_current_branch_calls_locate_binary_for_empty_cmds_cache(xonsh_builtins)
def test_current_branch_does_not_call_locate_binary_for_non_empty_cmds_cache(
xonsh_builtins
):
cache = xonsh_builtins.__xonsh_commands_cache__
xonsh_builtins.__xonsh_env__ = DummyEnv(VC_BRANCH_TIMEOUT=1)
cache = xonsh_builtins.__xonsh__.commands_cache
xonsh_builtins.__xonsh__.env = DummyEnv(VC_BRANCH_TIMEOUT=1)
cache.is_empty = Mock(return_value=False)
cache.locate_binary = Mock(return_value="")
# make lazy locate return nothing to avoid running vc binaries

View file

@ -128,7 +128,7 @@ def test_path(tmpdir):
)
check_token("cd X={}".format(test_dir), [(Name.Constant, test_dir)])
with builtins.__xonsh_env__.swap(AUTO_CD=True):
with builtins.__xonsh__.env.swap(AUTO_CD=True):
check_token(test_dir, [(Name.Constant, test_dir)])

View file

@ -20,8 +20,8 @@ Context = namedtuple("Context", ["indent", "buffer", "accept", "cli", "cr"])
@pytest.yield_fixture(scope="module")
def ctx():
"""Context in which the ptk multiline functionality will be tested."""
builtins.__xonsh_env__ = DummyEnv()
builtins.__xonsh_env__["INDENT"] = " "
builtins.__xonsh__.env = DummyEnv()
builtins.__xonsh__.env["INDENT"] = " "
from xonsh.ptk2.key_bindings import carriage_return
ptk_buffer = Buffer()
@ -34,7 +34,7 @@ def ctx():
cli=cli,
cr=carriage_return,
)
del builtins.__xonsh_env__
del builtins.__xonsh__.env
@skip_if_lt_ptk2

View file

@ -20,9 +20,9 @@ def ctx():
"""Create a global Shell instance to use in all the test."""
ctx = {"PATH": []}
execer = Execer(xonsh_ctx=ctx)
builtins.__xonsh_shell__ = Shell(execer=execer, ctx=ctx, shell_type="none")
builtins.__xonsh__.shell = Shell(execer=execer, ctx=ctx, shell_type="none")
yield
del builtins.__xonsh_shell__
del builtins.__xonsh__.shell
@skip_if_on_darwin

View file

@ -854,7 +854,7 @@ def expand(path):
],
)
def test_env_path_getitem(inp, exp, xonsh_builtins, env):
xonsh_builtins.__xonsh_env__ = env
xonsh_builtins.__xonsh__.env = env
obs = EnvPath(inp)[0] # call to __getitem__
if env.get("EXPAND_ENV_VARS"):
assert expand(exp) == obs
@ -878,7 +878,7 @@ def test_env_path_getitem(inp, exp, xonsh_builtins, env):
)
def test_env_path_multipath(inp, exp, xonsh_builtins, env):
# cases that involve path-separated strings
xonsh_builtins.__xonsh_env__ = env
xonsh_builtins.__xonsh__.env = env
if env == TOOLS_ENV:
obs = [i for i in EnvPath(inp)]
assert [expand(i) for i in exp] == obs
@ -902,7 +902,7 @@ def test_env_path_multipath(inp, exp, xonsh_builtins, env):
],
)
def test_env_path_with_pathlib_path_objects(inp, exp, xonsh_builtins):
xonsh_builtins.__xonsh_env__ = TOOLS_ENV
xonsh_builtins.__xonsh__.env = TOOLS_ENV
# iterate over EnvPath to acquire all expanded paths
obs = [i for i in EnvPath(inp)]
assert [expand(i) for i in exp] == obs
@ -1391,7 +1391,7 @@ def test_executables_in(xonsh_builtins):
if executable and not _type == "brokensymlink":
os.chmod(path, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR)
if ON_WINDOWS:
xonsh_builtins.__xonsh_env__ = PATHEXT_ENV
xonsh_builtins.__xonsh__.env = PATHEXT_ENV
result = set(executables_in(test_path))
else:
result = set(executables_in(test_path))
@ -1441,7 +1441,7 @@ def test_expandvars(inp, exp, xonsh_builtins):
env = Env(
{"foo": "bar", "spam": "eggs", "a_bool": True, "an_int": 42, "none": None}
)
xonsh_builtins.__xonsh_env__ = env
xonsh_builtins.__xonsh__.env = env
assert expandvars(inp) == exp
@ -1464,7 +1464,7 @@ def test_expandvars(inp, exp, xonsh_builtins):
],
)
def test_ensure_timestamp(inp, fmt, exp, xonsh_builtins):
xonsh_builtins.__xonsh_env__["XONSH_DATETIME_FORMAT"] = "%Y-%m-%d %H:%M"
xonsh_builtins.__xonsh__.env["XONSH_DATETIME_FORMAT"] = "%Y-%m-%d %H:%M"
obs = ensure_timestamp(inp, fmt)
assert exp == obs
@ -1488,7 +1488,7 @@ def test_expand_path(expand_user, inp, expand_env_vars, exp_end, xonsh_builtins)
env = Env({"foo": "bar", "a_bool": True, "an_int": 42, "none": None})
env["EXPAND_ENV_VARS"] = expand_env_vars
xonsh_builtins.__xonsh_env__ = env
xonsh_builtins.__xonsh__.env = env
path = expand_path(inp, expand_user=expand_user)

View file

@ -16,7 +16,7 @@ def test_crud(xonsh_builtins, tmpdir):
"""
Creates a virtual environment, gets it, enumerates it, and then deletes it.
"""
xonsh_builtins.__xonsh_env__["VIRTUALENV_HOME"] = str(tmpdir)
xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)
last_event = None
@ -54,9 +54,9 @@ def test_activate(xonsh_builtins, tmpdir):
"""
Creates a virtual environment, gets it, enumerates it, and then deletes it.
"""
xonsh_builtins.__xonsh_env__["VIRTUALENV_HOME"] = str(tmpdir)
xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)
# I consider the case that the user doesn't have a PATH set to be unreasonable
xonsh_builtins.__xonsh_env__.setdefault("PATH", [])
xonsh_builtins.__xonsh__.env.setdefault("PATH", [])
last_event = None
@ -73,10 +73,10 @@ def test_activate(xonsh_builtins, tmpdir):
vox = Vox()
vox.create("spam")
vox.activate("spam")
assert xonsh_builtins.__xonsh_env__["VIRTUAL_ENV"] == vox["spam"].env
assert xonsh_builtins.__xonsh__.env["VIRTUAL_ENV"] == vox["spam"].env
assert last_event == ("activate", "spam")
vox.deactivate()
assert "VIRTUAL_ENV" not in xonsh_builtins.__xonsh_env__
assert "VIRTUAL_ENV" not in xonsh_builtins.__xonsh__.env
assert last_event == ("deactivate", "spam")
@ -86,21 +86,21 @@ def test_path(xonsh_builtins, tmpdir):
"""
Test to make sure Vox properly activates and deactivates by examining $PATH
"""
xonsh_builtins.__xonsh_env__["VIRTUALENV_HOME"] = str(tmpdir)
xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)
# I consider the case that the user doesn't have a PATH set to be unreasonable
xonsh_builtins.__xonsh_env__.setdefault("PATH", [])
xonsh_builtins.__xonsh__.env.setdefault("PATH", [])
oldpath = list(xonsh_builtins.__xonsh_env__["PATH"])
oldpath = list(xonsh_builtins.__xonsh__.env["PATH"])
vox = Vox()
vox.create("eggs")
vox.activate("eggs")
assert oldpath != xonsh_builtins.__xonsh_env__["PATH"]
assert oldpath != xonsh_builtins.__xonsh__.env["PATH"]
vox.deactivate()
assert oldpath == xonsh_builtins.__xonsh_env__["PATH"]
assert oldpath == xonsh_builtins.__xonsh__.env["PATH"]
@skip_if_on_msys
@ -109,7 +109,7 @@ def test_crud_subdir(xonsh_builtins, tmpdir):
"""
Creates a virtual environment, gets it, enumerates it, and then deletes it.
"""
xonsh_builtins.__xonsh_env__["VIRTUALENV_HOME"] = str(tmpdir)
xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)
vox = Vox()
vox.create("spam/eggs")
@ -163,7 +163,7 @@ def test_crud_subdir(xonsh_builtins, tmpdir):
"""
Creates a virtual environment, gets it, enumerates it, and then deletes it.
"""
xonsh_builtins.__xonsh_env__["VIRTUALENV_HOME"] = str(tmpdir)
xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)
vox = Vox()
with pytest.raises(ValueError):

View file

@ -13,12 +13,12 @@ def test_envionment():
def test_xonsh_party():
orig = builtins.__xonsh_env__.get('XONSH_INTERACTIVE')
builtins.__xonsh_env__['XONSH_INTERACTIVE'] = False
orig = builtins.__xonsh__.env.get('XONSH_INTERACTIVE')
builtins.__xonsh__.env['XONSH_INTERACTIVE'] = False
try:
x = 'xonsh'
y = 'party'
out = $(echo @(x + '-' + y)).strip()
assert out == 'xonsh-party', 'Out really was <' + out + '>, sorry.'
finally:
builtins.__xonsh_env__['XONSH_INTERACTIVE'] = orig
builtins.__xonsh__.env['XONSH_INTERACTIVE'] = orig

View file

@ -160,12 +160,12 @@ class DummyEnv(MutableMapping):
def check_exec(input, **kwargs):
if not input.endswith("\n"):
input += "\n"
builtins.__xonsh_execer__.exec(input, **kwargs)
builtins.__xonsh__.execer.exec(input, **kwargs)
return True
def check_eval(input):
builtins.__xonsh_env__ = Env(
builtins.__xonsh__.env = Env(
{
"AUTO_CD": False,
"XONSH_ENCODING": "utf-8",
@ -174,13 +174,13 @@ def check_eval(input):
}
)
if ON_WINDOWS:
builtins.__xonsh_env__["PATHEXT"] = [".COM", ".EXE", ".BAT", ".CMD"]
builtins.__xonsh_execer__.eval(input)
builtins.__xonsh__.env["PATHEXT"] = [".COM", ".EXE", ".BAT", ".CMD"]
builtins.__xonsh__.execer.eval(input)
return True
def check_parse(input):
tree = builtins.__xonsh_execer__.parse(input, ctx=None)
tree = builtins.__xonsh__.execer.parse(input, ctx=None)
return tree

View file

@ -1208,6 +1208,8 @@ def load_builtins(execer=None, ctx=None):
BUILTINS_LOADED variable to True.
"""
global BUILTINS_LOADED
if not hasattr(builtins, "__xonsh__"):
builtins.__xonsh__ = XonshSession(ctx=ctx)
builtins.__xonsh__.load(execer=execer)
builtins.__xonsh__.link_builtins(execer=execer)
BUILTINS_LOADED = True
@ -1253,11 +1255,31 @@ class XonshSession:
"""
def __init__(self):
self.ctx = {}
def __init__(self, execer=None, ctx=None):
"""
Paramters
---------
execer : Execer, optional
Xonsh execution object, may be None to start
ctx : Mapping, optional
Context to start xonsh session with.
"""
self.execer = execer
self.ctx = {} if ctx is None else ctx
def load(self, execer=None):
def load(self, execer=None, ctx=None):
"""Loads the session with deafult values.
Paramters
---------
execer : Execer, optional
Xonsh execution object, may be None to start
ctx : Mapping, optional
Context to start xonsh session with.
"""
self.config__ = {}
if ctx is not None:
self.ctx = ctx
self.env = Env(default_env())
self.help = helper
self.superhelp = superhelper
@ -1283,7 +1305,8 @@ class XonshSession:
self.subproc_captured_object = subproc_captured_object
self.subproc_captured_hiddenobject = subproc_captured_hiddenobject
self.subproc_uncaptured = subproc_uncaptured
self.execer = execer
if execer is not None:
self.execer = execer
self.commands_cache = CommandsCache()
self.all_jobs = {}
self.ensure_list_of_strs = ensure_list_of_strs

View file

@ -144,7 +144,7 @@ def to_debug(x):
execer's debug level.
"""
val = to_bool_or_int(x)
if hasattr(builtins.__xonsh__, "execer"):
if hasattr(builtins, "__xonsh__") and builtins.__xonsh__.execer is not None:
builtins.__xonsh__.execer.debug_level = val
return val

View file

@ -53,7 +53,7 @@ class XonshImportHook(MetaPathFinder, SourceLoader):
@property
def execer(self):
if hasattr(builtins.__xonsh__, "execer"):
if hasattr(builtins, "__xonsh__") and builtins.__xonsh__.execer is not None:
execer = builtins.__xonsh__.execer
if self._execer is not None:
self._execer = None

View file

@ -96,7 +96,8 @@ class XonshCalledProcessError(XonshError, subprocess.CalledProcessError):
def expand_path(s, expand_user=True):
"""Takes a string path and expands ~ to home if expand_user is set
and environment vars if EXPAND_ENV_VARS is set."""
env = getattr(builtins.__xonsh__, "env", os_environ)
session = getattr(builtins, "__xonsh__", None)
env = os_environ if session is None else getattr(session, "env", os_environ)
if env.get("EXPAND_ENV_VARS", False):
s = expandvars(s)
if expand_user:
@ -117,7 +118,8 @@ def _expandpath(path):
"""Performs environment variable / user expansion on a given path
if EXPAND_ENV_VARS is set.
"""
env = getattr(builtins.__xonsh__, "env", os_environ)
session = getattr(builtins, "__xonsh__", None)
env = os_environ if session is None else getattr(session, "env", os_environ)
expand_user = env.get("EXPAND_ENV_VARS", False)
return expand_path(path, expand_user=expand_user)
@ -126,7 +128,8 @@ def decode_bytes(b):
"""Tries to decode the bytes using XONSH_ENCODING if available,
otherwise using sys.getdefaultencoding().
"""
env = getattr(builtins.__xonsh__, "env", os_environ)
session = getattr(builtins, "__xonsh__", None)
env = os_environ if session is None else getattr(session, "env", os_environ)
enc = env.get("XONSH_ENCODING") or DEFAULT_ENCODING
err = env.get("XONSH_ENCODING_ERRORS") or "strict"
return b.decode(encoding=enc, errors=err)
@ -2115,7 +2118,7 @@ def _dotglobstr(s):
def _iglobpath(s, ignore_case=False, sort_result=None, include_dotfiles=None):
s = builtins.__xonsh_expand_path__(s)
s = builtins.__xonsh__.expand_path(s)
if sort_result is None:
sort_result = builtins.__xonsh__.env.get("GLOB_SORTED")
if include_dotfiles is None:

View file

@ -12,11 +12,11 @@ __all__ = ()
@events.on_transform_command
def bash_preproc(cmd, **kw):
if not __xonsh_history__.inps:
if not __xonsh__.history.inps:
if cmd.strip() == '!!':
return ''
return cmd
return cmd.replace('!!', __xonsh_history__.inps[-1].strip())
return cmd.replace('!!', __xonsh__.history.inps[-1].strip())
@events.on_ptk_create
@ -30,12 +30,12 @@ def custom_keybindings(bindings, **kw):
@Condition
def last_command_exists():
return len(__xonsh_history__) > 0
return len(__xonsh__.history) > 0
@handler(Keys.Escape, '.', filter=last_command_exists &
insert_mode)
def recall_last_arg(event):
arg = __xonsh_history__[-1].cmd.split()[-1]
arg = __xonsh__.history[-1].cmd.split()[-1]
event.current_buffer.insert_text(arg)

View file

@ -2,8 +2,8 @@ from xonsh.tools import ON_WINDOWS as _ON_WINDOWS
def _ret_code_color():
if __xonsh_history__.rtns:
color = 'blue' if __xonsh_history__.rtns[-1] == 0 else 'red'
if __xonsh__.history.rtns:
color = 'blue' if __xonsh__.history.rtns[-1] == 0 else 'red'
else:
color = 'blue'
if _ON_WINDOWS:
@ -19,8 +19,8 @@ def _ret_code_color():
def _ret_code():
if __xonsh_history__.rtns:
return_code = __xonsh_history__.rtns[-1]
if __xonsh__.history.rtns:
return_code = __xonsh__.history.rtns[-1]
if return_code != 0:
return '[{}]'.format(return_code)
return None