Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/oakfang/facade
- Owner: oakfang
- License: mit
- Created: 2016-01-31T15:22:50.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-14T16:54:19.000Z (almost 9 years ago)
- Last Synced: 2024-12-09T22:37:52.475Z (about 1 month ago)
- Language: Python
- Size: 8.79 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Facade
## Meta loaders for fun and profitFacade 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 modulexyz_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 tripletriple.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 tripleprint triple.triple(10) // 30
```