def start_services(shell_kwargs, args): """Starts up the essential services in the proper order. This returns the environment instance as a convenience. """ install_import_hooks() # create execer, which loads builtins ctx = shell_kwargs.get('ctx', {}) debug = to_bool_or_int(os.getenv('XONSH_DEBUG', '0')) events.on_timingprobe.fire(name='pre_execer_init') execer = Execer(xonsh_ctx=ctx, debug_level=debug, scriptcache=shell_kwargs.get('scriptcache', True), cacheall=shell_kwargs.get('cacheall', False)) events.on_timingprobe.fire(name='post_execer_init') # load rc files login = shell_kwargs.get('login', True) env = builtins.__xonsh_env__ rc = shell_kwargs.get('rc', None) rc = env.get('XONSHRC') if rc is None else rc if args.mode != XonshMode.interactive and not args.force_interactive: # Don't load xonshrc if not interactive shell rc = None events.on_pre_rc.fire() xonshrc_context(rcfiles=rc, execer=execer, ctx=ctx, env=env, login=login) events.on_post_rc.fire() # create shell builtins.__xonsh_shell__ = Shell(execer=execer, **shell_kwargs) ctx['__name__'] = '__main__' return env
def start_services(shell_kwargs, args): """Starts up the essential services in the proper order. This returns the environment instance as a convenience. """ install_import_hooks() # create execer, which loads builtins ctx = shell_kwargs.get("ctx", {}) debug = to_bool_or_int(os.getenv("XONSH_DEBUG", "0")) events.on_timingprobe.fire(name="pre_execer_init") execer = Execer( xonsh_ctx=ctx, debug_level=debug, scriptcache=shell_kwargs.get("scriptcache", True), cacheall=shell_kwargs.get("cacheall", False), ) events.on_timingprobe.fire(name="post_execer_init") # load rc files login = shell_kwargs.get("login", True) env = builtins.__xonsh__.env rc = shell_kwargs.get("rc", None) rc = env.get("XONSHRC") if rc is None else rc if args.mode != XonshMode.interactive and not args.force_interactive: # Don't load xonshrc if not interactive shell rc = None events.on_pre_rc.fire() xonshrc_context(rcfiles=rc, execer=execer, ctx=ctx, env=env, login=login) events.on_post_rc.fire() # create shell builtins.__xonsh__.shell = Shell(execer=execer, **shell_kwargs) ctx["__name__"] = "__main__" return env
def start_services(shell_kwargs): """Starts up the essential services in the proper order. This returns the environment instance as a convenience. """ install_import_hooks() # create execer, which loads builtins ctx = shell_kwargs.get('ctx', {}) debug = to_bool_or_int(os.getenv('XONSH_DEBUG', '0')) events.on_timingprobe.fire(name='pre_execer_init') execer = Execer(xonsh_ctx=ctx, debug_level=debug, scriptcache=shell_kwargs.get('scriptcache', True), cacheall=shell_kwargs.get('cacheall', False)) events.on_timingprobe.fire(name='post_execer_init') # load rc files login = shell_kwargs.get('login', True) env = builtins.__xonsh_env__ rc = shell_kwargs.get('rc', None) rc = env.get('XONSHRC') if rc is None else rc events.on_pre_rc.fire() xonshrc_context(rcfiles=rc, execer=execer, ctx=ctx, env=env, login=login) events.on_post_rc.fire() # create shell builtins.__xonsh_shell__ = Shell(execer=execer, **shell_kwargs) ctx['__name__'] = '__main__' return env
def _init_environ(self, ctx, config, rc, scriptcache, cacheall): self.ctx = {} if ctx is None else ctx debug = to_bool_or_int(os.getenv('XONSH_DEBUG', '0')) self.execer = Execer(config=config, login=self.login, xonsh_ctx=self.ctx, debug_level=debug) self.execer.scriptcache = scriptcache self.execer.cacheall = cacheall if self.stype != 'none' or self.login: # load xontribs from config file names = builtins.__xonsh_config__.get('xontribs', ()) for name in names: update_context(name, ctx=self.ctx) if getattr(update_context, 'bad_imports', None): prompt_xontrib_install(update_context.bad_imports) del update_context.bad_imports # load run control files env = builtins.__xonsh_env__ rc = env.get('XONSHRC') if rc is None else rc self.ctx.update( xonshrc_context(rcfiles=rc, execer=self.execer, initial=self.ctx)) self.ctx['__name__'] = '__main__'
def start_services(shell_kwargs, args, pre_env=None): """Starts up the essential services in the proper order. This returns the environment instance as a convenience. """ if pre_env is None: pre_env = {} # create execer, which loads builtins ctx = shell_kwargs.get("ctx", {}) debug = to_bool_or_int(os.getenv("XONSH_DEBUG", "0")) events.on_timingprobe.fire(name="pre_execer_init") execer = Execer( filename="<stdin>", debug_level=debug, scriptcache=shell_kwargs.get("scriptcache", True), cacheall=shell_kwargs.get("cacheall", False), ) XSH.load(ctx=ctx, execer=execer) events.on_timingprobe.fire(name="post_execer_init") install_import_hooks(execer) env = XSH.env for k, v in pre_env.items(): env[k] = v _autoload_xontribs(env) _load_rc_files(shell_kwargs, args, env, execer, ctx) # create shell XSH.shell = Shell(execer=execer, **shell_kwargs) ctx["__name__"] = "__main__" return env
def to_debug(x): """Converts value using to_bool_or_int() and sets this value on as the execer's debug level. """ val = to_bool_or_int(x) if hasattr(builtins, "__xonsh_execer__"): builtins.__xonsh_execer__.debug_level = val return val
def to_debug(x): """Converts value using to_bool_or_int() and sets this value on as the execer's debug level. """ val = to_bool_or_int(x) if hasattr(builtins, '__xonsh_execer__'): builtins.__xonsh_execer__.debug_level = val return val
def start_services(shell_kwargs, args, pre_env=None): """Starts up the essential services in the proper order. This returns the environment instance as a convenience. """ if pre_env is None: pre_env = {} # create execer, which loads builtins ctx = shell_kwargs.get("ctx", {}) debug = to_bool_or_int(os.getenv("XONSH_DEBUG", "0")) events.on_timingprobe.fire(name="pre_execer_init") execer = Execer( debug_level=debug, scriptcache=shell_kwargs.get("scriptcache", True), cacheall=shell_kwargs.get("cacheall", False), ) XSH.load(ctx=ctx, execer=execer) events.on_timingprobe.fire(name="post_execer_init") install_import_hooks(execer) # load rc files login = shell_kwargs.get("login", True) rc_cli = shell_kwargs.get("rc") env = XSH.env for k, v in pre_env.items(): env[k] = v # determine which RC files to load, including whether any RC directories # should be scanned for such files if shell_kwargs.get("norc") or (args.mode != XonshMode.interactive and not args.force_interactive and not args.login): # if --no-rc was passed, or we're not in an interactive shell and # interactive mode was not forced, then disable loading RC files and dirs rc = () rcd = () elif rc_cli: # if an explicit --rc was passed, then we should load only that RC # file, and nothing else (ignore both XONSHRC and XONSHRC_DIR) rc = [r for r in rc_cli if os.path.isfile(r)] rcd = [r for r in rc_cli if os.path.isdir(r)] else: # otherwise, get the RC files from XONSHRC, and RC dirs from XONSHRC_DIR rc = env.get("XONSHRC") rcd = env.get("XONSHRC_DIR") events.on_pre_rc.fire() XSH.rc_files = xonshrc_context(rcfiles=rc, rcdirs=rcd, execer=execer, ctx=ctx, env=env, login=login) events.on_post_rc.fire() # create shell XSH.shell = Shell(execer=execer, **shell_kwargs) ctx["__name__"] = "__main__" return env
def _init_environ(self, ctx, config, rc, scriptcache, cacheall): self.ctx = {} if ctx is None else ctx debug = to_bool_or_int(os.getenv("XONSH_DEBUG", "0")) self.execer = Execer(config=config, login=self.login, xonsh_ctx=self.ctx, debug_level=debug) self.execer.scriptcache = scriptcache self.execer.cacheall = cacheall if self.stype != "none" or self.login: # load xontribs from config file names = builtins.__xonsh_config__.get("xontribs", ()) for name in names: xontribs.update_context(name, ctx=self.ctx) # load run control files env = builtins.__xonsh_env__ rc = env.get("XONSHRC") if rc is None else rc self.ctx.update(xonshrc_context(rcfiles=rc, execer=self.execer, initial=self.ctx)) self.ctx["__name__"] = "__main__"
def test_to_bool_or_int(): cases = [ (True, True), (False, False), (1, 1), (0, 0), ('', False), (0.0, False), (1.0, True), ('T', True), ('f', False), ('0', 0), ('10', 10), ] for inp, exp in cases: obs = to_bool_or_int(inp) assert exp == obs
def test_to_bool_or_int(): cases = [ (True, True), (False, False), (1, 1), (0, 0), ('', False), (0.0, False), (1.0, True), ('T', True), ('f', False), ('0', 0), ('10', 10), ] for inp, exp in cases: obs = to_bool_or_int(inp) yield assert_equal, exp, obs
def _init_environ(self, ctx, config, rc, scriptcache, cacheall): self.ctx = {} if ctx is None else ctx debug = to_bool_or_int(os.getenv('XONSH_DEBUG', '0')) self.execer = Execer(config=config, login=self.login, xonsh_ctx=self.ctx, debug_level=debug) self.execer.scriptcache = scriptcache self.execer.cacheall = cacheall if self.stype != 'none' or self.login: # load xontribs from config file names = builtins.__xonsh_config__.get('xontribs', ()) for name in names: update_context(name, ctx=self.ctx) if getattr(update_context, 'bad_imports', None): prompt_xontrib_install(update_context.bad_imports) del update_context.bad_imports # load run control files env = builtins.__xonsh_env__ rc = env.get('XONSHRC') if rc is None else rc self.ctx.update(xonshrc_context(rcfiles=rc, execer=self.execer, initial=self.ctx)) self.ctx['__name__'] = '__main__'
def test_to_bool_or_int(inp, exp): obs = to_bool_or_int(inp) assert exp == obs