def __init__(self, execer, ctx=None, shell_type=None, **kwargs): """ Parameters ---------- execer : Execer An execer instance capable of running xonsh code. ctx : Mapping, optional The execution context for the shell (e.g. the globals namespace). If none, this is computed by loading the rc files. If not None, this no additional context is computed and this is used directly. shell_type : str, optional The shell type to start, such as 'readline', 'prompt_toolkit', or 'random'. """ self.execer = execer self.ctx = {} if ctx is None else ctx env = builtins.__xonsh_env__ # build history backend before creating shell builtins.__xonsh_history__ = hist = xhm.construct_history( env=env.detype(), ts=[time.time(), None], locked=True) # pick a valid shell -- if no shell is specified by the user, # shell type is pulled from env if shell_type is None: shell_type = env.get('SHELL_TYPE') if shell_type == 'none': # This bricks interactive xonsh # Can happen from the use of .xinitrc, .xsession, etc shell_type = 'best' if shell_type == 'best' or shell_type is None: shell_type = best_shell_type() elif shell_type == 'random': shell_type = random.choice(('readline', 'prompt_toolkit')) if shell_type == 'prompt_toolkit': if not has_prompt_toolkit(): warnings.warn('prompt_toolkit is not available, using ' 'readline instead.') shell_type = 'readline' elif not ptk_version_is_supported(): warnings.warn('prompt-toolkit version < v1.0.0 is not ' 'supported. Please update prompt-toolkit. Using ' 'readline instead.') shell_type = 'readline' self.shell_type = env['SHELL_TYPE'] = shell_type # actually make the shell if shell_type == 'none': from xonsh.base_shell import BaseShell as shell_class elif shell_type == 'prompt_toolkit': from xonsh.ptk.shell import PromptToolkitShell as shell_class elif shell_type == 'readline': from xonsh.readline_shell import ReadlineShell as shell_class else: raise XonshError('{} is not recognized as a shell type'.format( shell_type)) self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs) # allows history garbage collector to start running if hist.gc is not None: hist.gc.wait_for_shell = False
def choose_shell_type(init_shell_type=None, env=None): # pick a valid shell -- if no shell is specified by the user, # shell type is pulled from env # extracted for testability shell_type = init_shell_type if shell_type is None and env: shell_type = env.get("SHELL_TYPE") if shell_type == "none": # This bricks interactive xonsh # Can happen from the use of .xinitrc, .xsession, etc # odd logic. We don't override if shell.__init__( shell_type="none"), # only if it come from environment? shell_type = "best" shell_type = Shell.shell_type_aliases.get(shell_type, shell_type) if shell_type == "best" or shell_type is None: shell_type = best_shell_type() elif env and env.get("TERM", "") == "dumb": shell_type = "dumb" elif shell_type == "random": shell_type = random.choice(("readline", "prompt_toolkit")) if shell_type == "prompt_toolkit": if not has_prompt_toolkit(): use_vended_prompt_toolkit() elif not ptk_above_min_supported(): warnings.warn( "Installed prompt-toolkit version < v{}.{}.{} is not ". format(*minimum_required_ptk_version) + "supported. Falling back to the builtin prompt-toolkit.") use_vended_prompt_toolkit() if init_shell_type in ("ptk1", "prompt_toolkit1"): warnings.warn( "$SHELL_TYPE='{}' now deprecated, please update your run control file'" .format(init_shell_type)) return shell_type
def __init__(self, ctx=None, shell_type=None, config=None, rc=None, **kwargs): """ Parameters ---------- ctx : Mapping, optional The execution context for the shell (e.g. the globals namespace). If none, this is computed by loading the rc files. If not None, this no additional context is computed and this is used directly. shell_type : str, optional The shell type to start, such as 'readline', 'prompt_toolkit', or 'random'. config : str, optional Path to configuration file. rc : list of str, optional Sequence of paths to run control files. """ self.login = kwargs.get('login', True) self.stype = shell_type self._init_environ(ctx, config, rc, kwargs.get('scriptcache', True), kwargs.get('cacheall', False)) env = builtins.__xonsh_env__ # pick a valid shell -- if no shell is specified by the user, # shell type is pulled from env if shell_type is None: shell_type = env.get('SHELL_TYPE') if shell_type == 'best' or shell_type is None: shell_type = best_shell_type() elif shell_type == 'random': shell_type = random.choice(('readline', 'prompt_toolkit')) if shell_type == 'prompt_toolkit': if not has_prompt_toolkit(): warnings.warn('prompt_toolkit is not available, using ' 'readline instead.') shell_type = 'readline' elif not ptk_version_is_supported(): warnings.warn('prompt-toolkit version < v1.0.0 is not ' 'supported. Please update prompt-toolkit. Using ' 'readline instead.') shell_type = 'readline' env['SHELL_TYPE'] = shell_type # actually make the shell if shell_type == 'none': from xonsh.base_shell import BaseShell as shell_class elif shell_type == 'prompt_toolkit': from xonsh.ptk.shell import PromptToolkitShell as shell_class elif shell_type == 'readline': from xonsh.readline_shell import ReadlineShell as shell_class else: raise XonshError( '{} is not recognized as a shell type'.format(shell_type)) self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs) # allows history garbace colector to start running builtins.__xonsh_history__.gc.wait_for_shell = False
def __init__(self, execer, ctx=None, shell_type=None, **kwargs): """ Parameters ---------- execer : Execer An execer instance capable of running xonsh code. ctx : Mapping, optional The execution context for the shell (e.g. the globals namespace). If none, this is computed by loading the rc files. If not None, this no additional context is computed and this is used directly. shell_type : str, optional The shell type to start, such as 'readline', 'prompt_toolkit', or 'random'. """ self.execer = execer self.ctx = {} if ctx is None else ctx env = builtins.__xonsh_env__ # build history backend before creating shell builtins.__xonsh_history__ = hist = xhm.construct_history( env=env.detype(), ts=[time.time(), None], locked=True) # pick a valid shell -- if no shell is specified by the user, # shell type is pulled from env if shell_type is None: shell_type = env.get('SHELL_TYPE') if shell_type == 'none': # This bricks interactive xonsh # Can happen from the use of .xinitrc, .xsession, etc shell_type = 'best' if shell_type == 'best' or shell_type is None: shell_type = best_shell_type() elif shell_type == 'random': shell_type = random.choice(('readline', 'prompt_toolkit')) if shell_type == 'prompt_toolkit': if not has_prompt_toolkit(): warnings.warn('prompt_toolkit is not available, using ' 'readline instead.') shell_type = 'readline' elif not ptk_version_is_supported(): warnings.warn('prompt-toolkit version < v1.0.0 is not ' 'supported. Please update prompt-toolkit. Using ' 'readline instead.') shell_type = 'readline' self.shell_type = env['SHELL_TYPE'] = shell_type # actually make the shell if shell_type == 'none': from xonsh.base_shell import BaseShell as shell_class elif shell_type == 'prompt_toolkit': from xonsh.ptk.shell import PromptToolkitShell as shell_class elif shell_type == 'readline': from xonsh.readline_shell import ReadlineShell as shell_class else: raise XonshError( '{} is not recognized as a shell type'.format(shell_type)) self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs) # allows history garbage collector to start running if hist.gc is not None: hist.gc.wait_for_shell = False
def __init__(self, ctx=None, shell_type=None, config=None, rc=None, **kwargs): """ Parameters ---------- ctx : Mapping, optional The execution context for the shell (e.g. the globals namespace). If none, this is computed by loading the rc files. If not None, this no additional context is computed and this is used directly. shell_type : str, optional The shell type to start, such as 'readline', 'prompt_toolkit', or 'random'. config : str, optional Path to configuration file. rc : list of str, optional Sequence of paths to run control files. """ self.login = kwargs.get('login', True) self.stype = shell_type self._init_environ(ctx, config, rc, kwargs.get('scriptcache', True), kwargs.get('cacheall', False)) env = builtins.__xonsh_env__ # pick a valid shell -- if no shell is specified by the user, # shell type is pulled from env if shell_type is None: shell_type = env.get('SHELL_TYPE') if shell_type == 'best' or shell_type is None: shell_type = best_shell_type() elif shell_type == 'random': shell_type = random.choice(('readline', 'prompt_toolkit')) if shell_type == 'prompt_toolkit': if not has_prompt_toolkit(): warnings.warn('prompt_toolkit is not available, using ' 'readline instead.') shell_type = 'readline' elif not ptk_version_is_supported(): warnings.warn('prompt-toolkit version < v1.0.0 is not ' 'supported. Please update prompt-toolkit. Using ' 'readline instead.') shell_type = 'readline' env['SHELL_TYPE'] = shell_type # actually make the shell if shell_type == 'none': from xonsh.base_shell import BaseShell as shell_class elif shell_type == 'prompt_toolkit': from xonsh.ptk.shell import PromptToolkitShell as shell_class elif shell_type == 'readline': from xonsh.readline_shell import ReadlineShell as shell_class else: raise XonshError('{} is not recognized as a shell type'.format( shell_type)) self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs) # allows history garbace colector to start running builtins.__xonsh_history__.gc.wait_for_shell = False
def __init__(self, ctx=None, shell_type=None, config=None, rc=None, **kwargs): """ Parameters ---------- ctx : Mapping, optional The execution context for the shell (e.g. the globals namespace). If none, this is computed by loading the rc files. If not None, this no additional context is computed and this is used directly. shell_type : str, optional The shell type to start, such as 'readline', 'prompt_toolkit', or 'random'. config : str, optional Path to configuration file. rc : list of str, optional Sequence of paths to run control files. """ self.login = kwargs.get("login", True) self.stype = shell_type self._init_environ(ctx, config, rc, kwargs.get("scriptcache", True), kwargs.get("cacheall", False)) env = builtins.__xonsh_env__ # pick a valid shell -- if no shell is specified by the user, # shell type is pulled from env if shell_type is None: shell_type = env.get("SHELL_TYPE") if shell_type == "best" or shell_type is None: shell_type = best_shell_type() elif shell_type == "random": shell_type = random.choice(("readline", "prompt_toolkit")) if shell_type == "prompt_toolkit": if not has_prompt_toolkit(): warn("prompt_toolkit is not available, using readline instead.") shell_type = "readline" env["SHELL_TYPE"] = shell_type # actually make the shell if shell_type == "none": from xonsh.base_shell import BaseShell as shell_class elif shell_type == "prompt_toolkit": if ptk_version_info()[:2] < (1, 0): msg = ( "prompt-toolkit version < v1.0.0 is not supported, " "xonsh may not work as expected. Please update." ) warn(msg, RuntimeWarning) from xonsh.ptk.shell import PromptToolkitShell as shell_class elif shell_type == "readline": from xonsh.readline_shell import ReadlineShell as shell_class else: raise XonshError("{} is not recognized as a shell type".format(shell_type)) self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs) # allows history garbace colector to start running builtins.__xonsh_history__.gc.wait_for_shell = False
def __init__(self, execer, ctx=None, shell_type=None, **kwargs): """ Parameters ---------- execer : Execer An execer instance capable of running xonsh code. ctx : Mapping, optional The execution context for the shell (e.g. the globals namespace). If none, this is computed by loading the rc files. If not None, this no additional context is computed and this is used directly. shell_type : str, optional The shell type to start, such as 'readline', 'prompt_toolkit1', or 'random'. """ self.execer = execer self.ctx = {} if ctx is None else ctx env = builtins.__xonsh__.env # build history backend before creating shell builtins.__xonsh__.history = hist = xhm.construct_history( env=env.detype(), ts=[time.time(), None], locked=True) # pick a valid shell -- if no shell is specified by the user, # shell type is pulled from env if shell_type is None: shell_type = env.get("SHELL_TYPE") if shell_type == "none": # This bricks interactive xonsh # Can happen from the use of .xinitrc, .xsession, etc shell_type = "best" shell_type = self.shell_type_aliases.get(shell_type, shell_type) if shell_type == "best" or shell_type is None: shell_type = best_shell_type() elif env.get("TERM", "") == "dumb": shell_type = "dumb" elif shell_type == "random": shell_type = random.choice(("readline", "prompt_toolkit")) if shell_type == "prompt_toolkit": if not has_prompt_toolkit(): warnings.warn("prompt_toolkit is not available, using " "readline instead.") shell_type = "readline" elif not ptk_above_min_supported(): warnings.warn("prompt-toolkit version < v1.0.0 is not " "supported. Please update prompt-toolkit. Using " "readline instead.") shell_type = "readline" else: shell_type = ptk_shell_type() self.shell_type = env["SHELL_TYPE"] = shell_type # actually make the shell if shell_type == "none": from xonsh.base_shell import BaseShell as shell_class elif shell_type == "prompt_toolkit2": from xonsh.ptk2.shell import PromptToolkit2Shell as shell_class elif shell_type == "prompt_toolkit1": from xonsh.ptk.shell import PromptToolkitShell as shell_class elif shell_type == "readline": from xonsh.readline_shell import ReadlineShell as shell_class elif shell_type == "jupyter": from xonsh.jupyter_shell import JupyterShell as shell_class elif shell_type == "dumb": from xonsh.dumb_shell import DumbShell as shell_class else: raise XonshError( "{} is not recognized as a shell type".format(shell_type)) self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs) # allows history garbage collector to start running if hist.gc is not None: hist.gc.wait_for_shell = False
def __init__(self, execer, ctx=None, shell_type=None, **kwargs): """ Parameters ---------- execer : Execer An execer instance capable of running xonsh code. ctx : Mapping, optional The execution context for the shell (e.g. the globals namespace). If none, this is computed by loading the rc files. If not None, this no additional context is computed and this is used directly. shell_type : str, optional The shell type to start, such as 'readline', 'prompt_toolkit1', or 'random'. """ self.execer = execer self.ctx = {} if ctx is None else ctx env = builtins.__xonsh__.env # build history backend before creating shell builtins.__xonsh__.history = hist = xhm.construct_history( env=env.detype(), ts=[time.time(), None], locked=True ) # pick a valid shell -- if no shell is specified by the user, # shell type is pulled from env if shell_type is None: shell_type = env.get("SHELL_TYPE") if shell_type == "none": # This bricks interactive xonsh # Can happen from the use of .xinitrc, .xsession, etc shell_type = "best" shell_type = self.shell_type_aliases.get(shell_type, shell_type) if shell_type == "best" or shell_type is None: shell_type = best_shell_type() elif env.get("TERM", "") == "dumb": shell_type = "dumb" elif shell_type == "random": shell_type = random.choice(("readline", "prompt_toolkit")) if shell_type == "prompt_toolkit": if not has_prompt_toolkit(): warnings.warn( "prompt_toolkit is not available, using " "readline instead." ) shell_type = "readline" elif not ptk_above_min_supported(): warnings.warn( "prompt-toolkit version < v1.0.0 is not " "supported. Please update prompt-toolkit. Using " "readline instead." ) shell_type = "readline" else: shell_type = ptk_shell_type() self.shell_type = env["SHELL_TYPE"] = shell_type # actually make the shell if shell_type == "none": from xonsh.base_shell import BaseShell as shell_class elif shell_type == "prompt_toolkit2": from xonsh.ptk2.shell import PromptToolkit2Shell as shell_class elif shell_type == "prompt_toolkit1": from xonsh.ptk.shell import PromptToolkitShell as shell_class elif shell_type == "readline": from xonsh.readline_shell import ReadlineShell as shell_class elif shell_type == "jupyter": from xonsh.jupyter_shell import JupyterShell as shell_class elif shell_type == "dumb": from xonsh.dumb_shell import DumbShell as shell_class else: raise XonshError("{} is not recognized as a shell type".format(shell_type)) self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs) # allows history garbage collector to start running if hist.gc is not None: hist.gc.wait_for_shell = False