Skip to content

Commit

Permalink
docs: fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
thearchitector committed Dec 1, 2023
1 parent 271dd7f commit 00a9d94
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
__pycache__
.pytest_cache
.mypy_cache
.ruff_cache

.venv
.pdm-python
.pdm-build

dist
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
# tee-subprocess

![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/thearchitector/tee-subprocess/ci.yaml?label=tests&style=flat-square)
![PyPI - Downloads](https://img.shields.io/pypi/dw/tee-subprocess?style=flat-square)

A subprocess replacement with tee support for both synchronous and asynchronous contexts.

## Usage
Supports Python 3.8+.

## Example

Just import the `run` function and use it as you would use `subprocess.run`.

```python
from subprocess_tee import run
from tee_subprocess import run

process = run(["python", "--version"], tee=True, text=True, capture_output=True)
# ==> Python 3.11.2
print(process.stdout)
# ==> Python 3.11.2
```

Changing `stdout` and `stderr` changes the location to which the `tee` occurs. You can supply any of the defined options in `subprocess` or `asyncio.subprocess`(`STDOUT`, `DEVNULL`, etc), as well as a writable text or binary file object.
Changing `stdout` and `stderr` changes the location to which the `tee` occurs. You can supply any of the defined options in `subprocess` or `asyncio.subprocess` (`STDOUT`, `DEVNULL`, etc), as well as a writable text or binary file object; if providing a text file object, you must specify `text = True`.

### Async

Internally, `subprocess_tee` utilizes `asyncio` to concurrently output and capture the subprocess logs. If an event loop is already running, `run` will return an awaitable coroutine. Otherwise, it will call `asyncio.run` for you. Practically, this means you can just treat `run` as a coroutine if you're in an async content; if you're not, just call it synchronously.
Internally, `tee_subprocess` utilizes `asyncio` to concurrently output and capture the subprocess logs. If an event loop is already running, `run` will return an awaitable coroutine. Otherwise, it will call `asyncio.run` for you. Practically, this means you can just treat `run` as a coroutine if you're in an async content; if you're not, just call it synchronously.

```python
async def main():
Expand All @@ -33,6 +36,10 @@ async def main():
asyncio.run(main())
```

## Alternatives

[subprocess-tee](https://github.com/pycontribs/subprocess-tee), the motivation for this library, has the same objective but fails to accommodate asynchronous applications and non-shell invocations. This library supports asynchronous contexts as well as direct, non-shell, program execution ("list-style" vs. "shell-style").

## License

MIT License
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tee-subprocess"
version = "1.0.0"
version = "1.0.0.post0"
description = "A subprocess replacement with tee support for both synchronous and asynchronous contexts."
authors = [
{name = "Elias Gabriel",email = "[email protected]"},
Expand All @@ -16,7 +16,6 @@ documentation = "https://github.com/thearchitector/tee-subprocess"
repository = "https://github.com/thearchitector/tee-subprocess"
changelog = "https://github.com/thearchitector/tee-subprocess/blob/main/CHANGELOG.md"


[tool.pdm.dev-dependencies]
dev = [
"pytest>=7.4.3",
Expand Down
Empty file added tee_subprocess/py.typed
Empty file.

0 comments on commit 00a9d94

Please sign in to comment.