forked from DataDog/dd-trace-py
-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
366 lines (320 loc) · 12.2 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import os
import platform
import sys
from setuptools import setup, find_packages, Extension
from setuptools.command.test import test as TestCommand
from setuptools.command.build_ext import build_ext as BuildExtCommand
# ORDER MATTERS
# Import this after setuptools or it will fail
from Cython.Build import cythonize # noqa: I100
import Cython.Distutils
HERE = os.path.dirname(os.path.abspath(__file__))
DEBUG_COMPILE = "DD_COMPILE_DEBUG" in os.environ
IS_PYSTON = hasattr(sys, "pyston_version_info")
def load_module_from_project_file(mod_name, fname):
"""
Helper used to load a module from a file in this project
DEV: Loading this way will by-pass loading all parent modules
e.g. importing `ddtrace.vendor.psutil.setup` will load `ddtrace/__init__.py`
which has side effects like loading the tracer
"""
fpath = os.path.join(HERE, fname)
if sys.version_info >= (3, 5):
import importlib.util
spec = importlib.util.spec_from_file_location(mod_name, fpath)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
elif sys.version_info >= (3, 3):
from importlib.machinery import SourceFileLoader
return SourceFileLoader(mod_name, fpath).load_module()
else:
import imp
return imp.load_source(mod_name, fpath)
class Tox(TestCommand):
user_options = [("tox-args=", "a", "Arguments to pass to tox")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.tox_args = None
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import tox
import shlex
args = self.tox_args
if args:
args = shlex.split(self.tox_args)
errno = tox.cmdline(args=args)
sys.exit(errno)
class CMake(BuildExtCommand):
def build_extension(self, ext):
import shutil
import subprocess
import tempfile
to_build = set()
# Detect if any source file sits next to a CMakeLists.txt file
for source in ext.sources:
source_dir = os.path.dirname(os.path.realpath(source))
if os.path.exists(os.path.join(source_dir, "CMakeLists.txt")):
to_build.add(source_dir)
if not to_build:
# Build the extension as usual
BuildExtCommand.build_extension(self, ext)
return
try:
cmake_command = os.environ.get("CMAKE_COMMAND", "cmake")
build_type = "RelWithDebInfo" if DEBUG_COMPILE else "Release"
opts = ["-DCMAKE_BUILD_TYPE={}".format(build_type)]
if platform.system() == "Windows":
opts.extend(["-A", "x64" if platform.architecture()[0] == "64bit" else "Win32"])
else:
opts.extend(["-G", "Ninja"])
ninja_command = os.environ.get("NINJA_COMMAND", "")
if ninja_command:
opts.append("-DCMAKE_MAKE_PROGRAM={}".format(ninja_command))
for source_dir in to_build:
try:
build_dir = tempfile.mkdtemp()
subprocess.check_call([cmake_command, "-S", source_dir, "-B", build_dir] + opts)
subprocess.check_call([cmake_command, "--build", build_dir, "--config", build_type])
finally:
if not DEBUG_COMPILE:
shutil.rmtree(build_dir, ignore_errors=True)
BuildExtCommand.build_extension(self, ext)
except Exception as e:
print('WARNING: building extension "%s" failed: %s' % (ext.name, e))
raise
long_description = """
# dd-trace-py
`ddtrace` is Datadog's tracing library for Python. It is used to trace requests
as they flow across web servers, databases and microservices so that developers
have great visibility into bottlenecks and troublesome requests.
## Getting Started
For a basic product overview, installation and quick start, check out our
[setup documentation][setup docs].
For more advanced usage and configuration, check out our [API
documentation][api docs].
For descriptions of terminology used in APM, take a look at the [official
documentation][visualization docs].
[setup docs]: https://docs.datadoghq.com/tracing/setup/python/
[api docs]: https://ddtrace.readthedocs.io/
[visualization docs]: https://docs.datadoghq.com/tracing/visualization/
"""
def get_exts_for(name):
try:
mod = load_module_from_project_file(
"ddtrace.vendor.{}.setup".format(name), "ddtrace/vendor/{}/setup.py".format(name)
)
return mod.get_extensions()
except Exception as e:
print("WARNING: Failed to load %s extensions, skipping: %s" % (name, e))
return []
if sys.byteorder == "big":
encoding_macros = [("__BIG_ENDIAN__", "1")]
else:
encoding_macros = [("__LITTLE_ENDIAN__", "1")]
if platform.system() == "Windows":
encoding_libraries = ["ws2_32"]
extra_compile_args = []
debug_compile_args = []
ddwaf_libraries = ["ddwaf_static"]
else:
linux = platform.system() == "Linux"
encoding_libraries = []
extra_compile_args = ["-DPy_BUILD_CORE"]
if DEBUG_COMPILE:
if linux:
debug_compile_args = ["-g", "-O0", "-Wall", "-Wextra", "-Wpedantic"]
else:
debug_compile_args = [
"-g",
"-O0",
"-Wall",
"-Wextra",
"-Wpedantic",
# Cython is not deprecation-proof
"-Wno-deprecated-declarations",
]
else:
debug_compile_args = []
if linux:
ddwaf_libraries = ["ddwaf", "rt", "m", "dl", "pthread"]
else:
ddwaf_libraries = ["ddwaf"]
if sys.version_info[:2] >= (3, 4) and not IS_PYSTON:
ext_modules = [
Extension(
"ddtrace.profiling.collector._memalloc",
sources=[
"ddtrace/profiling/collector/_memalloc.c",
"ddtrace/profiling/collector/_memalloc_tb.c",
"ddtrace/profiling/collector/_memalloc_heap.c",
],
extra_compile_args=debug_compile_args,
),
]
else:
ext_modules = []
bytecode = [
"dead-bytecode; python_version<'3.0'", # backport of bytecode for Python 2.7
"bytecode~=0.12.0; python_version=='3.5'",
"bytecode~=0.13.0; python_version=='3.6'",
"bytecode~=0.13.0; python_version=='3.7'",
"bytecode; python_version>='3.8'",
]
setup(
name="ddtrace",
description="Datadog APM client library",
url="https://github.com/DataDog/dd-trace-py",
package_urls={
"Changelog": "https://ddtrace.readthedocs.io/en/stable/release_notes.html",
"Documentation": "https://ddtrace.readthedocs.io/en/stable/",
},
project_urls={
"Bug Tracker": "https://github.com/DataDog/dd-trace-py/issues",
"Source Code": "https://github.com/DataDog/dd-trace-py/",
"Changelog": "https://ddtrace.readthedocs.io/en/stable/release_notes.html",
"Documentation": "https://ddtrace.readthedocs.io/en/stable/",
},
author="Datadog, Inc.",
author_email="[email protected]",
long_description=long_description,
long_description_content_type="text/markdown",
license="BSD",
packages=find_packages(exclude=["tests*", "benchmarks"]),
package_data={
"ddtrace": ["py.typed"],
"ddtrace.appsec": ["rules.json"],
},
py_modules=["ddtrace_gevent_check"],
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
zip_safe=False,
# enum34 is an enum backport for earlier versions of python
# funcsigs backport required for vendored debtcollector
install_requires=[
"ddsketch>=2.0.1",
"enum34; python_version<'3.4'",
"funcsigs>=1.0.0; python_version=='2.7'",
"typing; python_version<'3.5'",
"packaging>=17.1",
"protobuf>=3; python_version>='3.7'",
"protobuf>=3,<4.0; python_version=='3.6'",
"protobuf>=3,<3.18; python_version<'3.6'",
"tenacity>=5",
"attrs>=19.2.0",
"cattrs",
"six>=1.12.0",
"typing_extensions",
"importlib_metadata; python_version<'3.8'",
"pathlib2; python_version<'3.5'",
"jsonschema",
"xmltodict>=0.12",
"backport_ipaddress; python_version=='2.7'",
]
+ bytecode,
extras_require={
# users can include opentracing by having:
# install_requires=['ddtrace[opentracing]', ...]
"opentracing": ["opentracing>=2.0.0"],
},
# plugin tox
tests_require=["tox", "flake8"],
cmdclass={"build_ext": CMake, "test": Tox},
entry_points={
"console_scripts": [
"ddtrace-run = ddtrace.commands.ddtrace_run:main",
],
"pytest11": [
"ddtrace = ddtrace.contrib.pytest.plugin",
"ddtrace.pytest_bdd = ddtrace.contrib.pytest_bdd.plugin",
],
"gevent.plugins.monkey.did_patch_all": [
"ddtrace_gevent_check = ddtrace_gevent_check:gevent_patch_all",
],
},
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.5",
"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",
],
use_scm_version={"write_to": "ddtrace/_version.py"},
setup_requires=["setuptools_scm[toml]>=4,<6.1", "cython", "cmake", "ninja"],
ext_modules=ext_modules
+ cythonize(
[
Cython.Distutils.Extension(
"ddtrace.internal._rand",
sources=["ddtrace/internal/_rand.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.internal._tagset",
sources=["ddtrace/internal/_tagset.pyx"],
language="c",
),
Extension(
"ddtrace.internal._encoding",
["ddtrace/internal/_encoding.pyx"],
include_dirs=["."],
libraries=encoding_libraries,
define_macros=encoding_macros,
),
Cython.Distutils.Extension(
"ddtrace.profiling.collector.stack",
sources=["ddtrace/profiling/collector/stack.pyx"],
language="c",
extra_compile_args=extra_compile_args,
),
Cython.Distutils.Extension(
"ddtrace.profiling.collector._traceback",
sources=["ddtrace/profiling/collector/_traceback.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.profiling._threading",
sources=["ddtrace/profiling/_threading.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.profiling.collector._task",
sources=["ddtrace/profiling/collector/_task.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.profiling.exporter.pprof",
sources=["ddtrace/profiling/exporter/pprof.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.profiling._build",
sources=["ddtrace/profiling/_build.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.appsec._ddwaf",
sources=["ddtrace/appsec/_ddwaf.pyx"],
include_dirs=["ddtrace/appsec/include"],
library_dirs=["ddtrace/appsec/lib"],
libraries=ddwaf_libraries,
language="c++",
),
],
compile_time_env={
"PY_MAJOR_VERSION": sys.version_info.major,
"PY_MINOR_VERSION": sys.version_info.minor,
"PY_MICRO_VERSION": sys.version_info.micro,
},
force=True,
annotate=os.getenv("_DD_CYTHON_ANNOTATE") == "1",
)
+ get_exts_for("wrapt")
+ get_exts_for("psutil"),
)