Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
events.transmogrify("on_exit", "LoadEvent")
events.doc(
"on_exit",
"""
on_exit() -> None
Fired after all commands have been executed, before tear-down occurs.
NOTE: All the caveats of the ``atexit`` module also apply to this event.
""",
)
events.transmogrify("on_pre_cmdloop", "LoadEvent")
events.doc(
"on_pre_cmdloop",
"""
on_pre_cmdloop() -> None
Fired just before the command loop is started, if it is.
""",
)
events.transmogrify("on_post_cmdloop", "LoadEvent")
events.doc(
"on_post_cmdloop",
"""
on_post_cmdloop() -> None
Fired just after the command loop finishes, if it is.
from xonsh.proc import HiddenCommandPipeline
from xonsh.jobs import ignore_sigtstp
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
from xonsh.environ import xonshrc_context, make_args_env
from xonsh.built_ins import XonshSession, load_builtins, load_proxies
events.transmogrify("on_post_init", "LoadEvent")
events.doc(
"on_post_init",
"""
on_post_init() -> None
Fired after all initialization is finished and we're ready to do work.
NOTE: This is fired before the wizard is automatically started.
""",
)
events.transmogrify("on_exit", "LoadEvent")
events.doc(
"on_exit",
"""
on_exit() -> None
* ``rtn``: The result of the command executed (``0`` for success)
* ``out``: If xonsh stores command output, this is the output
* ``ts``: Timestamps, in the order of ``[starting, ending]``
""",
)
events.doc(
"on_pre_prompt",
"""
on_pre_prompt() -> None
Fires just before the prompt is shown
""",
)
events.doc(
"on_post_prompt",
"""
on_post_prompt() -> None
Fires just after the prompt returns
""",
)
def transform_command(src, show_diff=True):
"""Returns the results of firing the precommand handles."""
i = 0
limit = sys.getrecursionlimit()
lst = ""
raw = src
while src != lst:
to_itself,
swap_values,
ptk2_color_depth_setter,
is_str_str_dict,
to_str_str_dict,
dict_to_str,
)
from xonsh.ansi_colors import (
ansi_color_escape_code_to_name,
ansi_reverse_style,
ansi_style_by_name,
)
import xonsh.prompt.base as prompt
events.doc(
"on_envvar_new",
"""
on_envvar_new(name: str, value: Any) -> None
Fires after a new environment variable is created.
Note: Setting envvars inside the handler might
cause a recursion until the limit.
""",
)
events.doc(
"on_envvar_change",
"""
on_envvar_change(name: str, oldvalue: Any, newvalue: Any) -> None
events.doc(
"on_transform_command",
"""
on_transform_command(cmd: str) -> str
Fired to request xontribs to transform a command line. Return the transformed
command, or the same command if no transformation occurs. Only done for
interactive sessions.
This may be fired multiple times per command, with other transformers input or
output, so design any handlers for this carefully.
""",
)
events.doc(
"on_precommand",
"""
on_precommand(cmd: str) -> None
Fires just before a command is executed.
""",
)
events.doc(
"on_postcommand",
"""
on_postcommand(cmd: str, rtn: int, out: str or None, ts: list) -> None
Fires just after a command is executed. The arguments are the same as history.
Parameters:
NOTE: All the caveats of the ``atexit`` module also apply to this event.
""",
)
events.transmogrify("on_pre_rc", "LoadEvent")
events.doc(
"on_pre_rc",
"""
on_pre_rc() -> None
Fired just before rc files are loaded, if they are.
""",
)
events.transmogrify("on_post_rc", "LoadEvent")
events.doc(
"on_post_rc",
"""
on_post_rc() -> None
Fired just after rc files are loaded, if they are.
""",
)
def get_setproctitle():
"""Proxy function for loading process title"""
try:
from setproctitle import setproctitle as spt
except ImportError:
return
return spt
def setup_timings(argv):
global _timings
if "--timings" in argv:
events.doc(
"on_timingprobe",
"""
on_timingprobe(name: str) -> None
Fired to insert some timings into the startuptime list
""",
)
@events.on_timingprobe
def timing_on_timingprobe(name, **kw):
global _timings
_timings[name] = clock()
@events.on_post_cmdloop
def timing_on_post_cmdloop(**kw):
global _timings
from xonsh.shell import transform_command
from xonsh.platform import HAS_PYGMENTS, ON_WINDOWS
from xonsh.style_tools import (
partial_color_tokenize,
_TokenType,
DEFAULT_STYLE_DICT as _DEFAULT_STYLE_DICT,
)
from xonsh.lazyimps import pygments, pyghooks, winutils
from xonsh.pygments_cache import get_all_styles
from xonsh.lazyasd import LazyObject
Token = _TokenType()
events.transmogrify("on_ptk_create", "LoadEvent")
events.doc(
"on_ptk_create",
"""
on_ptk_create(prompter: Prompter, history: PromptToolkitHistory, completer: PromptToolkitCompleter, bindings: KeyBindingManager) ->
Fired after prompt toolkit has been initialized
""",
)
# Convert new ansicolor names to names
# understood by PTK1
DEFAULT_STYLE_DICT = LazyObject(
lambda: ansicolors_to_ptk1_names(_DEFAULT_STYLE_DICT),
globals(),
"DEFAULT_STYLE_DICT",
)
"on_import_post_find_spec",
"""
on_import_post_find_spec(spec, fullname, path, target) -> None
Fires after all import find_spec() calls have been executed. The parameters
here the spec and the arguments importlib.abc.MetaPathFinder.find_spec(). Namely,
:``spec``: A ModuleSpec object if the spec was found, or None if it was not.
:``fullname``: The full name of the module to import.
:``path``: None if a top-level import, otherwise the ``__path__`` of the parent
package.
:``target``: Target module used to make a better guess about the package spec.
""",
)
events.doc(
"on_import_pre_create_module",
"""
on_import_pre_create_module(spec: ModuleSpec) -> None
Fires right before a module is created by its loader. The only parameter
is the spec object. See importlib for more details.
""",
)
events.doc(
"on_import_post_create_module",
"""
on_import_post_create_module(module: Module, spec: ModuleSpec) -> None
Fires after a module is created by its loader but before the loader returns it.
The parameters here are the module object itself and the spec object.