Skip to content

Commit

Permalink
Merge pull request #736 from axsaucedo/735_bash_default
Browse files Browse the repository at this point in the history
Contrib bash command to provide a default baked function for simplicity of usage
  • Loading branch information
amoffat authored Oct 9, 2024
2 parents 89975df + 5e5b50d commit f145e6d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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 }}

Expand All @@ -92,24 +92,24 @@ 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@v2
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
needs: test
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

Expand All @@ -118,13 +118,13 @@ jobs:
pip install coverage coveralls
- name: Download coverage artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
path: coverage-artifacts

- 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:
Expand All @@ -143,7 +143,7 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Get current version
id: get_version
Expand All @@ -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

Expand Down
26 changes: 26 additions & 0 deletions docs/source/sections/contrib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=========

Expand Down
6 changes: 6 additions & 0 deletions sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f145e6d

Please sign in to comment.