forked from bytedance/pyskynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
119 lines (107 loc) · 4.54 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from distutils.command.build_ext import build_ext
from distutils.command.build import build
from setup_ext import *
def create_cython_extensions():
ext_main = Extension('pyskynet._core',
include_dirs=INCLUDE_DIRS,
sources=['src/cy_src/_core.pyx'] +
list_path(SKYNET_SRC_PATH, ".c", ["skynet_main.c", "skynet_start.c", "skynet_env.c", "skynet_server.c", "skynet_error.c"]) +
list_path("src/skynet_modify", ".c") +
list_path("numsky/src/skynet_foreign/", ".c") +
list_path(LUA_PATH, ".c", ["lua.c", "luac.c"]),
depends=['src/cy_src/skynet_modify.pxd'],
define_macros=MACROS,
libraries=LIBRARIES,
extra_objects=[])
ext_seri = Extension('pyskynet._foreign_seri',
include_dirs=INCLUDE_DIRS,
sources=['src/cy_src/_foreign_seri.pyx'] +
list_path('numsky/src/foreign_seri/', '.c', ["lua-foreign_seri.c"]),
depends=['src/cy_src/skynet_modify.pxd'],
define_macros=MACROS,
libraries=LIBRARIES)
return [ext_main, ext_seri]
class build_with_numpy_cython(build):
def finalize_options(self):
super().finalize_options()
self.distribution.ext_modules = create_skynet_extensions() + create_cython_extensions() + create_lua_extensions() + create_3rd_extensions()
import numpy
for extension in self.distribution.ext_modules:
np_inc = numpy.get_include()
if not (np_inc in extension.include_dirs):
extension.include_dirs.append(np_inc)
from Cython.Build import cythonize
self.distribution.ext_modules = cythonize(self.distribution.ext_modules, language_level=3)
class build_ext_rename(build_ext):
def get_export_symbols(self, ext_name):
# TODO symbol PyInit_xxx will be add in this step, but lua library don't has this symbol, so override this in some platform
return super().get_export_symbols(ext_name)
def get_ext_filename(self, ext_name):
ext_name_last = ext_name.split(".")[-1]
# cython library start with skynet_py
if ext_name_last.find("_core") == 0 or ext_name_last.find("_foreign_seri") == 0:
# for cython library
return super().get_ext_filename(ext_name)
else:
# for lua library
ext_path = ext_name.split('.')
return os.path.join(*ext_path) + ".so"
def get_version():
with open("pyskynet/__init__.py") as fo:
data = fo.read()
result = re.search(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', data)
return result.group(1)
def main():
setup(
name="pyskynet",
version=get_version(),
author="cz",
author_email="[email protected]",
license='MIT',
description="PySkynet is a library for using skynet in python.",
ext_modules=[], # setted in build_with_numpy_cython
cmdclass={"build_ext": build_ext_rename, "build": build_with_numpy_cython},
packages=["pyskynet", "skynet", "numsky"],
package_data={
"pyskynet": ["service/*",
"lualib/*",
"thlua_loader.lua",
"lualib/*/*",
],
"skynet": ["service/*",
"cservice/*",
"luaclib/*",
"lualib/*",
"lualib/*/*",
"lualib/*/*/*",
# lua header
"3rd/lua/lua.hpp",
"3rd/lua/lua.h",
"3rd/lua/lauxlib.h",
"3rd/lua/lualib.h",
"3rd/lua/luaconf.h",
# skynet header
"skynet-src/spinlock.h",
],
"numsky": [
"src/lua-binding.h",
"src/skynet_foreign/*.h",
]
},
zip_safe=False,
entry_points={
"console_scripts": [
"pyskynet=pyskynet.boot:main",
"pyskynetc=pyskynet.compile:entry",
]
},
install_requires=[
"cffi ~= 1.14.2",
"gevent >= 20.6.0",
"numpy",
],
url='https://github.com/drinkwithwater/pyskynet',
setup_requires=["cython", "numpy"],
python_requires='>=3.5',
)
main()