-
Notifications
You must be signed in to change notification settings - Fork 44
/
setup.py
125 lines (107 loc) · 4.48 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
120
121
122
123
124
125
import os
import sys
import re
import platform
from os.path import dirname
import multiprocessing
import subprocess
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
__version__ = open("VERSION", "r").read().strip()
__lib_name__ = "ucall"
this_directory = os.path.abspath(dirname(__file__))
with open(os.path.join(this_directory, "README.md")) as f:
long_description = f.read()
class CMakeExtension(Extension):
def __init__(self, name, source_dir=""):
Extension.__init__(self, name, sources=[])
self.source_dir = os.path.abspath(source_dir)
class CMakeBuild(build_ext):
def build_extension(self, ext):
if "uring" in ext.name and platform.system() != "Linux":
return
self.parallel = multiprocessing.cpu_count() // 2
extension_dir = os.path.abspath(dirname(self.get_ext_fullpath(ext.name)))
# required for auto-detection & inclusion of auxiliary 'native' libs
if not extension_dir.endswith(os.path.sep):
extension_dir += os.path.sep
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extension_dir}",
f"-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY={extension_dir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
]
# Adding CMake arguments set as environment variable
# (needed e.g. to build for ARM OSx on conda-forge)
if "CMAKE_ARGS" in os.environ:
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]
if sys.platform.startswith("darwin"):
# Cross-compile support for macOS - respect ARCHFLAGS if set
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
if archs:
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
build_args = []
if sys.platform.startswith("win32"):
build_args += ["--config", "Release"]
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
# self.parallel is a Python 3 only way to set parallel jobs by hand
# using -j in the build_ext call, not supported by pip or PyPA-build.
if hasattr(self, "parallel") and self.parallel:
build_args += [f"-j{self.parallel}"]
subprocess.check_call(["cmake", ext.source_dir] + cmake_args)
subprocess.check_call(
["cmake", "--build", ".", "--target", "py_" + ext.name.replace(".", "_")]
+ build_args
)
def run(self):
build_ext.run(self)
setup(
name=__lib_name__,
version=__version__,
author="Ash Vardanian",
author_email="[email protected]",
url="https://github.com/unum-cloud/ucall",
description="Up to 100x Faster FastAPI. JSON-RPC with io_uring, SIMD-acceleration, and pure CPython bindings",
long_description=long_description,
long_description_content_type="text/markdown",
license="Apache-2.0",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Natural Language :: English",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: C",
"Operating System :: Unix",
"Operating System :: POSIX",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS",
"Programming Language :: C",
"Programming Language :: C++",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Communications :: File Sharing",
"Topic :: Internet :: WWW/HTTP",
"Topic :: System :: Networking",
],
packages=["ucall"],
package_dir={"": "src"},
ext_modules=[
CMakeExtension("ucall.uring"),
CMakeExtension("ucall.posix"),
],
cmdclass={
"build_ext": CMakeBuild,
},
entry_points={"console_scripts": ["ucall=ucall.cli:cli"]},
install_requires=["numpy", "pillow"],
zip_safe=False,
python_requires=">=3.9",
)