-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
183 lines (166 loc) · 6.01 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
174
175
176
177
178
179
180
181
182
183
import os
import sys
from setuptools import setup
from setuptools import find_packages
from setuptools import Extension
PYPY = hasattr(sys, 'pypy_version_info')
PY312 = sys.version_info[:2] == (3, 12)
def read(fname, here=os.path.dirname(__file__)):
with open(os.path.join(here, fname), encoding='utf-8') as f:
return f.read()
README = read('README.rst')
CHANGES = read('CHANGES.rst')
tests_require = [
'zope.testrunner',
# nti.testing > ZODB > persistent -> cffi
# CffI won't build on 3.13 yet; persistent is having trouble on PyPy
'nti.testing; python_version != "3.13" and platform_python_implementation != "PyPy"',
# transitive dep of nti.testing, which we don't always have, but need
# for our emulation
'zope.schema',
'pyhamcrest >= 1.10',
'pyperf',
]
###
# Cython
###
# Based on code from
# http://cython.readthedocs.io/en/latest/src/reference/compilation.html#distributing-cython-modules
def _dummy_cythonize(extensions, **_kwargs):
for extension in extensions:
sources = []
for sfile in extension.sources:
path, ext = os.path.splitext(sfile)
if ext in ('.pyx', '.py'):
ext = '.c'
sfile = path + ext
sources.append(sfile)
extension.sources[:] = sources
return extensions
try:
from Cython.Build import cythonize
except ImportError:
# The .c files had better already exist, as they should in
# an sdist.
cythonize = _dummy_cythonize
ext_modules = []
# Modules we want to compile with Cython. These *should* have a parallel
# .pxd file (with a leading _) defining cython attributes.
# They should also have a cython comment at the top giving options,
# and mention that they are compiled with cython on CPython.
# The bottom of the file must call import_c_accel.
# We use the support from Cython 28 to be able to parallel compile
# and cythonize modules to a different name with a leading _.
# This list is derived from the profile of bm_simple_iface
# https://github.com/NextThought/nti.externalization/commit/0bc4733aa8158acd0d23c14de2f9347fb698c040
if not PYPY:
def _source(m, ext):
# Yes, always /.
m = m.replace('.', '/')
return 'src/perfmetrics/' + m + '.' + ext
def _py_source(m):
return _source(m, 'py')
def _pxd(m):
return _source(m, 'pxd')
def _c(m):
return _source(m, 'c')
# Each module should list the python name of the
# modules it cimports from as deps. We'll generate the rest.
# (Not that this actually appears to do anything right now.)
for mod_name, deps in (
('metric', ()),
):
deps = ([_py_source(mod) for mod in deps]
+ [_pxd(mod) for mod in deps]
+ [_c(mod) for mod in deps])
source = _py_source(mod_name)
# 'foo.bar' -> 'foo._bar'
mod_name_parts = mod_name.rsplit('.', 1)
mod_name_parts[-1] = '_' + mod_name_parts[-1]
mod_name = '.'.join(mod_name_parts)
ext_modules.append(
Extension(
'perfmetrics.' + mod_name,
sources=[source],
depends=deps,
define_macros=[('CYTHON_TRACE', '0')],
))
try:
ext_modules = cythonize(
ext_modules,
annotate=True,
compiler_directives={
#'linetrace': True,
'infer_types': True,
'language_level': '3str',
'always_allow_keywords': False,
'nonecheck': False,
},
)
except ValueError:
# 'invalid literal for int() with base 10: '3str'
# This is seen when an older version of Cython is installed.
# It's a bit of a chicken-and-egg, though, because installing
# from dev-requirements first scans this egg for its requirements
# before doing any updates.
import traceback
traceback.print_exc()
ext_modules = _dummy_cythonize(ext_modules)
setup(
name='perfmetrics',
version='4.1.1.dev0',
author='Shane Hathaway',
author_email='[email protected]',
maintainer='Jason Madden',
maintainer_email='[email protected]',
description='Send performance metrics about Python code to Statsd',
keywords="statsd metrics performance monitoring",
long_description=README + '\n\n' + CHANGES,
python_requires=">=3.7",
# Get strings from https://pypi.org/pypi?%3Aaction=list_classifiers
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"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 :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"License :: Repoze Public License",
"Topic :: System :: Monitoring",
],
url="https://github.com/zodb/perfmetrics",
project_urls={
'Bug Tracker': 'https://github.com/zodb/perfmetrics/issues',
'Source Code': 'https://github.com/zodb/perfmetrics/',
'Documentation': 'https://perfmetrics.readthedocs.io',
},
license='BSD-derived (http://www.repoze.org/LICENSE.txt)',
packages=find_packages('src'),
package_dir={'': 'src'},
ext_modules=ext_modules,
include_package_data=True,
zip_safe=True,
tests_require=tests_require,
install_requires=[
'setuptools',
],
extras_require={
'test': tests_require,
'docs': [
'Sphinx >= 2.1.2',
'repoze.sphinx.autointerface',
'pyhamcrest',
'furo',
],
},
entry_points="""\
[paste.filter_app_factory]
statsd = perfmetrics:make_statsd_app
""",
)