fixed some more bugs

This commit is contained in:
Anthony Scopatz 2018-09-13 17:08:01 -04:00
parent 89a42458d9
commit 2264f72b45
7 changed files with 24 additions and 20 deletions

View file

@ -21,6 +21,7 @@ from xonsh.tools import setup_win_unicode_console, print_color, to_bool_or_int
from xonsh.platform import HAS_PYGMENTS, ON_WINDOWS
from xonsh.codecache import run_script_with_cache, run_code_with_cache
from xonsh.xonfig import print_welcome_screen
from xonsh.xontribs import xontribs_load
from xonsh.lazyimps import pygments, pyghooks
from xonsh.imphooks import install_import_hooks
from xonsh.events import events

View file

@ -105,14 +105,17 @@ class XonshLexer(PythonLexer):
filenames = ["*.xsh", "*xonshrc"]
def __init__(self, *args, **kwargs):
# If the lexor is loaded as a pygment plugin, we have to mock
# __xonsh_env__ and __xonsh_commands_cache__
# If the lexer is loaded as a pygment plugin, we have to mock
# __xonsh__.env and __xonsh__.commands_cache
if not hasattr(builtins, "__xonsh__"):
from argparse import Namespace
setattr(builtins, "__xonsh__", Namespace())
if not hasattr(builtins.__xonsh__, "env"):
setattr(builtins.__xonsh__, "env", {})
if ON_WINDOWS:
pathext = os_environ.get("PATHEXT", [".EXE", ".BAT", ".CMD"])
builtins.__xonsh__.env["PATHEXT"] = pathext.split(os.pathsep)
if not hasattr(builtins, "__xonsh_commands_cache__"):
if not hasattr(builtins.__xonsh__, "commands_cache"):
setattr(builtins.__xonsh__, "commands_cache", CommandsCache())
_ = builtins.__xonsh__.commands_cache.all_commands # NOQA
super().__init__(*args, **kwargs)

View file

@ -35,7 +35,7 @@ def _cwd_release_wrapper(func):
displayed. This works by temporarily setting
the workdir to the users home directory.
"""
env = builtins.__xonsh_env__
env = builtins.__xonsh__.env
if env.get('UPDATE_PROMPT_ON_KEYPRESS'):
return func if not hasattr(func, '_orgfunc') else func._orgfunc
@ -56,7 +56,7 @@ def _cwd_release_wrapper(func):
except (FileNotFoundError, NotADirectoryError):
print_exception()
newpath = _chdir_up(pwd)
builtins.__xonsh_env__['PWD'] = newpath
builtins.__xonsh__.env['PWD'] = newpath
raise KeyboardInterrupt
return out
wrapper._orgfunc = func
@ -68,7 +68,7 @@ def _cwd_restore_wrapper(func):
directory. Designed to wrap completer callbacks from the
prompt_toolkit or readline.
"""
env = builtins.__xonsh_env__
env = builtins.__xonsh__.env
if env.get('UPDATE_PROMPT_ON_KEYPRESS'):
return func if not hasattr(func, '_orgfunc') else func._orgfunc

View file

@ -28,9 +28,9 @@ def complete_jedi(prefix, line, start, end, ctx):
"""Jedi-based completer for Python-mode."""
if not HAS_JEDI:
return set()
src = builtins.__xonsh_shell__.shell.accumulated_inputs + line
src = builtins.__xonsh__.shell.shell.accumulated_inputs + line
script = jedi.api.Interpreter(src, [ctx], column=end)
if builtins.__xonsh_env__.get('CASE_SENSITIVE_COMPLETIONS'):
if builtins.__xonsh__.env.get('CASE_SENSITIVE_COMPLETIONS'):
rtn = {x.name_with_symbols for x in script.completions()
if x.name_with_symbols.startswith(prefix)}
else:
@ -39,7 +39,7 @@ def complete_jedi(prefix, line, start, end, ctx):
# register the completer
builtins.__xonsh_ctx__['complete_jedi'] = complete_jedi
builtins.__xonsh__.ctx['complete_jedi'] = complete_jedi
completer add jedi complete_jedi end
completer remove python_mode
del builtins.__xonsh_ctx__['complete_jedi']
del builtins.__xonsh__.ctx['complete_jedi']

View file

@ -32,7 +32,7 @@ def pylab_helpers():
def interactive_pyplot(module=None, **kwargs):
"""This puts pyplot in interactive mode once it is imported."""
if module.__name__ != 'matplotlib.pyplot' or \
not __xonsh_env__.get('XONSH_INTERACTIVE'):
not __xonsh__.env.get('XONSH_INTERACTIVE'):
return
# Since we are in interactive mode, let's monkey-patch plt.show
# to try to never block.

View file

@ -152,7 +152,7 @@ def display_figure_with_iterm2(fig):
def show():
'''Run the mpl display sequence by printing the most recent figure to console'''
try:
minimal = __xonsh_env__['XONTRIB_MPL_MINIMAL']
minimal = __xonsh__.env['XONTRIB_MPL_MINIMAL']
except KeyError:
minimal = XONTRIB_MPL_MINIMAL_DEFAULT
fig = plt.gcf()

View file

@ -107,12 +107,12 @@ class Vox(collections.abc.Mapping):
"""
def __init__(self):
if not builtins.__xonsh_env__.get('VIRTUALENV_HOME'):
if not builtins.__xonsh__.env.get('VIRTUALENV_HOME'):
home_path = os.path.expanduser('~')
self.venvdir = os.path.join(home_path, '.virtualenvs')
builtins.__xonsh_env__['VIRTUALENV_HOME'] = self.venvdir
builtins.__xonsh__.env['VIRTUALENV_HOME'] = self.venvdir
else:
self.venvdir = builtins.__xonsh_env__['VIRTUALENV_HOME']
self.venvdir = builtins.__xonsh__.env['VIRTUALENV_HOME']
def create(self, name, *, system_site_packages=False, symlinks=False,
with_pip=True):
@ -197,7 +197,7 @@ class Vox(collections.abc.Mapping):
the current one (throws a KeyError if there isn't one).
"""
if name is ...:
env_paths = [builtins.__xonsh_env__['VIRTUAL_ENV']]
env_paths = [builtins.__xonsh__.env['VIRTUAL_ENV']]
elif isinstance(name, PathLike):
env_paths = [fspath(name)]
else:
@ -254,9 +254,9 @@ class Vox(collections.abc.Mapping):
Returns None if no environment is active.
"""
if 'VIRTUAL_ENV' not in builtins.__xonsh_env__:
if 'VIRTUAL_ENV' not in builtins.__xonsh__.env:
return
env_path = builtins.__xonsh_env__['VIRTUAL_ENV']
env_path = builtins.__xonsh__.env['VIRTUAL_ENV']
if env_path.startswith(self.venvdir):
name = env_path[len(self.venvdir):]
if name[0] in '/\\':
@ -274,7 +274,7 @@ class Vox(collections.abc.Mapping):
name : str
Virtual environment name or absolute path.
"""
env = builtins.__xonsh_env__
env = builtins.__xonsh__.env
ve = self[name]
if 'VIRTUAL_ENV' in env:
self.deactivate()
@ -291,7 +291,7 @@ class Vox(collections.abc.Mapping):
"""
Deactivate the active virtual environment. Returns its name.
"""
env = builtins.__xonsh_env__
env = builtins.__xonsh__.env
if 'VIRTUAL_ENV' not in env:
raise NoEnvironmentActive('No environment currently active.')