From a185c65d1ce1d5ec4e64277d558e1c98f57ce449 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 00:24:03 +0200 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate (#5643) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.5.5 → v0.5.6](https://github.com/astral-sh/ruff-pre-commit/compare/v0.5.5...v0.5.6) - [github.com/pre-commit/mirrors-mypy: v1.11.0 → v1.11.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.11.0...v1.11.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index faeac3e7b..732b23289 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ default_language_version: repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: 'v0.5.5' + rev: 'v0.5.6' hooks: - id: ruff args: [., --fix, --exit-non-zero-on-fix] @@ -18,7 +18,7 @@ repos: pass_filenames: false - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v1.11.0' # Use the sha / tag you want to point at + rev: 'v1.11.1' # Use the sha / tag you want to point at hooks: - id: mypy pass_filenames: false From c0e0687376ed64e07ce95d12f014bf7ea59705e6 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Wed, 7 Aug 2024 22:39:00 +0200 Subject: [PATCH 2/3] docs: Update bash to xonsh guide (#5628) * update bash to xonsh * Update bash_to_xsh.rst * Update bash_to_xsh.rst * Update docs/bash_to_xsh.rst Co-authored-by: Jason R. Coombs * Update docs/bash_to_xsh.rst Co-authored-by: Jason R. Coombs --------- Co-authored-by: a <1@1.1> Co-authored-by: Jason R. Coombs --- docs/bash_to_xsh.rst | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/docs/bash_to_xsh.rst b/docs/bash_to_xsh.rst index d5834f723..abd94c6f9 100644 --- a/docs/bash_to_xsh.rst +++ b/docs/bash_to_xsh.rst @@ -1,11 +1,7 @@ Bash to Xonsh Translation Guide ================================ -As you have probably figured out by now, xonsh is not ``sh``-lang compliant. -If your muscles have memorized all of the Bash prestidigitations, this page -will help you put a finger on how to do the equivalent task in xonsh. - -For shell scripts, the recommended file extension is ``xsh``, and shebang -line is ``#!/usr/bin/env xonsh``. +Xonsh relies primarily on the Python syntax and is not a suitable replacement for `sh` and is thus considered a non-POSIX shell. +This page provides xonsh equivalents for common patterns in Bash. .. list-table:: :widths: 30 30 40 @@ -14,6 +10,16 @@ line is ``#!/usr/bin/env xonsh``. * - Bash - Xonsh - Notes + * - No special object for represent session. + - ``__xonsh__`` + - The ``__xonsh__`` object has all about current xonsh session e.g. ``__xonsh__.env``. + You can set ``X = __xonsh__`` to have a shortcut for ``X.env`` and similar. + * - ``script.sh`` + - ``script.xsh`` + - The recommended file extension is ``.xsh``. + * - ``#!/bin/bash`` + - ``#!/usr/bin/env xonsh`` + - Use ``xonsh`` in the shebang. * - ``echo --arg="val"`` ``echo {}`` @@ -33,7 +39,8 @@ line is ``#!/usr/bin/env xonsh``. characters, words or brackets. * - ``IFS`` - ``$XONSH_SUBPROC_OUTPUT_FORMAT`` - - Changing the output representation and splitting. + - Changing the output representation and splitting. Also take a look into ``DecoratorAlias`` + to have an ability to return object e.g. ``j = $(@json echo '{}')``. * - ``$NAME`` or ``${NAME}`` - ``$NAME`` - Look up an environment variable by name. @@ -59,7 +66,7 @@ line is ``#!/usr/bin/env xonsh``. * - ``ENV1=VAL1 command`` - ``$ENV1=VAL1 command`` - or ``with ${...}.swap(ENV1=VAL1): command`` + or ``with __xonsh__.env.swap(ENV1=VAL1): command`` - Set temporary environment variable(s) and execute the command. Use the second notation with an indented block to execute many commands in the same context. * - ``alias ll='ls -la'`` @@ -135,7 +142,7 @@ line is ``#!/usr/bin/env xonsh``. - Xonsh publishes a handful of containers, primarily targeting CI and automation use cases. All of them are published on `Docker Hub `_. * - ``exit 1`` - - ``exit(1)`` + - ``exit 1`` or ``exit(1)`` - Exiting from the current script. To understand how xonsh executes the subprocess commands try From a1846d05798763cfeba922ec3b9ec9b9d76aebf8 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Thu, 8 Aug 2024 14:26:33 +0200 Subject: [PATCH 3/3] Fix safe readlines: `AttributeError: 'NoneType' object has no attribute 'readlines'` (#5646) * fix * news * fix --------- Co-authored-by: a <1@1.1> --- news/fix_safe_readlines.rst | 23 +++++++++++++++++++++++ xonsh/procs/pipelines.py | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 news/fix_safe_readlines.rst diff --git a/news/fix_safe_readlines.rst b/news/fix_safe_readlines.rst new file mode 100644 index 000000000..fe4988298 --- /dev/null +++ b/news/fix_safe_readlines.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed exception "object has no attribute readlines" in case of redirect callable alias output. + +**Security:** + +* diff --git a/xonsh/procs/pipelines.py b/xonsh/procs/pipelines.py index eb136c64a..eec6c6c9e 100644 --- a/xonsh/procs/pipelines.py +++ b/xonsh/procs/pipelines.py @@ -62,6 +62,8 @@ def SIGNAL_MESSAGES(): def safe_readlines(handle, hint=-1): """Attempts to read lines without throwing an error.""" + if handle is None: + return [] try: lines = handle.readlines(hint) except OSError: @@ -276,7 +278,7 @@ class CommandPipeline: lines = b.splitlines(keepends=True) yield from lines self.end(tee_output=False) - elif self.captured == "stdout": + elif self.captured == "stdout" and stdout is not None: b = stdout.read() s = self._decode_uninew(b, universal_newlines=True) self.lines = s.splitlines(keepends=True)