xonshrc: add docs and tests for py files (#5515)

* Added py mention to docs
* Added tests
* Microfix

## 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-20 16:02:48 +02:00 committed by GitHub
parent 60db3e6138
commit 295e7f0582
Failed to generate hash of commit
2 changed files with 21 additions and 9 deletions

View file

@ -7,7 +7,7 @@ exactly once at startup.
The control file usually contains: The control file usually contains:
* Assignment statements setting `environment variables <envvars.html>`_. This includes standard OS environment variables that affect other programs and many that Xonsh uses for itself. * Assignment statements setting `environment variables <envvars.html>`_. This includes standard OS environment variables that affect other programs and many that Xonsh uses for itself.
* ``xontrib`` commands to load selected add-ins ("`xontribs<tutorial_xontrib.html#loading-xontribs>`"). * ``xontrib`` commands to load selected add-ins (`xontribs <tutorial_xontrib.html#loading-xontribs>`_).
* Xonsh function definitions. * Xonsh function definitions.
* `Alias definitions <aliases.html>`_, many of which invoke the above functions with specified arguments. * `Alias definitions <aliases.html>`_, many of which invoke the above functions with specified arguments.
@ -17,7 +17,7 @@ There are also a few places where Xonsh looks for run control files. These files
* Cross-desktop group (XDG) compliant ``~/.config/xonsh/rc.xsh`` control file. * Cross-desktop group (XDG) compliant ``~/.config/xonsh/rc.xsh`` control file.
* The system-wide control file ``/etc/xonsh/xonshrc`` for Linux and OSX and in ``%ALLUSERSPROFILE%\xonsh\xonshrc`` on Windows. It controls options that are applied to all users of Xonsh on a given system. * The system-wide control file ``/etc/xonsh/xonshrc`` for Linux and OSX and in ``%ALLUSERSPROFILE%\xonsh\xonshrc`` on Windows. It controls options that are applied to all users of Xonsh on a given system.
* The home-based directory ``~/.config/xonsh/rc.d/`` and system ``/etc/xonsh/rc.d/`` can contain ``.xsh`` files. They will be executed at startup in order. This allows for drop-in configuration where your configuration can be split across scripts and common and local configurations more easily separated. * The home-based directory ``~/.config/xonsh/rc.d/`` and system ``/etc/xonsh/rc.d/`` can contain ``.xsh`` or ``.py`` files. They will be executed at startup in order. This allows for drop-in configuration where your configuration can be split across scripts and common and local configurations more easily separated.
In addition: In addition:

View file

@ -1358,18 +1358,27 @@ def test_alias_stability_exception():
@pytest.mark.parametrize( @pytest.mark.parametrize(
"cmd,exp", "cmd,exp",
[ [
["-i", ".*CONFIG_XONSH_RC_XSH.*HOME_XONSHRC.*CONFIG_XONSH_RCD.*"], [
"-i",
".*CONFIG_XONSH_RC_XSH.*HOME_XONSHRC.*CONFIG_XONSH_RCD.*CONFIG_XONSH_PY_RCD.*",
],
["--rc rc.xsh", ".*RCXSH.*"], ["--rc rc.xsh", ".*RCXSH.*"],
["-i --rc rc.xsh", ".*RCXSH.*"], ["-i --rc rc.xsh", ".*RCXSH.*"],
["-c print('CMD')", ".*CONFIG_XONSH_RC_XSH.*CONFIG_XONSH_RCD.*CMD.*"], [
"-c print('CMD')",
".*CONFIG_XONSH_RC_XSH.*CONFIG_XONSH_RCD.*CONFIG_XONSH_PY_RCD.*CMD.*",
],
[ [
"-i -c print('CMD')", "-i -c print('CMD')",
".*CONFIG_XONSH_RC_XSH.*HOME_XONSHRC.*CONFIG_XONSH_RCD.*CMD.*", ".*CONFIG_XONSH_RC_XSH.*HOME_XONSHRC.*CONFIG_XONSH_RCD.*CONFIG_XONSH_PY_RCD.*CMD.*",
],
[
"script.xsh",
".*CONFIG_XONSH_RC_XSH.*CONFIG_XONSH_RCD.*CONFIG_XONSH_PY_RCD.*SCRIPT.*",
], ],
["script.xsh", ".*CONFIG_XONSH_RC_XSH.*CONFIG_XONSH_RCD.*SCRIPT.*"],
[ [
"-i script.xsh", "-i script.xsh",
".*CONFIG_XONSH_RC_XSH.*HOME_XONSHRC.*CONFIG_XONSH_RCD.*SCRIPT.*", ".*CONFIG_XONSH_RC_XSH.*HOME_XONSHRC.*CONFIG_XONSH_RCD.*CONFIG_XONSH_PY_RCD.*SCRIPT.*",
], ],
["--rc rc.xsh -- script.xsh", ".*RCXSH.*SCRIPT.*"], ["--rc rc.xsh -- script.xsh", ".*RCXSH.*SCRIPT.*"],
["-i --rc rc.xsh -- script.xsh", ".*RCXSH.*SCRIPT.*"], ["-i --rc rc.xsh -- script.xsh", ".*RCXSH.*SCRIPT.*"],
@ -1377,7 +1386,6 @@ def test_alias_stability_exception():
["-i --no-rc --rc rc.xsh -- script.xsh", ".*SCRIPT.*"], ["-i --no-rc --rc rc.xsh -- script.xsh", ".*SCRIPT.*"],
], ],
) )
# @pytest.mark.flaky(reruns=3, reruns_delay=2)
def test_xonshrc(tmpdir, cmd, exp): def test_xonshrc(tmpdir, cmd, exp):
# ~/.xonshrc # ~/.xonshrc
home = tmpdir.mkdir("home") home = tmpdir.mkdir("home")
@ -1397,12 +1405,16 @@ def test_xonshrc(tmpdir, cmd, exp):
(home_config_xonsh_rcd / "rcd1.xsh").write_text( (home_config_xonsh_rcd / "rcd1.xsh").write_text(
"echo CONFIG_XONSH_RCD", encoding="utf8" "echo CONFIG_XONSH_RCD", encoding="utf8"
) )
(home_config_xonsh_rcd / "rcd2.py").write_text(
"__xonsh__.print(__xonsh__.subproc_captured_stdout(['echo', 'CONFIG_XONSH_PY_RCD']))",
encoding="utf8",
)
# ~/home/rc.xsh # ~/home/rc.xsh
(rc_xsh := home / "rc.xsh").write_text("echo RCXSH", encoding="utf8") (rc_xsh := home / "rc.xsh").write_text("echo RCXSH", encoding="utf8")
(script_xsh := home / "script.xsh").write_text("echo SCRIPT_XSH", encoding="utf8") (script_xsh := home / "script.xsh").write_text("echo SCRIPT_XSH", encoding="utf8")
# Construct $XONSHRC and $XONSHRC_DIR # Construct $XONSHRC and $XONSHRC_DIR.
xonshrc_files = [str(home_config_xonsh_rc_xsh), str(home_xonsh_rc_path)] xonshrc_files = [str(home_config_xonsh_rc_xsh), str(home_xonsh_rc_path)]
xonshrc_dir = [str(home_config_xonsh_rcd)] xonshrc_dir = [str(home_config_xonsh_rcd)]