Skip to content

Latest commit

 

History

History
72 lines (47 loc) · 1.57 KB

README.md

File metadata and controls

72 lines (47 loc) · 1.57 KB

Facade

Meta loaders for fun and profit

Facade builds upon a less known feature of python, specified in PEP 302 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

# 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

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

view.index_page(...)

Using the DLL loader

facade is bundled with a CFFI-based DLL loader, and based on this awesome gist.

It is currently only tested against DLLs created using rustc.

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:

int triple(int);

And then, on your .py file:

from facade import dll
import triple

print triple.triple(10) // 30