Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/oakfang/facade

Meta loaders for fun and profit
https://github.com/oakfang/facade

Last synced: 6 days ago
JSON representation

Meta loaders for fun and profit

Awesome Lists containing this project

README

        

# Facade
## Meta loaders for fun and profit

Facade builds upon a less known feature of python,
specified in [PEP 302](https://www.python.org/dev/peps/pep-0302/)
called `Import Hooks` or the `meta_path`.

Facade exports 2 main features:

- Easy creation of meta loaders/import hooks
- 5 ready-made loaders to be used as examples or for real-life challenges

### Creating a new loader

```python
# my_loader.py
from facade import loader

@loader('.xyz') # my loader's dedicated extension
def xyz_loader(module_name, module, file_content):
module.data = file_content
return module

xyz_loader.register() # start hooking on .xyz files

# script.py
from my_loader import xyz_loader
import foo # this is actually the file foo.xyz!

xyz_loader.revoke() # stop hooking, not mandatory
```

### Using the sample loaders

```python
from facade import pyv
import views # a .pyv file, using `pyvue`

view.index_page(...)
```

### Using the DLL loader
`facade` is bundled with a [CFFI](http://cffi.readthedocs.org/en/latest/index.html)-based DLL loader, and based on this awesome [gist](https://gist.github.com/seanjensengrey/f5d73bbdf22cfa1ad463).

It is currently only tested against DLLs created using `rustc`.

```python
from facade import dll
import triple

triple.decalre('int triple(int);')

print triple.triple(10) // 30
```

You can also create a declaration file to save yourself the "effort". Let's assume `triple.h` to be in the same directory as `tripl.dll`:

```c
int triple(int);
```

And then, on your `.py` file:

```python
from facade import dll
import triple

print triple.triple(10) // 30
```