Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Commit

Permalink
Create _nnpy module out-of-line and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Sep 19, 2015
1 parent f160e60 commit 13130ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
15 changes: 10 additions & 5 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,22 @@ def symbols(ffi):

return '\n'.join(lines) + '\n'

def run():
def create_module():

hfiles = header_files()
headers = functions(hfiles)
del hfiles['ws.h'] # due to https://github.com/nanomsg/nanomsg/issues/467

ffi = FFI()
ffi.cdef(headers)
ffi.cdef(functions(hfiles))
ffi.set_source('_nnpy', '\n'.join('#include <%s>' % fn for fn in hfiles),
libraries=['nanomsg'], include_dirs=INCLUDE)
return ffi

with open('nnpy/nanomsg.h', 'w') as f:
f.write(headers)
def run():
ffi = create_module()
with open('nnpy/constants.py', 'w') as f:
f.write(symbols(ffi))
ffi.compile()

if __name__ == '__main__':
run()
10 changes: 1 addition & 9 deletions nnpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
from .constants import *
from cffi import FFI
from _nnpy import ffi, lib as nanomsg
import os

HERE = os.path.dirname(__file__)

ffi = FFI()
with open(os.path.join(HERE, 'nanomsg.h')) as f:
ffi.cdef(f.read())

nanomsg = ffi.dlopen('nanomsg')

from .socket import Socket

0 comments on commit 13130ad

Please sign in to comment.