From df22611b5b0dfb9ed92ad7bcb14405fda1787a35 Mon Sep 17 00:00:00 2001 From: Alexander Shadchin Date: Sun, 16 Jun 2024 07:39:10 +0300 Subject: [PATCH 01/10] Simplify import --- sh.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sh.py b/sh.py index 590dd9b3..549a7550 100644 --- a/sh.py +++ b/sh.py @@ -24,11 +24,7 @@ # =============================================================================== import asyncio from collections import deque - -try: - from collections.abc import Mapping -except ImportError: # pragma: no cover - from collections.abc import Mapping +from collections.abc import Mapping import errno import fcntl From fc96a1b96cdd9e970f279d8592248635d37edbc4 Mon Sep 17 00:00:00 2001 From: Ryan Rawdon Date: Mon, 17 Jun 2024 14:04:38 -0400 Subject: [PATCH 02/10] Fixes #707 bad docuentation URLs --- sh.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sh.py b/sh.py index 549a7550..6c289c77 100644 --- a/sh.py +++ b/sh.py @@ -1,5 +1,6 @@ """ -http://amoffat.github.io/sh/ +https://sh.readthedocs.io/en/latest/ +https://github.com/amoffat/sh """ # =============================================================================== # Copyright (C) 2011-2023 by Andrew Moffat @@ -1094,7 +1095,7 @@ def fg_validator(passed_kwargs, merged_kwargs): msg = """\ _fg is invalid with nearly every other option, see warning and workaround here: - https://amoffat.github.io/sh/sections/special_arguments.html#fg""" + https://sh.readthedocs.io/en/latest/sections/special_arguments.html#fg""" allowlist = {"env", "fg", "cwd", "ok_code"} offending = set(passed_kwargs.keys()) - allowlist From e71a249033f64fc4bf2626cf7c7eb60fe323cb3c Mon Sep 17 00:00:00 2001 From: Erik Cederstrand Date: Tue, 30 Jul 2024 13:03:59 +0200 Subject: [PATCH 03/10] Remove mention of pbs. Fixes #720 While here, use official spelling ofg supported OS'es. --- sh.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sh.py b/sh.py index 6c289c77..556df8ff 100644 --- a/sh.py +++ b/sh.py @@ -72,9 +72,7 @@ if "windows" in platform.system().lower(): # pragma: no cover raise ImportError( - f"sh {__version__} is currently only supported on linux and osx. \ -please install pbs 0.110 (http://pypi.python.org/pypi/pbs) for windows \ -support." + f"sh {__version__} is currently only supported on Linux and macOS." ) TEE_STDOUT = {True, "out", 1} From 8b6eca23722fbe5080527c732917a508ee67c55e Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Fri, 6 Sep 2024 12:41:58 -0400 Subject: [PATCH 04/10] Update index.rst Don't mention specific versions so the doc doesn't look out of date as you continue to support newer versions of Python. --- docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index fd2e550a..f1a2993c 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -33,7 +33,7 @@ sh :target: https://github.com/amoffat/sh :alt: Github -sh is a full-fledged subprocess replacement for Python 3.8 - 3.11, PyPy that +sh is a full-fledged subprocess replacement for Python 3.8+, and PyPy that allows you to call any program as if it were a function: From 8d7aeaaa6639457d1fdc2db6a5755a6a59c6c0fa Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 6 Oct 2024 12:03:33 +0200 Subject: [PATCH 05/10] Added contrib command Signed-off-by: Alejandro Saucedo --- sh.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sh.py b/sh.py index 556df8ff..4a83a3ac 100644 --- a/sh.py +++ b/sh.py @@ -3471,6 +3471,12 @@ def git(orig): # pragma: no cover return cmd +@contrib("bash") +def bash(orig): + cmd = orig.bake("-c") + return cmd + + @contrib("sudo") def sudo(orig): # pragma: no cover """a nicer version of sudo that uses getpass to ask for a password, or From 1c79351bb2177c62eee8c479b5111b6ae61f9d8e Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 6 Oct 2024 12:08:18 +0200 Subject: [PATCH 06/10] Added documentation for bash contrib command Signed-off-by: Alejandro Saucedo --- docs/source/sections/contrib.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/source/sections/contrib.rst b/docs/source/sections/contrib.rst index c18877ee..dd189437 100644 --- a/docs/source/sections/contrib.rst +++ b/docs/source/sections/contrib.rst @@ -130,6 +130,32 @@ this. The currently written character. + +.. _contrib_bash: + +Bash +--- + +Often users may find themselves having to run bash commands directly, whether due +to commands having special characters (e.g. dash, or dot) or other reasons. +This can lead into recurrently having to bake the ``bash`` command to call it directly. To +account for this, the contrib version provides a ``bash`` command baked in: + +.. py:function:: bash(*args, **kwargs) + + Call bash with the prefix of "bash -c [...]". + +.. code-block:: python + + from sh.contrib import bash + + # Calling commands directly + bash.ls() # equivallent to "bash -c ls" + + # Or adding the full commands + bash("command-with-dashes args") + + Extending ========= From 824f9feccc8a3178ae83209f5ea68aa6ab2899dd Mon Sep 17 00:00:00 2001 From: Andrew Moffat Date: Tue, 8 Oct 2024 23:35:30 -0700 Subject: [PATCH 07/10] fixing action versions --- .github/workflows/main.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c8778236..2dabbdd2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,22 +14,22 @@ jobs: name: Lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Cache pip directory with: path: ~/.cache/pip key: ${{ runner.os }}-pip-3.9 - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Cache poetry deps with: path: .venv key: ${{ runner.os }}-build-${{ hashFiles('poetry.lock') }}-3.9 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9 @@ -60,15 +60,15 @@ jobs: lang: [C, en_US.UTF-8] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Cache pip directory with: path: ~/.cache/pip key: ${{ runner.os }}-pip-3.9 - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Cache poetry deps env: cache-name: poetry-deps @@ -77,7 +77,7 @@ jobs: key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('poetry.lock') }}-${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -95,7 +95,7 @@ jobs: SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=${{ matrix.use-select }} LANG=${{ matrix.lang }} poetry run coverage run -a -m pytest - name: Store coverage - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: coverage.${{ matrix.use-select }}.${{ matrix.lang }}.${{ matrix.python-version }} path: .coverage @@ -106,10 +106,10 @@ jobs: runs-on: ubuntu-latest steps: # required because coveralls complains if we're not in a git dir - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9 @@ -118,7 +118,7 @@ jobs: pip install coverage coveralls - name: Download coverage artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: path: coverage-artifacts @@ -143,7 +143,7 @@ jobs: id-token: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Get current version id: get_version @@ -155,7 +155,7 @@ jobs: git push -f origin "${{steps.get_version.outputs.version}}" - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9 From 5e5b50d4902883b9a7c56451ce63db06e513893d Mon Sep 17 00:00:00 2001 From: Andrew Moffat Date: Tue, 8 Oct 2024 23:44:13 -0700 Subject: [PATCH 08/10] fixing broken coverage --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2dabbdd2..5bed69cc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -92,13 +92,13 @@ jobs: - name: Run tests run: | - SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=${{ matrix.use-select }} LANG=${{ matrix.lang }} poetry run coverage run -a -m pytest + SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=${{ matrix.use-select }} LANG=${{ matrix.lang }} poetry run coverage run --data-file=coverage.data -a -m pytest - name: Store coverage uses: actions/upload-artifact@v4 with: name: coverage.${{ matrix.use-select }}.${{ matrix.lang }}.${{ matrix.python-version }} - path: .coverage + path: coverage.data report: name: Report Coverage @@ -124,7 +124,7 @@ jobs: - name: Combine coverage run: | - find coverage-artifacts -name .coverage | xargs coverage combine -a + find coverage-artifacts -name coverage.data | xargs coverage combine -a - name: Report coverage env: From 604b4fc82b73cc6cff1842d25c5fabe1efd2134b Mon Sep 17 00:00:00 2001 From: Andrew Moffat Date: Tue, 8 Oct 2024 23:56:23 -0700 Subject: [PATCH 09/10] automate release publishing --- .github/workflows/main.yml | 30 ++++++++++++++++++++------ dev_scripts/changelog_extract.py | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 dev_scripts/changelog_extract.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5bed69cc..0b51bfdf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -140,6 +140,7 @@ jobs: if: github.ref_name == 'master' permissions: + contents: write id-token: write steps: @@ -147,12 +148,7 @@ jobs: - name: Get current version id: get_version - run: echo "::set-output name=version::$(sed -n 's/^version = "\(.*\)"/\1/p' pyproject.toml)" - - - name: Tag commit - run: | - git tag "${{steps.get_version.outputs.version}}" "${{github.ref_name}}" - git push -f origin "${{steps.get_version.outputs.version}}" + run: echo "version=$(sed -n 's/^version = "\(.*\)"/\1/p' pyproject.toml)" >> $GITHUB_ENV - name: Set up Python uses: actions/setup-python@v5 @@ -165,5 +161,27 @@ jobs: - name: Build run: python -m build + - name: Tag commit + run: | + git tag "${{steps.get_version.outputs.version}}" "${{github.ref_name}}" + git push -f origin "${{steps.get_version.outputs.version}}" + + - name: Get changes + id: changelog + run: | + python dev_scripts/changelog_extract.py ${{ steps.get_version.outputs.version }} \ + > release_changes.md + + - name: Create Release + id: create-release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.get_version.outputs.version }} + name: Release ${{ steps.get_version.outputs.version }} + body_path: release_changes.md + draft: false + prerelease: false + files: dist/* + - name: Publish uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/dev_scripts/changelog_extract.py b/dev_scripts/changelog_extract.py new file mode 100644 index 00000000..06b06480 --- /dev/null +++ b/dev_scripts/changelog_extract.py @@ -0,0 +1,37 @@ +import re +import sys +from pathlib import Path +from typing import Iterable + +THIS_DIR = Path(__file__).parent +CHANGELOG = THIS_DIR.parent / "CHANGELOG.md" + + +def fetch_changes(changelog: Path, version: str) -> Iterable[str]: + with open(changelog, "r") as f: + lines = f.readlines() + + found_a_change = False + aggregate = False + for line in lines: + if line.startswith(f"## {version}"): + aggregate = True + + if aggregate: + if line.startswith("-"): + line = re.sub(r"-\s*", "", line).strip() + found_a_change = True + yield line + elif found_a_change: + aggregate = False + + return changes + + +version = sys.argv[1].strip() +changes = fetch_changes(CHANGELOG, version) +if not changes: + exit(1) + +for change in changes: + print("- " + change) From 695922ec1f559fc6cfc0424db5931bd37ed04d87 Mon Sep 17 00:00:00 2001 From: Andrew Moffat Date: Tue, 8 Oct 2024 23:58:02 -0700 Subject: [PATCH 10/10] 2.1.0 version bump --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a188e3e5..dda831bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.1.0 - 10/8/24 + +- Add contrib command `sh.contrib.bash` [#736](https://github.com/amoffat/sh/pull/736) + ## 2.0.7 - 5/31/24 - Fix `sh.glob` arguments [#708](https://github.com/amoffat/sh/issues/708) diff --git a/pyproject.toml b/pyproject.toml index a6da69b9..9b8b0348 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sh" -version = "2.0.7" +version = "2.1.0" description = "Python subprocess replacement" authors = ["Andrew Moffat "] readme = "README.rst"