Skip to content

Commit

Permalink
Standalone support (#5)
Browse files Browse the repository at this point in the history
* standalone support
  • Loading branch information
jaykv authored May 14, 2023
1 parent b9501c3 commit 28be20d
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 210 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
check: lint test

SOURCE_FILES=pybash.py test_pybash.py run.py
SOURCE_FILES=pybash test_pybash.py run.py

install:
pip install -e .
Expand Down Expand Up @@ -39,4 +39,7 @@ lint:
shell:
source $(poetry env info --path)/bin/activate

debug:
python -m ideas demo -a pybash.hook -s

.PHONY: test clean
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@ Streamline bash-command execution from python with a new syntax. It combines the

For security and performance reasons, PyBash will NOT execute as shell, unless explicitly specified with a `$` instead of a single `>` before the command. While running commands as shell can be convenient, it can also spawn security risks if you're not too careful. If you're curious about the transformations, look at the [unit tests](test_pybash.py) for some quick examples.

Note: this is a mainly experimental library. Consider the risks and test before using in prod.
Note: this is a mainly experimental library.

# Installation
# Setup

## As standalone transformer
`pip install pybash`

# Setup hook

```python
import pybash
pybash.add_hook()
from pybash.transformer import transform

transform(">echo hello world") # returns the python code for the bash command as string
```

## As ideas hook
`pip install "pybash[ideas]"`

See [run.py](run.py) for an example.

# Usage

### 1. Simple execution with output
Expand Down Expand Up @@ -149,5 +157,5 @@ cp_test()
#### Demo
`python run.py`

#### Debugging
`python -m ideas demo -a pybash -s` to view the transformed source code
#### Debug
`make debug` to view the transformed source code
4 changes: 2 additions & 2 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

# dynamic interpolation
options = {'version': '-v', 'help': '-h'}
>git {{{options['help']}}}
>git f{options['help']}

namespace = "coffee"
>kubectl get pods {{{"--" + "-".join(['show', 'labels'])}}} --namespace {{{namespace}}}
>kubectl get pods f{"--" + "-".join(['show', 'labels'])} --namespace f{namespace}

# static interpolation
git_command = "status"
Expand Down
Loading

0 comments on commit 28be20d

Please sign in to comment.