1- from setuptools import setup , Extension
1+ from setuptools import setup
2+ from setuptools .extension import Extension
23from setuptools .dist import Distribution
34from pkg_resources import resource_string
4- from Cython .Distutils import build_ext
5+
6+
7+ try :
8+ from Cython .Distutils import build_ext
9+ except ImportError :
10+ USE_CYTHON = False
11+ else :
12+ USE_CYTHON = True
513
614
715class BinaryDistribution (Distribution ):
@@ -14,40 +22,54 @@ def is_pure(self):
1422 return False
1523
1624
17- class build_ext_subclass (build_ext ):
18- """
19- This class is an ugly hack to a problem that arises when one must force
20- a compiler to use specific flags by adding to the environment somethiing
21- like the following:
22-
23- CXX="clang --some_flagA --some_flagB -I/usr/bin/include/mylibC"
24-
25- (as opposed to setting CXXFLAGS). Distutils in that case will complain
26- that it cannot run the entire command as given because it is not
27- found as an executable (specific error message is: "unable to execute...
28- ... no such file or directory").
29-
30- This subclass of ``build_ext`` will extract the compiler name from the
31- command line and insert any remaining arguments right after it.
32- """
33- def build_extensions (self ):
34- ccm = self .compiler .compiler
35- if ' ' in ccm [0 ]:
36- self .compiler .compiler = ccm [0 ].split (' ' ) + ccm [1 :]
37- cxx = self .compiler .compiler_cxx
38- if ' ' in cxx [0 ]:
39- self .compiler .compiler_cxx = cxx [0 ].split (' ' ) + cxx [1 :]
40- build_ext .build_extensions (self )
41-
42-
4325CXXFLAGS = u"""
4426-O3
4527-msse4.2
4628-Wno-unused-value
4729-Wno-unused-function
4830""" .split ()
4931
50- VERSION = '0.0.12'
32+
33+ INCLUDE_DIRS = ['include' ]
34+ CXXHEADERS = [
35+ "include/metro.h" ,
36+ "include/metrohash.h" ,
37+ "include/metrohash128.h" ,
38+ "include/metrohash128crc.h" ,
39+ "include/metrohash64.h" ,
40+ "include/platform.h" ,
41+ ]
42+ CXXSOURCES = [
43+ "src/metrohash64.cc" ,
44+ "src/metrohash128.cc" ,
45+ ]
46+
47+ CMDCLASS = {}
48+ EXT_MODULES = []
49+
50+ if USE_CYTHON :
51+ EXT_MODULES .append (
52+ Extension (
53+ "metrohash" ,
54+ CXXSOURCES + ["src/metrohash.pyx" ],
55+ depends = CXXHEADERS ,
56+ language = "c++" ,
57+ extra_compile_args = CXXFLAGS ,
58+ include_dirs = INCLUDE_DIRS )
59+ )
60+ CMDCLASS ['build_ext' ] = build_ext
61+ else :
62+ EXT_MODULES .append (
63+ Extension (
64+ "metrohash" ,
65+ CXXSOURCES + ["src/metrohash.cpp" ],
66+ depends = CXXHEADERS ,
67+ language = "c++" ,
68+ extra_compile_args = CXXFLAGS ,
69+ include_dirs = INCLUDE_DIRS )
70+ )
71+
72+ VERSION = '0.0.13'
5173URL = "https://github.com/escherba/python-metrohash"
5274
5375setup (
@@ -59,27 +81,9 @@ def build_extensions(self):
5981 download_url = URL + "/tarball/master/" + VERSION ,
6082 name = 'metrohash' ,
6183 license = 'MIT' ,
62- cmdclass = {'build_ext' : build_ext_subclass },
6384 zip_safe = False ,
64- ext_modules = [Extension (
65- "metrohash" ,
66- [
67- "src/metrohash64.cc" ,
68- "src/metrohash128.cc" ,
69- "src/metrohash.pyx"
70- ],
71- depends = [
72- "include/metro.h" ,
73- "include/metrohash.h" ,
74- "include/metrohash128.h" ,
75- "include/metrohash128crc.h" ,
76- "include/metrohash64.h" ,
77- "include/platform.h"
78- ],
79- language = "c++" ,
80- extra_compile_args = CXXFLAGS ,
81- include_dirs = ['include' ])
82- ],
85+ cmdclass = CMDCLASS ,
86+ ext_modules = EXT_MODULES ,
8387 keywords = ['hash' , 'hashing' , 'metrohash' , 'cityhash' ],
8488 classifiers = [
8589 'Development Status :: 4 - Beta' ,
0 commit comments