From 43d052765719b983c50ecce518baa0ed6cbea000 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Thu, 14 Feb 2019 10:00:20 -0500 Subject: [PATCH] fixes --- news/lscolors.rst | 1 + tests/test_environ.py | 2 +- xonsh/__init__.py | 20 ++++++++++---------- xonsh/environ.py | 5 +++++ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/news/lscolors.rst b/news/lscolors.rst index 2cce1fa8d..058d379f5 100644 --- a/news/lscolors.rst +++ b/news/lscolors.rst @@ -29,6 +29,7 @@ * New ``xonsh.tools.detype()`` function that simply calls an objects own ``detype()`` method in order to detype it. * New ``xonsh.tools.always_none()`` function that simply returns None. +* New ``Env.set_ensurer()`` method for setting an ensurer on an environment. **Changed:** diff --git a/tests/test_environ.py b/tests/test_environ.py index b4b71bc3d..f770e1f44 100644 --- a/tests/test_environ.py +++ b/tests/test_environ.py @@ -68,7 +68,7 @@ def test_env_detype_mutable_access_clear(path1, path2): def test_env_detype_no_dict(): env = Env(YO={"hey": 42}) - env.get_ensurer('YO', default=Ensurer(always_true, None, None)) + env.set_ensurer('YO', Ensurer(always_true, None, None)) det = env.detype() assert "YO" not in det diff --git a/xonsh/__init__.py b/xonsh/__init__.py index 9da765f9f..a7e36dd60 100644 --- a/xonsh/__init__.py +++ b/xonsh/__init__.py @@ -22,6 +22,8 @@ else: _sys.modules["xonsh.lazyasd"] = __amalgam__ lazyjson = __amalgam__ _sys.modules["xonsh.lazyjson"] = __amalgam__ + color_tools = __amalgam__ + _sys.modules["xonsh.color_tools"] = __amalgam__ platform = __amalgam__ _sys.modules["xonsh.platform"] = __amalgam__ pretty = __amalgam__ @@ -36,10 +38,10 @@ else: _sys.modules["xonsh.tokenize"] = __amalgam__ tools = __amalgam__ _sys.modules["xonsh.tools"] = __amalgam__ + ansi_colors = __amalgam__ + _sys.modules["xonsh.ansi_colors"] = __amalgam__ ast = __amalgam__ _sys.modules["xonsh.ast"] = __amalgam__ - color_tools = __amalgam__ - _sys.modules["xonsh.color_tools"] = __amalgam__ commands_cache = __amalgam__ _sys.modules["xonsh.commands_cache"] = __amalgam__ diff_history = __amalgam__ @@ -56,18 +58,18 @@ else: _sys.modules["xonsh.lexer"] = __amalgam__ openpy = __amalgam__ _sys.modules["xonsh.openpy"] = __amalgam__ + style_tools = __amalgam__ + _sys.modules["xonsh.style_tools"] = __amalgam__ xontribs = __amalgam__ _sys.modules["xonsh.xontribs"] = __amalgam__ - ansi_colors = __amalgam__ - _sys.modules["xonsh.ansi_colors"] = __amalgam__ dirstack = __amalgam__ _sys.modules["xonsh.dirstack"] = __amalgam__ + inspectors = __amalgam__ + _sys.modules["xonsh.inspectors"] = __amalgam__ proc = __amalgam__ _sys.modules["xonsh.proc"] = __amalgam__ shell = __amalgam__ _sys.modules["xonsh.shell"] = __amalgam__ - style_tools = __amalgam__ - _sys.modules["xonsh.style_tools"] = __amalgam__ timings = __amalgam__ _sys.modules["xonsh.timings"] = __amalgam__ xonfig = __amalgam__ @@ -76,14 +78,12 @@ else: _sys.modules["xonsh.base_shell"] = __amalgam__ environ = __amalgam__ _sys.modules["xonsh.environ"] = __amalgam__ - inspectors = __amalgam__ - _sys.modules["xonsh.inspectors"] = __amalgam__ + tracer = __amalgam__ + _sys.modules["xonsh.tracer"] = __amalgam__ readline_shell = __amalgam__ _sys.modules["xonsh.readline_shell"] = __amalgam__ replay = __amalgam__ _sys.modules["xonsh.replay"] = __amalgam__ - tracer = __amalgam__ - _sys.modules["xonsh.tracer"] = __amalgam__ aliases = __amalgam__ _sys.modules["xonsh.aliases"] = __amalgam__ dumb_shell = __amalgam__ diff --git a/xonsh/environ.py b/xonsh/environ.py index c322452d7..0c4d3806f 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -1403,6 +1403,11 @@ class Env(cabc.MutableMapping): self._ensurers[key] = ensurer return ensurer + def set_ensurer(self, key, value): + """Sets an ensurer.""" + self._detyped = None + self._ensurers[key] = value + def get_docs(self, key, default=VarDocs("")): """Gets the documentation for the environment variable.""" vd = self._docs.get(key, None)