Python interfaces to system calls
Project description
manual
Python interfaces to system calls
To install: pip install manual
Examples
Write some "instructions" for someone with some placeholders like so:
template = """
git checkout {main_branch}
git pull
git checkout {to_merge_branch}
git merge {main_branch}
git push
"""
Then just make a function like this:
ri = mk_command_runner(template)
Then ri
is a function with a nice signature with arguments to control the
placeholders.
from inspect import signature
assert str(signature(ri)) == '(main_branch, to_merge_branch, *, _dry_run=False)'
If you call the function, it will run the commands one by one, printing
the command it's about the run and then the output of the run.
The _dry_run
allows one to just do the command prints without actually running
the commands:
print(ri('master', 'fixing_something', _dry_run=True))
(1/5)$ git checkout master
(2/5)$ git pull
(3/5)$ git checkout fixing_something
(4/5)$ git merge master
(5/5)$ git push
Note that you can also specify your commands as a list, and also ask that the commands be run one by one, asking the user to type any key to continue at every step:
pwd_and_ls = mk_command_runner(["pwd", "ls -l"], step_by_step=True)
pwd_and_ls()
(1/2)$ pwd
/Users/Thor.Whalen/Dropbox/dev/p3/proj/t/manual
TYPE ANY KEY TO CONTINUE
(2/2)$ ls -l
total 48
-rw-r--r--@ 1 Thor.Whalen staff 11357 Jun 15 21:00 LICENSE
-rw-r--r--@ 1 Thor.Whalen staff 1040 Jun 15 21:13 README.md
drwxr-xr-x@ 9 Thor.Whalen staff 288 Jun 15 21:00 docsrc
drwxr-xr-x@ 5 Thor.Whalen staff 160 Jun 15 21:04 manual
-rw-r--r--@ 1 Thor.Whalen staff 422 Jun 15 21:04 setup.cfg
-rw-r--r--@ 1 Thor.Whalen staff 91 Jun 15 21:00 setup.py
Where this is going
How many times do we write instructions for others, or ask others for us. Or perhaps we're even organized enough to have a little file where we put our little how-to recipes, commenting them with natural language so we can understand what the steps are, and simply be able to find those instructions when the time comes.
And then we go through those commands one by one, making sure we replace the right part of the instructions with the right values for our context, maybe trying to read the comments, so we know what we're doing.
Really though, we no extra effort but following some convention to make our instructions parsable, we can make our instructions, well, executable.
So instead of this:
git checkout {your_main_branch}
git pull
git checkout {your_branch}
git merge {your_main_branch}
# Now resolve conflics and press any key when ready for the next step
git commit -m {your_commit_message}
git push
just being that, we can take it as a DSL that will also give us:
- A function that does it all
- A function that will actually guide the user through the steps, explaining what's happening etc. (so also educational)
This means that we can then REUSE something like a markdown document that explains recipes, installation instructions, etc. also as boilerplate-less utils.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file manual-0.0.2.tar.gz
.
File metadata
- Download URL: manual-0.0.2.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.28.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cef8e1281c350a6060e176e2e3a046e3854f8a228a9d8634559ad82b88d5ecf7 |
|
MD5 | 188815da16a32e466d3ff1c8e69f7d71 |
|
BLAKE2b-256 | 22fa79a0d4d068db9333a22b715aa72d481f398d293c6d7379a916085c551720 |
File details
Details for the file manual-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: manual-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.28.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7396f6494286de45dcd53a7b27e67be0b03a00bb936e6a5e51127358879fdd20 |
|
MD5 | 3a024dd0a8f4435bd81c10957205192d |
|
BLAKE2b-256 | 8a877a5cee695878eabd3ec19356ba008d6a326f8979510b36316c6d36c6c0c2 |