-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
99 lines (79 loc) · 2.97 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
# coding:utf-8
import os
import platform
import sys
import subprocess
from setuptools.command.build_ext import build_ext
from distutils.core import setup, Extension
from distutils import log as logger
import Cython
from Cython.Build import cythonize
is_x64 = platform.architecture()[0] == '64bit'
is_win = sys.platform.startswith('win')
is_mac = sys.platform.startswith('darwin')
use_openssl = not (is_win or is_mac)
LIBHV_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "vendor", "libhv"))
class hvloop_build_ext(build_ext):
def build_libhv(self):
# cmake configure
cmake_args = [LIBHV_DIR, "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"]
if is_win:
cmake_args.append("-DCMAKE_GENERATOR_PLATFORM=x64")
cmake_args.append("-DCMAKE_GENERATOR_TOOLSET=host=x64")
print(cmake_args)
subprocess.check_call(["cmake"] + cmake_args, cwd=self.build_temp)
# cmake build
subprocess.check_call([
"cmake", "--build", ".", "--config", "Release", "--target", "libhv_static"],
cwd=self.build_temp)
def build_extension(self, *args, **kwargs):
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
build_dir = os.path.abspath(self.build_temp)
self.build_libhv()
if is_win:
libhv_lib = os.path.join(build_dir, "lib", "Release", "hv_static.lib")
else:
libhv_lib = os.path.join(build_dir, "lib", "libhv_static.a")
if not os.path.exists(libhv_lib):
raise RuntimeError("failed to build libhv")
self.extensions[-1].extra_objects.extend([libhv_lib])
self.compiler.add_include_dir(os.path.join(build_dir, "include", "hv"))
super().build_extension(*args, **kwargs)
ext_type = Extension(
"hvloop.loop",
sources=["hvloop/loop.pyx"],
language="c",
define_macros=[('HV_STATICLIB', '1'), ],
)
with open("README.md", "r", encoding="utf-8") as f:
LONG_DESCRIPTION = f.read()
setup(
name="hvloop",
version="0.0.2",
packages=['hvloop'],
license="MIT License",
author="xiispace",
author_email="[email protected]",
description="asyncio event loop base on libhv",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
url="https://github.com/xiispace/hvloop",
classifiers=[
'Development Status :: 1 - Planning',
'Framework :: AsyncIO',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'License :: OSI Approved :: Apache Software License',
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
],
cmdclass={
"build_ext": hvloop_build_ext
},
python_requires=">=3.6",
include_package_data=True,
ext_modules=cythonize([ext_type], compiler_directives={'language_level': "3"})
)