Skip to content

Commit

Permalink
UPD: readme improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
desty2k committed Jun 28, 2021
1 parent 780a3e1 commit 71bce52
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions README.md
Expand Up @@ -5,7 +5,7 @@
[![Version](https://img.shields.io/pypi/dm/paker)](https://pypi.org/project/paker/)


Paker is module for importing Python packages/modules from JSON documents.
Paker is module for importing Python packages/modules from dictionaries and JSON formatted documents.
It was inspired by [httpimporter](https://github.com/operatorequals/httpimport).


Expand All @@ -28,7 +28,7 @@ pip install .

### In Python script

You can import Python module from dict.
You can import Python modules directly from string, dict or bytes (without disk IO).

```python

Expand All @@ -49,8 +49,8 @@ if __name__ == '__main__':

```

It is also possible to import modules from `.json` files.
In this example we will use paker to serialize [mss](https://pypi.org/project/mss/) package.
To import modules from `.json` files use `load` function.
In this example paker will serialize and import [mss](https://pypi.org/project/mss/) package.

```python

Expand Down Expand Up @@ -82,8 +82,6 @@ import mss

```

Check example directory for more scripts.


### CLI
Paker can also work as a standalone script.
Expand All @@ -107,10 +105,10 @@ paker list mss.json

## How it works

Paker implements its own [importer](https://docs.python.org/3/glossary.html#term-importer) called `jsonimporter`.
When importing modules or packages Python iterates over importers in `sys.meta_path` and calls `find_module` method on each object.
When importing modules or packages Python iterates over [importers](https://docs.python.org/3/glossary.html#term-importer) in `sys.meta_path` and calls `find_module` method on each object.
If the importer returns `self`, it means that the module can be imported and `None` means that importer did not find searched package.
If any importer has confirmed the ability to import module, Python executes another method on it - `load_module`.
Paker implements its own importer called `jsonimporter`, which instead of searching for modules in directories, looks for them in Python dictionaries

To dump module or package to JSON document, Paker recursively iterates over modules and creates dict with
code and type of each module and submodules if object is package.
Expand Down

0 comments on commit 71bce52

Please sign in to comment.