-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
53 lines (49 loc) · 2.29 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from os.path import join, isdir, abspath, basename, exists, dirname
from distutils.core import setup, Extension
from distutils.command import build_ext
import traceback
base_module = Extension(name='ftmsc.core',
sources = ['ftmsc/core_ivw.c'],
include_dirs = ['.', 'ftmsc/include'],
library_dirs = ['lib'],
libraries = ['msc','dl','pthread'])
class my_build_ext(build_ext.build_ext):
def initialize_options(self):
build_ext.build_ext.initialize_options(self)
def build_extension(self, ext):
result = build_ext.build_ext.build_extension(self, ext)
# hack: create a symlink from build/../core.so to gevent/core.so
# to prevent "ImportError: cannot import name core" failures
try:
fullname = self.get_ext_fullname(ext.name)
modpath = fullname.split('.')
filename = self.get_ext_filename(ext.name)
filename = os.path.split(filename)[-1]
if not self.inplace:
filename = os.path.join(*modpath[:-1] + [filename])
path_to_build_core_so = abspath(os.path.join(self.build_lib, filename))
path_to_core_so = abspath(join('ftmsc', basename(path_to_build_core_so)))
if path_to_build_core_so != path_to_core_so:
try:
os.unlink(path_to_core_so)
except OSError:
pass
if hasattr(os, 'symlink'):
print 'Linking %s to %s' % (path_to_build_core_so, path_to_core_so)
os.symlink(path_to_build_core_so, path_to_core_so)
else:
print 'Copying %s to %s' % (path_to_build_core_so, path_to_core_so)
import shutil
shutil.copyfile(path_to_build_core_so, path_to_core_so)
except Exception:
traceback.print_exc()
return result
setup (name = 'ftmsc',
version = '0.1',
description = 'this is a package for wrap flytek wake sdk',
packages = ['ftmsc'],
ext_modules = [base_module],
cmdclass = {'build_ext': my_build_ext},
author = 'juncaofish',
author_email = 'juncaofish@sina.com')