After #5491 there is one case unfixed:

### Before
```xsh
echo 'echo home' >> ~/.xonshrc
cd /tmp
echo 'echo script' > 1.xsh

xonsh 1.xsh
# all rc without ~/.xonshrc
# script
xonsh -i 1.xsh
# all rc without ~/.xonshrc  # bug
# script
```

### After

```xsh
echo 'echo home' >> ~/.xonshrc
cd /tmp
echo 'echo script' > 1.xsh

xonsh 1.xsh
# all rc without ~/.xonshrc
# script
xonsh -i 1.xsh
# all rc with ~/.xonshrc
# home    # FIX
# script
```

## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Andy Kipp 2024-06-13 17:19:21 +02:00 committed by GitHub
parent f81d55d09b
commit 5ee386eed9
Failed to generate hash of commit
2 changed files with 52 additions and 1 deletions

View file

@ -1358,6 +1358,7 @@ def test_rc_no_xonshrc_for_non_interactive(tmpdir):
(rc_dir / "rc_dir.xsh").write_text("echo RC_DIR", encoding="utf8")
(user_home_dir / ".xonshrc").write_text("echo RC_HOME", encoding="utf8")
(script := user_home_dir / "script.xsh").write_text("echo SCRIPT", encoding="utf8")
user_home_rc_path_crossplatform = str(
(Path(user_home_dir) / ".xonshrc").expanduser()
)
@ -1375,6 +1376,25 @@ def test_rc_no_xonshrc_for_non_interactive(tmpdir):
]
cmd = "print(42+42)"
add_env = {"HOME": str(user_home_dir)}
# xonsh
out, err, ret = run_xonsh(
cmd=None,
stdin=None,
single_command=False,
interactive=True,
args=args,
add_env=add_env,
)
exp = ".*RC_NOT_HOME.*RC_HOME.*RC_DIR.*"
assert re.match(
exp,
out,
re.MULTILINE | re.DOTALL,
), f"Expected: {exp!r},\nResult: {out!r},\nargs={args!r}"
# xonsh -c "cmd"
out, err, ret = run_xonsh(cmd=cmd, interactive=False, args=args, add_env=add_env)
exp = ".*RC_NOT_HOME.*RC_DIR.*84.*"
assert re.match(
@ -1383,6 +1403,7 @@ def test_rc_no_xonshrc_for_non_interactive(tmpdir):
re.MULTILINE | re.DOTALL,
), f"Expected: {exp!r},\nResult: {out!r},\nargs={args!r}"
# xonsh -i -c "cmd"
out, err, ret = run_xonsh(
cmd=cmd + "\n", interactive=True, args=args, add_env=add_env
)
@ -1397,3 +1418,33 @@ def test_rc_no_xonshrc_for_non_interactive(tmpdir):
out,
re.MULTILINE | re.DOTALL,
), f"Expected: {exp!r},\nResult: {out!r},\nargs={args!r}"
# xonsh script.xsh
out, err, ret = run_xonsh(
cmd=cmd + "\n",
interactive=False,
single_command=False,
args=args + ["--", script],
add_env=add_env,
)
exp = ".*RC_NOT_HOME.*RC_DIR.*SCRIPT.*"
assert re.match(
exp,
out,
re.MULTILINE | re.DOTALL,
), f"Expected: {exp!r},\nResult: {out!r},\nargs={args!r}"
# xonsh -i script.xsh
out, err, ret = run_xonsh(
cmd=None,
interactive=False,
single_command=False,
args=args + ["-i", "--", script],
add_env=add_env,
)
exp = ".*RC_NOT_HOME.*RC_HOME.*RC_DIR.*SCRIPT.*"
assert re.match(
exp,
out,
re.MULTILINE | re.DOTALL,
), f"Expected: {exp!r},\nResult: {out!r},\nargs={args!r}"

View file

@ -309,7 +309,7 @@ def _get_rc_files(shell_kwargs: dict, args, env):
rc = env.get("XONSHRC")
rcd = env.get("XONSHRC_DIR")
if not env.get("XONSH_INTERACTIVE", False):
if not env.get("XONSH_INTERACTIVE", False) or not args.force_interactive:
"""
Home based ``~/.xonshrc`` file has special meaning and history. The ecosystem around shells treats this kind of files
as the place where interactive tools can add configs. To avoid unintended and unexpected affection