From 295e7f0582ff7399144939c4a56a85379417003d Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Thu, 20 Jun 2024 16:02:48 +0200 Subject: [PATCH] xonshrc: add docs and tests for py files (#5515) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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> --- docs/xonshrc.rst | 4 ++-- tests/test_integrations.py | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/docs/xonshrc.rst b/docs/xonshrc.rst index 3a086e391..dfb22591f 100644 --- a/docs/xonshrc.rst +++ b/docs/xonshrc.rst @@ -7,7 +7,7 @@ exactly once at startup. The control file usually contains: * Assignment statements setting `environment variables `_. 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`"). +* ``xontrib`` commands to load selected add-ins (`xontribs `_). * Xonsh function definitions. * `Alias definitions `_, 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. * 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: diff --git a/tests/test_integrations.py b/tests/test_integrations.py index fa2d038bd..24903c13f 100644 --- a/tests/test_integrations.py +++ b/tests/test_integrations.py @@ -1358,18 +1358,27 @@ def test_alias_stability_exception(): @pytest.mark.parametrize( "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.*"], ["-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')", - ".*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", - ".*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.*"], ["-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.*"], ], ) -# @pytest.mark.flaky(reruns=3, reruns_delay=2) def test_xonshrc(tmpdir, cmd, exp): # ~/.xonshrc home = tmpdir.mkdir("home") @@ -1397,12 +1405,16 @@ def test_xonshrc(tmpdir, cmd, exp): (home_config_xonsh_rcd / "rcd1.xsh").write_text( "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 (rc_xsh := home / "rc.xsh").write_text("echo RCXSH", 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_dir = [str(home_config_xonsh_rcd)]