Skip to content

Commit

Permalink
Improved regex module for python
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Nov 9, 2013
1 parent 016977d commit 87d927d
Show file tree
Hide file tree
Showing 11 changed files with 37,123 additions and 18 deletions.
4 changes: 4 additions & 0 deletions COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ License: LGPL-2.1
The full text of the LGPL is distributed as in
/usr/share/common-licenses/LGPL-2.1 on Debian systems.

Files: srx/regex/*
Copyright: Matthew Barnett
License: Python Software Foundation License

Files: src/calibre/ebooks/hyphenate.py
Copyright: Copyright (C) 1990, 2004, 2005 Gerard D.C. Kuiken.
License: other
Expand Down
40 changes: 22 additions & 18 deletions setup/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def absolutize(self, paths):
return list(set([x if os.path.isabs(x) else os.path.join(SRC, x.replace('/',
os.sep)) for x in paths]))


def __init__(self, name, sources, **kwargs):
self.name = name
self.needs_cxx = bool([1 for x in sources if os.path.splitext(x)[1] in
Expand Down Expand Up @@ -67,10 +66,15 @@ def preflight(self, obj_dir, compiler, linker, builder, cflags, ldflags):
icu_libs = ['icudt', 'icuin', 'icuuc', 'icuio']
if isosx:
icu_libs = ['icucore']
icu_cflags = ['-DU_DISABLE_RENAMING'] # Needed to use system libicucore.dylib
icu_cflags = ['-DU_DISABLE_RENAMING'] # Needed to use system libicucore.dylib

extensions = [

Extension('_regex',
['regex/_regex.c', 'regex/_regex_unicode.c'],
headers=['regex/_regex.h']
),

Extension('speedup',
['calibre/utils/speedup.c'],
),
Expand Down Expand Up @@ -127,7 +131,7 @@ def preflight(self, obj_dir, compiler, linker, builder, cflags, ldflags):

Extension('freetype',
['calibre/utils/fonts/freetype.cpp'],
inc_dirs = ft_inc_dirs,
inc_dirs=ft_inc_dirs,
libraries=ft_libs,
lib_dirs=ft_lib_dirs),

Expand Down Expand Up @@ -171,23 +175,23 @@ def preflight(self, obj_dir, compiler, linker, builder, cflags, ldflags):

Extension('pictureflow',
['calibre/gui2/pictureflow/pictureflow.cpp'],
inc_dirs = ['calibre/gui2/pictureflow'],
headers = ['calibre/gui2/pictureflow/pictureflow.h'],
sip_files = ['calibre/gui2/pictureflow/pictureflow.sip']
inc_dirs=['calibre/gui2/pictureflow'],
headers=['calibre/gui2/pictureflow/pictureflow.h'],
sip_files=['calibre/gui2/pictureflow/pictureflow.sip']
),

Extension('progress_indicator',
['calibre/gui2/progress_indicator/QProgressIndicator.cpp'],
inc_dirs = ['calibre/gui2/progress_indicator'],
headers = ['calibre/gui2/progress_indicator/QProgressIndicator.h'],
sip_files = ['calibre/gui2/progress_indicator/QProgressIndicator.sip']
inc_dirs=['calibre/gui2/progress_indicator'],
headers=['calibre/gui2/progress_indicator/QProgressIndicator.h'],
sip_files=['calibre/gui2/progress_indicator/QProgressIndicator.sip']
),

Extension('qt_hack',
['calibre/ebooks/pdf/render/qt_hack.cpp'],
inc_dirs = qt_private_inc + ['calibre/ebooks/pdf/render', 'qt-harfbuzz/src'],
headers = ['calibre/ebooks/pdf/render/qt_hack.h'],
sip_files = ['calibre/ebooks/pdf/render/qt_hack.sip']
inc_dirs=qt_private_inc + ['calibre/ebooks/pdf/render', 'qt-harfbuzz/src'],
headers=['calibre/ebooks/pdf/render/qt_hack.h'],
sip_files=['calibre/ebooks/pdf/render/qt_hack.sip']
),

Extension('unrar',
Expand All @@ -200,7 +204,7 @@ def preflight(self, obj_dir, compiler, linker, builder, cflags, ldflags):
volume.o list.o find.o unpack.o cmddata.o filestr.o scantree.o
'''.split()] + ['calibre/utils/unrar.cpp'],
inc_dirs=['unrar'],
cflags = [('/' if iswindows else '-') + x for x in (
cflags=[('/' if iswindows else '-') + x for x in (
'DSILENT', 'DRARDLL', 'DUNRAR')] + (
[] if iswindows else ['-D_FILE_OFFSET_BITS=64',
'-D_LARGEFILE_SOURCE']),
Expand Down Expand Up @@ -436,9 +440,9 @@ def build(self, ext, dest):
if iswindows:
#manifest = dest+'.manifest'
#cmd = [MT, '-manifest', manifest, '-outputresource:%s;2'%dest]
#self.info(*cmd)
#self.check_call(cmd)
#os.remove(manifest)
# self.info(*cmd)
# self.check_call(cmd)
# os.remove(manifest)
for x in ('.exp', '.lib'):
x = os.path.splitext(dest)[0]+x
if os.path.exists(x):
Expand Down Expand Up @@ -487,7 +491,7 @@ def path(x):
"style/windowmanager.cpp",
]
if not iswindows and not isosx:
headers.append( "style/shadowhelper.h")
headers.append("style/shadowhelper.h")
sources.append('style/shadowhelper.cpp')

pro = textwrap.dedent('''
Expand Down Expand Up @@ -586,7 +590,7 @@ def build_pyqt_extension(self, ext, dest):
sbf = self.j(src_dir, self.b(sipf)+'.sbf')
if self.newer(sbf, [sipf]+ext.headers):
exe = '.exe' if iswindows else ''
cmd = [pyqt.sip_bin+exe, '-w', '-c', src_dir, '-b', sbf, '-I'+\
cmd = [pyqt.sip_bin+exe, '-w', '-c', src_dir, '-b', sbf, '-I'+
pyqt.pyqt_sip_dir] + shlex.split(pyqt.pyqt_sip_flags) + [sipf]
self.info(' '.join(cmd))
self.check_call(cmd)
Expand Down
1 change: 1 addition & 0 deletions src/calibre/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def __init__(self):
'woff',
'unrar',
'qt_hack',
'_regex'
]
if iswindows:
plugins.extend(['winutil', 'wpd', 'winfonts'])
Expand Down
7 changes: 7 additions & 0 deletions src/calibre/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
import cStringIO
from calibre.constants import plugins, iswindows

def test_regex():
import regex
if regex.findall(r'(?i)(a)(b)', 'ab cd AB 1a1b') != [('a', 'b'), ('A', 'B')]:
raise ValueError('regex module failed on a simple search')
print ('regex OK!')

def test_html5lib():
import html5lib.html5parser # noqa
from html5lib import parse # noqa
Expand Down Expand Up @@ -119,6 +125,7 @@ def test():
test_woff()
test_qt()
test_html5lib()
test_regex()
if iswindows:
test_winutil()
test_wpd()
Expand Down
5 changes: 5 additions & 0 deletions src/regex/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This regex engine is taken, with thanks, from: https://code.google.com/p/mrab-regex-hg/

It is licensed under the Python Software Foundation License

Author: Matthew Barnett
Loading

0 comments on commit 87d927d

Please sign in to comment.