mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
skip running some startup config stuff unless we're running in login mode
This commit is contained in:
parent
9e17489edf
commit
9a2837194f
5 changed files with 31 additions and 20 deletions
|
@ -735,13 +735,13 @@ def ensure_list_of_strs(x):
|
|||
return rtn
|
||||
|
||||
|
||||
def load_builtins(execer=None, config=None):
|
||||
def load_builtins(execer=None, config=None, login=False):
|
||||
"""Loads the xonsh builtins into the Python builtins. Sets the
|
||||
BUILTINS_LOADED variable to True.
|
||||
"""
|
||||
global BUILTINS_LOADED, ENV
|
||||
# private built-ins
|
||||
builtins.__xonsh_env__ = ENV = Env(default_env(config=config))
|
||||
builtins.__xonsh_env__ = ENV = Env(default_env(config=config, login=login))
|
||||
builtins.__xonsh_ctx__ = {}
|
||||
builtins.__xonsh_help__ = helper
|
||||
builtins.__xonsh_superhelp__ = superhelper
|
||||
|
@ -771,7 +771,8 @@ def load_builtins(execer=None, config=None):
|
|||
builtins.execx = None if execer is None else execer.exec
|
||||
builtins.compilex = None if execer is None else execer.compile
|
||||
builtins.default_aliases = builtins.aliases = Aliases(DEFAULT_ALIASES)
|
||||
#builtins.aliases.update(load_foreign_aliases(issue_warning=False))
|
||||
if login:
|
||||
builtins.aliases.update(load_foreign_aliases(issue_warning=False))
|
||||
# history needs to be started after env and aliases
|
||||
# would be nice to actually include non-detyped versions.
|
||||
builtins.__xonsh_history__ = History(env=ENV.detype(),
|
||||
|
|
|
@ -1182,15 +1182,18 @@ def windows_env_fixes(ctx):
|
|||
ctx['PWD'] = _get_cwd()
|
||||
|
||||
|
||||
def default_env(env=None, config=None):
|
||||
def default_env(env=None, config=None, login=True):
|
||||
"""Constructs a default xonsh environment."""
|
||||
# in order of increasing precedence
|
||||
ctx = dict(BASE_ENV)
|
||||
ctx.update(os.environ)
|
||||
conf = load_static_config(ctx, config=config)
|
||||
ctx.update(conf.get('env', ()))
|
||||
#ctx.update(load_foreign_envs(shells=conf.get('foreign_shells', DEFAULT_SHELLS),
|
||||
# issue_warning=False))
|
||||
if login:
|
||||
ctx = dict(BASE_ENV)
|
||||
ctx.update(os.environ)
|
||||
conf = load_static_config(ctx, config=config)
|
||||
ctx.update(conf.get('env', ()))
|
||||
ctx.update(load_foreign_envs(shells=conf.get('foreign_shells', DEFAULT_SHELLS),
|
||||
issue_warning=False))
|
||||
else:
|
||||
ctx = {}
|
||||
if ON_WINDOWS:
|
||||
windows_env_fixes(ctx)
|
||||
# finalize env
|
||||
|
|
|
@ -17,7 +17,7 @@ class Execer(object):
|
|||
"""Executes xonsh code in a context."""
|
||||
|
||||
def __init__(self, filename='<xonsh-code>', debug_level=0, parser_args=None,
|
||||
unload=True, config=None):
|
||||
unload=True, config=None, login=True):
|
||||
"""Parameters
|
||||
----------
|
||||
filename : str, optional
|
||||
|
@ -37,7 +37,7 @@ class Execer(object):
|
|||
self.debug_level = debug_level
|
||||
self.unload = unload
|
||||
self.ctxtransformer = ast.CtxAwareTransformer(self.parser)
|
||||
load_builtins(execer=self, config=config)
|
||||
load_builtins(execer=self, config=config, login=login)
|
||||
|
||||
def __del__(self):
|
||||
if self.unload:
|
||||
|
|
|
@ -160,7 +160,11 @@ def premain(argv=None):
|
|||
version = '/'.join(('xonsh', __version__)),
|
||||
print(version)
|
||||
exit()
|
||||
shell_kwargs = {'shell_type': args.shell_type, 'completer': False}
|
||||
shell_kwargs = {'shell_type': args.shell_type,
|
||||
'completer': False,
|
||||
'login': False}
|
||||
if args.login:
|
||||
shell_kwargs['login'] = True
|
||||
if args.config_path is None:
|
||||
shell_kwargs['config'] = args.config_path
|
||||
if args.norc:
|
||||
|
@ -178,13 +182,12 @@ def premain(argv=None):
|
|||
else:
|
||||
args.mode = MODE_INTERACTIVE
|
||||
shell_kwargs['completer'] = True
|
||||
shell_kwargs['login'] = True
|
||||
shell = builtins.__xonsh_shell__ = Shell(**shell_kwargs)
|
||||
from xonsh import imphooks
|
||||
env = builtins.__xonsh_env__
|
||||
if args.defines is not None:
|
||||
env.update([x.split('=', 1) for x in args.defines])
|
||||
if args.login:
|
||||
env['XONSH_LOGIN'] = True
|
||||
env['XONSH_INTERACTIVE'] = False
|
||||
if ON_WINDOWS:
|
||||
setup_win_unicode_console(env.get('WIN_UNICODE_CONSOLE', True))
|
||||
|
|
|
@ -73,6 +73,8 @@ class Shell(object):
|
|||
rc : list of str, optional
|
||||
Sequence of paths to run control files.
|
||||
"""
|
||||
self.login = kwargs['login']
|
||||
self.stype = shell_type
|
||||
self._init_environ(ctx, config, rc)
|
||||
env = builtins.__xonsh_env__
|
||||
# pick a valid shell
|
||||
|
@ -106,8 +108,6 @@ class Shell(object):
|
|||
self.shell = shell_class(execer=self.execer,
|
||||
ctx=self.ctx, **kwargs)
|
||||
# allows history garbace colector to start running
|
||||
self.shell = shell_class(execer=self.execer,
|
||||
ctx=self.ctx, **kwargs)
|
||||
builtins.__xonsh_history__.gc.wait_for_shell = False
|
||||
|
||||
def __getattr__(self, attr):
|
||||
|
@ -115,12 +115,16 @@ class Shell(object):
|
|||
return getattr(self.shell, attr)
|
||||
|
||||
def _init_environ(self, ctx, config, rc):
|
||||
self.execer = Execer(config=config)
|
||||
self.execer = Execer(config=config, login=self.login)
|
||||
env = builtins.__xonsh_env__
|
||||
if ctx is None:
|
||||
rc = env.get('XONSHRC') if rc is None else rc
|
||||
self.ctx = xonshrc_context(rcfiles=rc, execer=self.execer)
|
||||
if self.stype == 'none' and not self.login:
|
||||
self.ctx = {}
|
||||
else:
|
||||
rc = env.get('XONSHRC') if rc is None else rc
|
||||
self.ctx = xonshrc_context(rcfiles=rc, execer=self.execer)
|
||||
else:
|
||||
self.ctx = ctx
|
||||
env['XONSH_LOGIN'] = self.login
|
||||
builtins.__xonsh_ctx__ = self.ctx
|
||||
self.ctx['__name__'] = '__main__'
|
||||
|
|
Loading…
Add table
Reference in a new issue