Skip to content

Commit 511856d

Browse files
committed
refactor and cleanup
1 parent 3d1218a commit 511856d

File tree

9 files changed

+305
-200
lines changed

9 files changed

+305
-200
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
## Install
2828

2929
```
30-
pip install -U python-shellrunner
30+
pip install -U shellrunner
3131
```
3232

3333
## Usage
@@ -83,7 +83,7 @@ Because writing anything remotely complicated in bash kinda sucks :)
8383

8484
One of the primary advantages of ShellRunner's approach is that you can seamlessly swap between the shell and Python. Some things are just easier to do in a shell (e.g. pipelines) and a lot of things are easier/better in Python (control flow, error handling, etc).
8585

86-
Also, users of [fish](https://github.com/fish-shell/fish-shell) might know that it [does not offer a way to easily exit a script if a command fails](https://github.com/fish-shell/fish-shell/issues/510). ShellRunner adds `set -e` and `pipefail` like functionality to any shell. Leverage the improved syntax of your preferred shell and the (optional) saftey of bash.
86+
Also, users of [fish](https://github.com/fish-shell/fish-shell) might know that it [does not offer a way to easily exit a script if a command fails](https://github.com/fish-shell/fish-shell/issues/510). ShellRunner adds `set -e` and `pipefail` like functionality to any shell. Leverage the improved syntax of your preferred shell and the (optional) safety of bash.
8787

8888
### Similar Projects
8989

@@ -95,7 +95,7 @@ ShellRunner is very similar to zxpy and shellpy but aims to be more simple in it
9595

9696
## Advanced Usage
9797

98-
A note on compatability: ShellRunner should work with on any POSIX-compliant system (and shell). No Windows support at this time.
98+
A note on compatibility: ShellRunner should work with on any POSIX-compliant system (and shell). No Windows support at this time.
9999

100100
Confirmed compatible with `sh` (dash), `bash`, `zsh`, and `fish`.
101101

@@ -104,7 +104,7 @@ Commands are automatically run with the shell that invoked your python script (t
104104
```python
105105
# my_script.py
106106
X("echo hello | string match hello")
107-
# Works if my_script.py is executed under fish. Will obviously fail if using bash.
107+
# Works if my_script.py is executed under fish (string match). Will obviously fail if using bash.
108108
```
109109

110110
### Shell Command Result
@@ -186,7 +186,7 @@ X([
186186
There are a few keyword arguments you can provide to adjust the behavior of `X`:
187187

188188
```python
189-
X("command", shell="bash", check=True, show_output=True, show_commands=True)
189+
X("command", shell="bash", check=True, show_output=True, show_command=True)
190190
```
191191

192192
`shell: str` (Default: the invoking shell) - Shell that will be used to execute the commands. Can be a path or simply the name (e.g. "/bin/bash", "bash").
@@ -195,7 +195,7 @@ X("command", shell="bash", check=True, show_output=True, show_commands=True)
195195

196196
`show_output: bool` (Default: True) - If True, command output will be printed.
197197

198-
`show_commands: bool` (Default: True) - If True, the current command will be printed before execution.
198+
`show_command: bool` (Default: True) - If True, the current command will be printed before execution.
199199

200200
### Output
201201

@@ -212,7 +212,7 @@ shellrunner: echo hello world
212212
hello world
213213
```
214214

215-
To hide the `shellrunner:` lines, set `show_commands=False`.
215+
To hide the `shellrunner:` lines, set `show_command=False`.
216216

217217
To hide actual command output, set `show_output=False`.
218218

@@ -226,7 +226,7 @@ Each option also has a corresponding environment variable to allow you to set th
226226

227227
`show_output` = `SHELLRUNNER_SHOW_OUTPUT`
228228

229-
`show_commands` = `SHELLRUNNER_SHOW_COMMANDS`
229+
`show_command` = `SHELLRUNNER_SHOW_COMMAND`
230230

231231
Environment variables are evaluated on each call of `X`, so you could also do something like this:
232232

@@ -253,5 +253,5 @@ packages = packages.splitlines()
253253

254254
for package in packages:
255255
print(f"=== {package} ===")
256-
X(f"pip show {package} | grep -E 'Requires|Required-by'", show_commands=False)
256+
X(f"pip show {package} | grep -E 'Requires|Required-by'", show_command=False)
257257
```

pyproject.toml

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[project]
2-
name = "python-shellrunner"
2+
name = "shellrunner"
33
version = "0.3.5"
44
description = "Write safe shell scripts in Python."
55
authors = [
66
{name = "adamhl8", email = "[email protected]"},
77
]
88
dependencies = [
9-
"psutil>=5.9.5",
9+
"psutil>=5.9.6",
1010
]
1111
requires-python = ">=3.10"
1212
readme = "README.md"
@@ -24,43 +24,46 @@ classifiers = [
2424
keywords = ["shell", "scripting", "bash", "zsh", "fish"]
2525

2626
[project.urls]
27-
"Homepage" = "https://github.com/adamhl8/python-shellrunner"
28-
"Source" = "https://github.com/adamhl8/python-shellrunner"
29-
"Bug Tracker" = "https://github.com/adamhl8/python-shellrunner/issues"
27+
"Homepage" = "https://github.com/adamhl8/shellrunner"
28+
"Source" = "https://github.com/adamhl8/shellrunner"
29+
"Bug Tracker" = "https://github.com/adamhl8/shellrunner/issues"
3030

3131
[tool.rye]
3232
managed = true
3333
dev-dependencies = [
34-
"black>=23.9.1",
35-
"ruff>=0.0.292",
36-
"pytest>=7.4.2",
34+
"ruff>=0.1.7",
35+
"pytest>=7.4.3",
3736
"pyroma>=4.2",
38-
"types-psutil>=5.9.5.16",
37+
"types-psutil>=5.9.5.17",
3938
]
4039

4140
[tool.rye.scripts]
4241
test = "pytest shellrunner"
4342
"lint:pyright" = "pyright ."
4443
"lint:ruff" = "ruff check ."
45-
"lint:black" = "black --check ."
44+
"lint:ruff:format" = "ruff format --check ."
4645
"lint:pyroma" = "pyroma -n 10 ."
47-
lint = { chain = ["lint:pyright", "lint:ruff", "lint:black", "lint:pyroma"] }
48-
format = "black ."
46+
lint = { chain = ["lint:pyright", "lint:ruff", "lint:ruff:format", "lint:pyroma"] }
47+
format = "ruff format ."
4948

5049
[tool.pyright]
5150
typeCheckingMode = "strict"
5251

53-
[tool.black]
54-
line-length = 120
55-
target-version = ["py312"]
56-
5752
[tool.ruff]
5853
line-length = 120
59-
target-version = "py312"
60-
select = ["E", "F", "W", "I", "N", "UP", "BLE", "FBT", "B", "A", "COM", "C4", "T10", "EM", "EXE", "ISC", "ICN", "G",
61-
"INP", "PIE", "PYI", "PT", "Q", "RSE", "RET", "SLF", "SIM", "TID", "TCH", "ARG", "PTH", "ERA", "PL", "PLC", "PLE",
62-
"PLR", "PLW", "TRY", "RUF"]
63-
ignore = ["E501", "PLR0915", "PLR0912", "PLR0913", "PLC1901"]
54+
output-format = "grouped"
55+
56+
[tool.ruff.lint]
57+
select = ["ALL"]
58+
ignore = [
59+
"ANN101",
60+
# ruff conflicts
61+
"D203",
62+
"D213",
63+
# ruff format conflicts
64+
"COM812",
65+
"ISC001",
66+
]
6467

6568
[build-system]
6669
requires = ["hatchling"]

requirements-dev.lock

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,23 @@
77
# all-features: false
88

99
-e file:.
10-
black==23.9.1
1110
build==1.0.3
12-
certifi==2023.7.22
13-
charset-normalizer==3.3.0
14-
click==8.1.7
11+
certifi==2023.11.17
12+
charset-normalizer==3.3.2
1513
docutils==0.20.1
16-
idna==3.4
14+
idna==3.6
1715
iniconfig==2.0.0
18-
mypy-extensions==1.0.0
1916
packaging==23.2
20-
pathspec==0.11.2
21-
platformdirs==3.11.0
2217
pluggy==1.3.0
23-
psutil==5.9.5
24-
pygments==2.16.1
18+
psutil==5.9.6
19+
pygments==2.17.2
2520
pyproject-hooks==1.0.0
2621
pyroma==4.2
27-
pytest==7.4.2
22+
pytest==7.4.3
2823
requests==2.31.0
29-
ruff==0.0.292
30-
trove-classifiers==2023.9.19
31-
types-psutil==5.9.5.16
32-
urllib3==2.0.6
24+
ruff==0.1.7
25+
trove-classifiers==2023.11.29
26+
types-psutil==5.9.5.17
27+
urllib3==2.1.0
3328
# The following packages are considered to be unsafe in a requirements file:
34-
setuptools==68.2.2
29+
setuptools==69.0.2

requirements.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
# all-features: false
88

99
-e file:.
10-
psutil==5.9.5
10+
psutil==5.9.6

shellrunner/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
"""shellrunner package."""
2+
13
from ._exceptions import ShellCommandError, ShellCommandResult, ShellResolutionError, ShellRunnerError
24
from ._shellrunner import run as X # noqa: N812
35

46
__all__ = [
5-
"ShellCommandError",
7+
"X",
68
"ShellCommandResult",
9+
"ShellCommandError",
710
"ShellResolutionError",
811
"ShellRunnerError",
9-
"X",
1012
]

shellrunner/_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ShellRunnerError(RuntimeError):
1212

1313

1414
class ShellCommandError(ShellRunnerError):
15-
def __init__(self, message: str, result: ShellCommandResult):
15+
def __init__(self, message: str, result: ShellCommandResult) -> None:
1616
super().__init__(message)
1717
self.out = result.out
1818
self.status = result.status

0 commit comments

Comments
 (0)