Don't load xonshrc is xonsh is running a script

As per discussions with @asmeurer -- if xonsh is being used to launch a script,
e.g.

```
xonsh run_my_cool_deploy.xsh
```

then it should not load the `xonshrc` file since this should be reserved for
interactive functionality and we don't want side effects in the script.

Basically, if you need a xontrib to be loaded for your script, load it in your
script
This commit is contained in:
Gil Forsyth 2017-07-15 12:09:05 -04:00
parent c787f9ab3a
commit 1f464fb193
2 changed files with 11 additions and 0 deletions

View file

@ -58,6 +58,14 @@ def test_premain_custom_rc(shell, tmpdir):
assert f.strpath in builtins.__xonsh_env__.get('XONSHRC')
def test_no_rc_with_script(shell, tmpdir):
builtins.__xonsh_env__ = Env(XONSH_CACHE_SCRIPTS=False)
f = tmpdir.join('wakkawakka')
f.write("print('hi')")
xonsh.main.premain(['--rc', f.strpath, 'tests/sample.xsh'])
assert not (builtins.__xonsh_env__.get('XONSH_INTERACTIVE'))
def test_premain_no_rc(shell, tmpdir):
xonsh.main.premain(['--no-rc'])
assert not builtins.__xonsh_env__.get('XONSHRC')

View file

@ -236,6 +236,9 @@ def start_services(shell_kwargs):
env = builtins.__xonsh_env__
rc = shell_kwargs.get('rc', None)
rc = env.get('XONSHRC') if rc is None else rc
if shell_kwargs['shell_type'] != 'none':
# 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()