forked from jaredly/codetalker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.pbj
executable file
·42 lines (35 loc) · 1.51 KB
/
make.pbj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
from pbj import Builder, cmd, PBJFailed
import os
import glob
import re
import traceback
build = Builder('CodeTalker')
pyx_files = glob.glob('codetalker/pgm/cgrammar/*.pyx')
@build.file('codetalker/pgm/cgrammar/process.so', depends=pyx_files, completion=pyx_files)
def pyx(fname):
for fname in pyx_files:
extra = []
if fname.endswith('/tokens.pyx') or fname.endswith('/tokenize.pyx'):
extra = ['codetalker/pgm/cgrammar/_speed_tokens.c']
compile_pyx(fname, extra)
build.clean('build', 'codetalker/pgm/cgrammar/*.c', 'codetalker/pgm/cgrammar/*.so', keep=['codetalker/pgm/cgrammar/_speed_tokens.c'])
build.cmd('test_tokenize', ['py.test'] + glob.glob('tests/tokenize/*.py'), depends='@pyx', always=True)
build.cmd('test_parse', ['py.test'] + glob.glob('tests/parse/*.py'), depends='@pyx', always=True)
build.cmd('test', ['py.test'] + glob.glob('tests/tokenize/*.py') + glob.glob('tests/parse/*.py'), depends='@pyx', always=True)
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import sys
import os
def compile_pyx(fname, extra = []):
if fname.split('/')[-1] == '_grammar.pyx':return
if fname.endswith('.pyx'):
fname = fname[:-4]
old_argv = sys.argv[:]
sys.argv[1:] = ['build_ext','--inplace']
setup(cmdclass = {'build_ext': build_ext},
ext_modules = [Extension(fname.replace('/','.'), [fname + '.pyx'] + extra)])
sys.argv = old_argv
if __name__ == '__main__':
build.run()