commit b22c781fe69f6fdac92be02fac200af3f00ea6ba Author: vaydheesh Date: Wed Jun 5 01:36:11 2019 +0000 Added travis config travis: install swig and python3-setuptools configure.ac: python3 and swig 3.0.4 setup.py.in: removed get_env, instead substitute variable removed: setup2.py and tests/ diff --git a/.travis.yml b/.travis.yml index 7812f25..6aecef4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ os: compiler: - clang - gcc +install: + - if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install swig python3-setuptools; else brew install swig; fi script: - ./autogen.sh - ./configure diff --git a/configure.ac b/configure.ac index 04ecc35..a6d578f 100644 --- a/configure.ac +++ b/configure.ac @@ -140,12 +140,12 @@ static_assert(!is_same::value, "size_t == uint32_t"); static_assert(!is_same::value, "size_t == uint64_t"); ]])], [AC_DEFINE([SIZET_NOT_CSTDINT], [1], [size_t != (uint32_t, uint64_t)])]) -AM_PATH_PYTHON([2], [], [AC_MSG_WARN([Can't run 'make test' without Python installed.])]) +AM_PATH_PYTHON([3.4], [], [AC_MSG_WARN([Can't generate wrapper without Python])]) AC_CONFIG_FILES([ python/setup.py ]) -AX_PKG_SWIG(4.0.0) +AX_PKG_SWIG(3.0.4) AX_SWIG_ENABLE_CXX AX_SWIG_PYTHON diff --git a/python/Makefile.am b/python/Makefile.am index d1373d8..6b5e1d7 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -5,4 +5,7 @@ all: analysis_wrap.cpp analysis_wrap.cpp: $(SWIG_SOURCES) setup.py $(SWIG) $(AX_SWIG_PYTHON_OPT) -I$(top_srcdir) -o $@ $< + $(PYTHON) setup.py build + +install-exec-local: $(PYTHON) setup.py install diff --git a/python/setup.py.in b/python/setup.py.in index 210fc3d..c267d8c 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -17,15 +17,6 @@ class CustomBuild(build): ] -def getenv_list(var_name): - from os import getenv - var = getenv(var_name) - if var: - return var.split() - else: - return [] - - def get_sources(): from os import path sources = ['analysis_wrap.cpp'] @@ -35,14 +26,13 @@ def get_sources(): sources.extend([path.join(rel_path, f) for f in cc_sources.split()]) return sources - analysis_module = Extension( name='_analysis', sources=get_sources(), include_dirs=['@top_srcdir@', '/usr/include/libxml2'], library_dirs=['/usr/include/libxml2'], - extra_compile_args=getenv_list('CPPFLAGS') + getenv_list('CXXFLAGS'), - extra_link_args=getenv_list('LDFLAGS') + ['-lxml2'] + extra_compile_args='@CXXFLAGS@'.split(), + extra_link_args=['-lxml2'], ) setup( diff --git a/python/setup2.py b/python/setup2.py deleted file mode 100644 index 842a59b..0000000 --- a/python/setup2.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/python - -""" -Setup for SWIG Python bindings for lttoolbox -""" - -from distutils.core import setup, Extension - -# swig -python -c++ -o analysis_wrap.cpp analysis.i - -def getenv_list(var_name): - from os import getenv - var = getenv(var_name) - if var: - return var.split() - else: - return [] - - -def get_sources(): - from os import path - sources = ['analysis_wrap.cpp'] - cc_sources = '\ - att_compiler.cc compiler.cc entry_token.cc expander.cc match_exe.cc \ - match_node.cc match_state.cc pattern_list.cc \ - regexp_compiler.cc sorted_vector.cc transducer.cc tmx_compiler.cc' - - paths = '/home/kawai/Desktop/git_push/lttoolbox/lttoolbox/' - cc = 'alphabet.cc compression.cc fst_processor.cc lt_locale.cc node.cc state.cc trans_exe.cc xml_parse_util.cc' - # for i in cc.split(): - # sources.append(path + i) - # sources.extend(cc_sources.split()) - sources.extend([path.join(paths, f) for f in cc.split()]) - return sources - -analysis_module = Extension( - '_analysis', - # sources=['analysis_wrap.cpp', '/home/kawai/Desktop/git_push/lttoolbox/lttoolbox/fst_processor.cc'], - sources=get_sources(), - include_dirs=['/home/kawai/Desktop/git_push/lttoolbox', '/usr/include/libxml2'], - library_dirs=['/usr/include/libxml2'], - extra_compile_args=getenv_list('CPPFLAGS') + getenv_list('CXXFLAGS'), - extra_link_args= (getenv_list('LDFLAGS')) + ['-lxml2']) - - -setup(name='python-@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@', - py_modules=['analysis'], - ext_modules=[analysis_module]) diff --git a/python/tests/__init__.py b/python/tests/__init__.py deleted file mode 100644 index 9f54269..0000000 --- a/python/tests/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -import os -import sys -import tempfile -import unittest - -base_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') -sys.path.append(base_path) - -import analysis - -class TestAnalysisunittest.TestCase): - def test_FST(self): - with tempfile.NamedTemporaryFile('w') as input_file, tempfile.NamedTemporaryFile('r') as output_file: - input_text = 'cats\n' - automorf_path = "/usr/share/apertium/apertium-eng/eng.automorf.bin" - input_file.write(input_text) - input_file.flush() - x = analysis.FST() - x.init_analysis(automorf_path, input_file.name, output_file.name) - output = output_file.read() - self.assertEqual(output, "cats") \ No newline at end of file