Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pomponchik committed May 26, 2023
1 parent 755db0a commit c80b03b
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Thanks to this package, it is very easy to manage the lifecycle of packages dire
## Table of contents

- [**Quick start**](#quick-start)
- [**Context manager and imports**](#сontext-manager-and-imports)
- [**Installing multiple packages**](#installing-multiple-packages)
- [**Options**](#options)
- [**Output and logging**](#output-and-logging)
- [**Script launch mode**](#script-launch-mode)
- [**Context manager mode**](#сontext-manager-mode)
- [**Installing multiple packages**](#installing-multiple-packages)
- [**Options**](#options)
- [**Output and logging**](#output-and-logging)
- [**How does it work?**](#how-does-it-work)


Expand All @@ -36,7 +36,15 @@ Install [it](https://pypi.org/project/instld/):
pip install instld
```

You can use the library in two ways: by importing a context manager from there or by running your script through it. Example of a context manager:
You can use the library in two ways: by running your script through it or by importing a context manager from there.

If you run the script [like this](#script-launch-mode), all dependencies will be automatically installed when the application starts and deleted when it stops:

```bash
instld script.py
```

And an example of a [context manager](#сontext-manager-mode):

```python
import installed
Expand All @@ -45,10 +53,31 @@ with installed('some_package'):
import some_module
```

The above code downloads `some_package` and imports `some_module` from it. Read on about how [running the script](#script-launch-mode) via `instld` works.
Read more about each method, its capabilities and limitations below.


## Script launch mode

You can use `instld` to run your script. To do this, you need to run a command like this in the console:

```bash
instld script.py
```

The contents of the script will be executed in the same way as if you were running it through the `python script.py` command. However, if your program has imports of any packages other than the built-in ones, they will be installed automatically. Installed packages are automatically cleaned up when you exit the program, so they don't leave any garbage behind.

If the name of the imported module and the package name are different, you need to use a special explanatory comment. For example, this code imports the `f` function from the [`fazy`](https://github.com/pomponchik/fazy) library version `0.0.3`:

```python
import f # instld: version 0.0.3, package fazy

## Context manager and imports
print(f('some string'))
```

You can also specify only the version or only the package name in the comment, they do not have to be specified together.


## Context manager mode

The context manager `installed` generates a context. While you are inside the context manager, you can import modules using the usual `import` command:

Expand Down Expand Up @@ -204,26 +233,6 @@ with installed('flask', catch_output=True):

The `INFO` [level](https://docs.python.org/3/library/logging.html#logging-levels) is used by default. For errors - `ERROR`.

## Script launch mode

You can use `instld` to run your script. To do this, you need to run a command like this in the console:

```bash
instld script.py
```

The contents of the script will be executed in the same way as if you were running it through the `python script.py` command. However, if your program has imports of any packages other than the built-in ones, they will be installed automatically. Installed packages are automatically cleaned up when you exit the program, so they don't leave any garbage behind.

If the name of the imported module and the package name are different, you need to use a special explanatory comment. For example, this code imports the `f` function from the [`fazy`](https://github.com/pomponchik/fazy) library version `0.0.3`:

```python
import f # instld: version 0.0.3, package fazy

print(f('some string'))
```

You can also specify only the version or only the package name in the comment, they do not have to be specified together.


## How does it work?

Expand Down

0 comments on commit c80b03b

Please sign in to comment.