mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
return env to original state
This commit is contained in:
parent
2ad910b8bd
commit
9e48e9cdd1
2 changed files with 23 additions and 1 deletions
|
@ -10,6 +10,7 @@ import builtins
|
|||
import subprocess
|
||||
from warnings import warn
|
||||
from functools import wraps
|
||||
from contextlib import contextmanager
|
||||
from collections import MutableMapping, MutableSequence, MutableSet, namedtuple
|
||||
|
||||
from xonsh import __version__ as XONSH_VERSION
|
||||
|
@ -281,6 +282,24 @@ class Env(MutableMapping):
|
|||
self.ensurers[key] = ens
|
||||
return ens
|
||||
|
||||
@contextmanager
|
||||
def swap(self, other):
|
||||
"""Provides a context manager for temporarily swapping out certain
|
||||
environment variables with other values. On exit from the context
|
||||
manager, the original values are restored.
|
||||
"""
|
||||
old = {}
|
||||
for k, v in other.items():
|
||||
old[k] = self.get(k, NotImplemented)
|
||||
self[k] = v
|
||||
yield self
|
||||
for k, v in old.items():
|
||||
if v is NotImplemented:
|
||||
del self[k]
|
||||
else:
|
||||
self[k] = v
|
||||
|
||||
|
||||
#
|
||||
# Mutable mapping interface
|
||||
#
|
||||
|
|
|
@ -93,6 +93,7 @@ def make_fs():
|
|||
path='/foreign_shells/{idx}/funcscmd'),
|
||||
StoreNonEmpty("source command [str, default=None]: ",
|
||||
path='/foreign_shells/{idx}/sourcer'),
|
||||
Message(message='') # inserts a newline
|
||||
])
|
||||
return fs
|
||||
|
||||
|
@ -127,8 +128,10 @@ def _wizard(ns):
|
|||
env = builtins.__xonsh_env__
|
||||
fname = env.get('XONSHCONFIG') if ns.file is None else ns.file
|
||||
wiz = make_wizard(default_file=fname, confirm=ns.confirm)
|
||||
tempenv = {'PROMPT': '', 'XONSH_STORE_STDOUT': False}
|
||||
pv = PromptVisitor(wiz)
|
||||
pv.visit()
|
||||
with env.swap(tempenv):
|
||||
pv.visit()
|
||||
|
||||
|
||||
def _format_human(data):
|
||||
|
|
Loading…
Add table
Reference in a new issue