From ca7045f3f253211a723845980199dffbabbf4881 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 5 Jul 2014 20:49:34 +0200 Subject: [PATCH] * Add build/setup stuff --- fabfile.py | 10 +++++++ requirements.txt | 2 ++ setup.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 fabfile.py create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 000000000..c35e27323 --- /dev/null +++ b/fabfile.py @@ -0,0 +1,10 @@ +from fabric.api import local, run, lcd, cd, env + +def make(): + local('python setup.py build_ext --inplace') + +def clean(): + local('python setup.py clean --all') + +def test(): + local('py.test -x') diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..029a6618e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +cython +sparsehash diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..88e631fb9 --- /dev/null +++ b/setup.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +import Cython.Distutils +from distutils.extension import Extension +import distutils.core + +import sys +import os +import os.path +from os import path + + +def clean(ext): + for pyx in ext.sources: + if pyx.endswith('.pyx'): + c = pyx[:-4] + '.c' + cpp = pyx[:-4] + '.cpp' + so = pyx[:-4] + '.so' + html = pyx[:-4] + '.html' + if os.path.exists(so): + os.unlink(so) + if os.path.exists(c): + os.unlink(c) + elif os.path.exists(cpp): + os.unlink(cpp) + if os.path.exists(html): + os.unlink(html) + + +HERE = os.path.dirname(__file__) +virtual_env = os.environ.get('VIRTUAL_ENV', '') +compile_args = [] +link_args = [] +libs = [] + +includes = [] + +exts = [ + Extension("ext.sparsehash", ["ext/sparsehash.pyx"], language="c++"), + Extension('ext.murmurhash', + ["ext/murmurhash.pyx", "ext/MurmurHash2.cpp", + "ext/MurmurHash3.cpp"], language="c++", + include_dirs=[path.join(HERE, 'ext')]), + + Extension("spacy.en", + ["spacy/en.pyx", "ext/MurmurHash3.cpp", "ext/MurmurHash2.cpp"], + language="c++", + include_dirs=[path.join(HERE, 'ext')]), + Extension("spacy.lexeme", ["spacy/lexeme.pyx"], language="c++", include_dirs=includes), + Extension("spacy.spacy", ["spacy/spacy.pyx"], language="c++", include_dirs=includes), +] + + +if sys.argv[1] == 'clean': + print >> sys.stderr, "cleaning .c, .c++ and .so files matching sources" + map(clean, exts) + +distutils.core.setup( + name='Sparse linear models with Cython', + packages=['thinc'], + author='Matthew Honnibal', + author_email='honnibal@gmail.com', + version='1.0', + cmdclass={'build_ext': Cython.Distutils.build_ext}, + ext_modules=exts, +) + + +