xontrib: do not autoload xontribs in `xonsh --no-rc` mode (#5586)

* no rc no autoload

* docs

---------

Co-authored-by: a <1@1.1>
This commit is contained in:
Andy Kipp 2024-07-09 17:21:20 +02:00 committed by GitHub
parent 10a75ec8ac
commit 86d3f9427e
Failed to generate hash of commit
4 changed files with 31 additions and 3 deletions

View file

@ -25,6 +25,7 @@ In addition:
* Use ``xonsh --rc snail.xsh`` to run only a certain control file.
* Use ``xonsh -i script.xsh`` to run xonsh in interactive mode with loading all possible control files.
* Use ``xonsh --rc rc1.xsh rc2.xsh -- script.xsh`` to run scripts with multiple control files.
* You can create autoloadable `xontrib <tutorial_xontrib.html#loading-xontribs>`_ as alternative to run control file and reuse it as python package.
The options set per user override settings in the system-wide control file.

23
news/norc_noautoload.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* xontrib: Do not autoload xontribs in ``xonsh --no-rc`` mode.
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -1347,8 +1347,9 @@ class InterpreterSetting(Xettings):
class XontribSetting(Xettings):
"""Xontrib Settings"""
XONTRIBS_AUTOLOAD_DISABLED = Var(
XONTRIBS_AUTOLOAD_DISABLED = Var.with_default(
default=False,
type_str="bool",
doc="""\
Controls auto-loading behaviour of xontrib packages at the startup.
* Set this to ``True`` to disable autoloading completely.

View file

@ -361,8 +361,10 @@ def start_services(shell_kwargs, args, pre_env=None):
scriptcache=shell_kwargs.get("scriptcache", True),
cacheall=shell_kwargs.get("cacheall", False),
)
XSH.load(ctx=ctx, execer=execer, inherit_env=shell_kwargs.get("inherit_env", True))
events.on_timingprobe.fire(name="post_execer_init")
events.on_timingprobe.fire(name="pre_xonsh_session_load")
XSH.load(ctx=ctx, execer=execer, inherit_env=shell_kwargs.get("inherit_env", True))
events.on_timingprobe.fire(name="post_xonsh_session_load")
install_import_hooks(execer)
@ -370,6 +372,7 @@ def start_services(shell_kwargs, args, pre_env=None):
for k, v in pre_env.items():
env[k] = v
if not shell_kwargs.get("norc"):
_autoload_xontribs(env)
_load_rc_files(shell_kwargs, args, env, execer, ctx)
# create shell