-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
173 lines (145 loc) · 4.57 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
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import platform
import struct
from setuptools import setup
from setuptools.dist import Distribution
from setuptools.extension import Extension
try:
from cpuinfo import get_cpu_info
CPU_FLAGS = get_cpu_info()["flags"]
except Exception as exc:
print("exception loading cpuinfo", exc)
CPU_FLAGS = {}
try:
from Cython.Distutils import build_ext
USE_CYTHON = True
except ImportError:
USE_CYTHON = False
class BinaryDistribution(Distribution):
"""
Subclass the setuptools Distribution to flip the purity flag to false.
See https://lucumr.pocoo.org/2014/1/27/python-on-wheels/
"""
def is_pure(self):
"""Returns purity flag"""
return False
def get_system_bits():
"""Return 32 for 32-bit systems and 64 for 64-bit"""
return struct.calcsize("P") * 8
SYSTEM = os.name
BITS = get_system_bits()
HAVE_SSE42 = "sse4_2" in CPU_FLAGS
HAVE_AES = "aes" in CPU_FLAGS
CXXFLAGS = []
print("system: %s-%d" % (SYSTEM, BITS))
print("available CPU flags:", CPU_FLAGS)
print("environment:", ", ".join(["%s=%s" % (k, v) for k, v in os.environ.items()]))
if SYSTEM == "nt":
CXXFLAGS.extend(["/O2"])
else:
CXXFLAGS.extend(
[
"-O3",
"-Wno-unused-value",
"-Wno-unused-function",
]
)
# The "cibuildwheel" tool sets AUDITWHEEL_ARCH variable to architecture strings
# such as 'x86_64', 'aarch64', 'i686', etc. If this variable is not set, we
# assume that the build is not a CI build and target current machine
# architecture.
TARGET_ARCH = os.environ.get("AUDITWHEEL_ARCH", platform.machine())
print("building for target architecture:", TARGET_ARCH)
if HAVE_SSE42 and (TARGET_ARCH == "x86_64") and (BITS == 64):
print("enabling SSE4.2 on compile")
if SYSTEM == "nt":
CXXFLAGS.append("/D__SSE4_2__")
else:
CXXFLAGS.append("-msse4.2")
if HAVE_AES and (TARGET_ARCH == "x86_64") and (BITS == 64):
print("enabling AES on compile")
if SYSTEM == "nt":
CXXFLAGS.append("/D__AES__")
else:
CXXFLAGS.append("-maes")
CXXHEADERS = [
"src/metro.h",
"src/metrohash.h",
"src/metrohash128.h",
"src/metrohash128crc.h",
"src/metrohash64.h",
"src/platform.h",
]
CXXSOURCES = [
"src/metrohash64.cc",
"src/metrohash128.cc",
]
if USE_CYTHON:
print("building extension using Cython")
CMDCLASS = {"build_ext": build_ext}
SRC_EXT = ".pyx"
else:
print("building extension w/o Cython")
CMDCLASS = {}
SRC_EXT = ".cpp"
EXT_MODULES = [
Extension(
"metrohash",
CXXSOURCES + ["src/metrohash" + SRC_EXT],
depends=CXXHEADERS,
language="c++",
extra_compile_args=CXXFLAGS,
include_dirs=["src"],
),
]
VERSION = "0.3.3"
URL = "https://github.com/escherba/python-metrohash"
def get_long_description(relpath, encoding="utf-8"):
_long_desc = """
"""
fname = os.path.join(os.path.dirname(__file__), relpath)
try:
with open(fname, "rb") as fh:
return fh.read().decode(encoding)
except Exception:
return _long_desc
setup(
version=VERSION,
description="Python bindings for MetroHash, a fast non-cryptographic hash algorithm",
author="Eugene Scherba",
author_email="escherba+metrohash@gmail.com",
url=URL,
download_url=URL + "/tarball/master/" + VERSION,
name="metrohash",
license="Apache License 2.0",
python_requires='>=3.6',
zip_safe=False,
cmdclass=CMDCLASS,
ext_modules=EXT_MODULES,
package_dir={"": "src"},
keywords=["hash", "hashing", "metrohash", "cython"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: C++",
"Programming Language :: Cython",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Information Analysis",
"Topic :: Software Development :: Libraries",
"Topic :: System :: Distributed Computing",
],
long_description=get_long_description("README.md"),
long_description_content_type="text/markdown",
tests_require=["pytest"],
distclass=BinaryDistribution,
)