-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.py
160 lines (137 loc) · 4.56 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from __future__ import annotations
import os
import pathlib
import platform
import sys
import versioneer
__author__ = "Ali-Akber Saifee"
__email__ = "[email protected]"
__copyright__ = "Copyright 2023, Ali-Akber Saifee"
from setuptools import find_packages, setup
from setuptools.command.build_ext import build_ext
from setuptools.extension import Extension
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
PY_IMPLEMENTATION = platform.python_implementation()
USE_MYPYC = False
PURE_PYTHON = os.environ.get("PURE_PYTHON", PY_IMPLEMENTATION != "CPython")
def get_requirements(req_file):
requirements = []
for r in open(os.path.join(THIS_DIR, "requirements", req_file)).read().splitlines():
req = r.strip()
if req.startswith("-r"):
requirements.extend(get_requirements(req.replace("-r ", "")))
elif req:
requirements.append(req)
return requirements
class coredis_build_ext(build_ext):
warning_message = """
********************************************************************
{target} could not
be compiled. No C extensions are essential for coredis to run,
although they do result in significant speed improvements for
response parsing.
{comment}
********************************************************************
"""
def run(self):
try:
super().run()
except Exception as e:
self.warn(e)
self.warn(
self.warning_message.format(
target="Extension modules",
comment=(
"There is an issue with your platform configuration "
"- see above."
),
)
)
def build_extension(self, ext):
try:
super().build_extension(ext)
except Exception as e:
self.warn(e)
self.warn(
self.warning_message.format(
target=f"The {ext.name} extension ",
comment=(
"The output above this warning shows how the "
"compilation failed."
),
)
)
_ROOT_DIR = pathlib.Path(__file__).parent
with open(str(_ROOT_DIR / "README.md")) as f:
long_description = f.read()
if len(sys.argv) > 1 and "--use-mypyc" in sys.argv:
sys.argv.remove("--use-mypyc")
USE_MYPYC = True
if not PURE_PYTHON:
extensions = [
Extension(
name="coredis.speedups",
sources=["coredis/speedups.c"],
)
]
if USE_MYPYC:
from mypyc.build import mypycify
extensions += mypycify(
[
"coredis/constants.py",
"coredis/parser.py",
"coredis/_packer.py",
],
debug_level="0",
strip_asserts=True,
)
for ext in extensions:
if "-Werror" in ext.extra_compile_args:
ext.extra_compile_args.remove("-Werror")
else:
extensions = []
setup(
name="coredis",
version=versioneer.get_version(),
description="Python async client for Redis key-value store",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/alisaifee/coredis",
project_urls={
"Source": "https://github.com/alisaifee/coredis",
"Changes": "https://github.com/alisaifee/coredis/releases",
"Documentation": "https://coredis.readthedocs.org",
},
author=__author__,
author_email=__email__,
maintainer=__author__,
maintainer_email=__email__,
keywords=["Redis", "key-value store", "asyncio"],
license="MIT",
packages=find_packages(exclude=["*tests*"]),
include_package_data=True,
package_data={
"coredis": ["py.typed"],
},
python_requires=">=3.8",
install_requires=get_requirements("main.txt"),
cmdclass=versioneer.get_cmdclass(
{
"build_ext": coredis_build_ext,
}
),
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: PyPy",
],
ext_modules=extensions,
)