Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SWIG Python wrapper guarded by --enable-python-bindings
- Loading branch information
1 parent
ced6ff8
commit a9f0f84
Showing
6 changed files
with
215 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
*.pyc | ||
**/*.deps/ | ||
/.ccls-cache/ | ||
/*.pc | ||
/aclocal.m4 | ||
/autom4te.cache | ||
/compile | ||
/config.guess | ||
/config.log | ||
/config.status | ||
/config.sub | ||
/configure | ||
/depcomp | ||
/INSTALL | ||
/install-sh | ||
/m4/libtool.m4 | ||
/m4/lt~obsolete.m4 | ||
/m4/ltoptions.m4 | ||
/m4/ltsugar.m4 | ||
/m4/ltversion.m4 | ||
/Makefile | ||
/Makefile.in | ||
/missing | ||
|
||
# Prerequisites | ||
*.d | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.mod | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
|
||
lrx-comp | ||
lrx-proc | ||
lrx_config.h | ||
lrx_config.h.in | ||
multitrans | ||
stamp-h1 | ||
|
||
/python/Makefile.in | ||
/python/Makefile | ||
/python/lex_tools_wrap.cpp | ||
/python/lextools.py | ||
/python/setup.py | ||
/python/build* | ||
*.egg-info/ | ||
*.egg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
SWIG_INTERFACE = lex_tools.i | ||
|
||
BUILT_SOURCES = %_wrap.cpp | ||
|
||
%_wrap.cpp: $(SWIG_INTERFACE) setup.py | ||
$(PYTHON) setup.py build | ||
|
||
install-exec-local: | ||
$(PYTHON) setup.py install --prefix=$(DESTDIR)$(prefix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
%module lextools | ||
|
||
%{ | ||
#define SWIG_FILE_WITH_INIT | ||
#include <lrx_processor.h> | ||
|
||
|
||
class LRX: public LRXProcessor | ||
{ | ||
public: | ||
/** | ||
* Imitates functionality of lrx_proc using file path | ||
*/ | ||
void lrx_proc(char arg, char *dictionary_path, char *input_path, char *output_path); | ||
}; | ||
|
||
|
||
void | ||
LRX::lrx_proc(char arg, char *dictionary_path, char *input_path, char *output_path) | ||
{ | ||
bool useMaxEnt = false; | ||
FILE *in = fopen(dictionary_path, "rb"); | ||
load(in); | ||
FILE *input = fopen(input_path, "r"), *output = fopen(output_path, "w"); | ||
switch(arg) | ||
{ | ||
case 'm': | ||
useMaxEnt = true; | ||
break; | ||
default: | ||
useMaxEnt = false; | ||
} | ||
init(); | ||
if(useMaxEnt) | ||
{ | ||
processME(input, output); | ||
} | ||
else | ||
{ | ||
process(input, output); | ||
} | ||
fclose(in); | ||
fclose(input); | ||
fclose(output); | ||
} | ||
|
||
%} | ||
|
||
|
||
%include <lrx_processor.h> | ||
|
||
|
||
class LRX: public LRXProcessor | ||
{ | ||
public: | ||
/** | ||
* Imitates functionality of lrx_proc using file path | ||
*/ | ||
void lrx_proc(char arg, char *dictionary_path, char *input_path, char *output_path); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Setup for SWIG Python bindings for lex-tools | ||
""" | ||
from os import path | ||
from distutils.core import Extension, setup | ||
from distutils.command.build import build | ||
|
||
|
||
class CustomBuild(build): | ||
sub_commands = [ | ||
('build_ext', build.has_ext_modules), | ||
('build_py', build.has_pure_modules), | ||
('build_clib', build.has_c_libraries), | ||
('build_scripts', build.has_scripts), | ||
] | ||
|
||
|
||
def get_sources(): | ||
sources = ['lex_tools.i'] | ||
cc_sources = ['lrx_processor.cc'] | ||
rel_path = '..' | ||
sources.extend(path.join(rel_path, f) for f in cc_sources) | ||
return sources | ||
|
||
def get_include_dirs(): | ||
# get rid of '-I' in LTTOOLBOX_CFLAGS and split list from 1, to remove extra element '' | ||
# Strip extra space at end | ||
dirs = '@LTTOOLBOX_CFLAGS@'.split('-I')[1:] | ||
dirs += '@LIBXML_LIBS@'.split('-I')[1:] | ||
dirs = [x.strip() for x in dirs] | ||
return dirs + ['..'] | ||
|
||
|
||
lextools_module = Extension( | ||
name='_lextools', | ||
sources=get_sources(), | ||
swig_opts = ["-c++", "-I..", "-Wall"], | ||
include_dirs=get_include_dirs(), | ||
library_dirs=['/usr/include/libxml2', '/usr/local/lib'], | ||
extra_compile_args='@CXXFLAGS@'.split(), | ||
extra_link_args=['-lxml2', '-llttoolbox3'], | ||
) | ||
|
||
setup( | ||
name='@PACKAGE@', | ||
version='@PACKAGE_VERSION@', | ||
description='SWIG interface to @PACKAGE_NAME@', | ||
long_description="SWIG interface to @PACKAGE_NAME@ for use in apertium-python", | ||
# TODO: author, maintainer, url | ||
author_email='@PACKAGE_BUGREPORT@', | ||
license='GPL-3.0+', | ||
maintainer_email='@PACKAGE_BUGREPORT@', | ||
cmdclass={'build': CustomBuild}, | ||
ext_modules=[lextools_module], | ||
py_modules=['lextools'], | ||
) |