docs: add more full fledged documentation

This commit is contained in:
Daylin Morgan 2023-03-09 14:58:01 -06:00
parent e548487918
commit b9100ca2a1
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
2 changed files with 36 additions and 6 deletions

View file

@ -13,6 +13,22 @@
See [usage](https://github.com/daylinmorgan/viv/blob/main/docs/usage.md) for more demo gifs.
---
Python is a great choice to quickly prototype or accomplish small tasks in scripts.
However, leveraging it's vast ecosystem can be tedious for one-off or rarely used scripts.
This is were `viv` comes in handy.
`Viv` is a standalone dependency-free `venv` creator.
It is meant to be invoked in any script that has third-party dependencies,
prior to loading of any of the external modules.
These `venvs` can be identified by name or by their specification.
In any case they will be re-used across scripts (and generated on-demand, if needed).
**Importantly**, `viv` will remove your user site directory (`python -m 'import site;print(site.USER_SITE)'`),
to ensure the script isn't using anything outside the standard library and the `viv`-managed `venv`.
## Setup
### Manual (Recommended)
@ -33,35 +49,47 @@ Place this directory on the python path in your rc file.
export PYTHONPATH="$PYTHONPATH:$HOME/.viv/src"
```
Advanced users may recognize that principally,
the module just needs to be recognized at run time
and the single script at `./src/viv/viv.py` can be invoked directly for the CLI.
How you accomplish these options is ultimately up to you but the above instructions can get you started.
### Pypi (Not Recommended)
```sh
pip install viv
```
Why is this *not recommended*? Mainly, because `viv` is all about hacking your `sys.path`.
Placing it in it's own virtual environment or installing in a user site directory may complicate this endeavor.
## Usage
Then in any python script with external dependencies you can add this line,
to automate env creation and installation of dependencies.
In any python script with external dependencies you can add this line,
to automate `vivenv` creation and installation of dependencies.
```python
__import__("viv").activate("click")
```
To remove all `vivenvs`:
```sh
viv remove $(viv list -q)
```
## Standalone Function
# Standalone Viv
Supposing you want to increase the portability of your script while still employing `viv`.
The below function can be freely pasted at the top of your scripts and requires
no modification of your PYTHONPATH or import of additional modules.
no modification of your PYTHONPATH or import of additional modules (including downloading/installing `viv`).
It can be auto-generated with for example: `viv freeze rich --standalone`.
It can be auto-generated with for example: `viv freeze <spec> --standalone`.
The only part necessary to modify if copied verbatim from here is the call to `_viv_activate`.
The only part necessary to modify if copied verbatim from below is the call to `_viv_activate`.
output of `viv freeze rich --standalone`:
```python
# <<<<< auto-generated by daylinmorgan/viv (v.22.12a3)
# fmt: off

View file

@ -5,3 +5,5 @@
- [ ] use config file (probably ini or toml for python>=3.11)
- [ ] enable a garbage collection based on time or file existence (configurable)
- [ ] unit tests (v important)
- [ ] add more options to filter `viv list`