-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
179 lines (142 loc) · 5.14 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
from __future__ import print_function
import sys
import os
with_setuptools = False
try:
from setuptools import setup
with_setuptools = True
except ImportError:
from distutils.core import setup
from distutils.core import Extension
from distutils.command.build_ext import build_ext
from distutils.errors import (CCompilerError, DistutilsExecError,
DistutilsPlatformError)
copyright = '(C) Copyright 2010-2013 New Relic Inc. All rights reserved.'
script_directory = os.path.dirname(__file__)
if not script_directory:
script_directory = os.getcwd()
develop_file = os.path.join(script_directory, 'DEVELOP')
version_file = os.path.join(script_directory, 'VERSION')
license_file = os.path.join(script_directory, 'LICENSE')
if os.path.exists(develop_file):
# Building from source repository.
import newrelic
package_version = newrelic.version
version_file_fds = open(version_file, 'w')
print(package_version, file=version_file_fds)
version_file_fds.close()
else:
# Installing from release package.
package_version = open(version_file, 'r').read().strip()
if sys.platform == 'win32' and sys.version_info > (2, 6):
build_ext_errors = (CCompilerError, DistutilsExecError,
DistutilsPlatformError, IOError)
else:
build_ext_errors = (CCompilerError, DistutilsExecError,
DistutilsPlatformError)
class BuildExtFailed(Exception):
pass
class optional_build_ext(build_ext):
def run(self):
try:
build_ext.run(self)
except DistutilsPlatformError:
raise BuildExtFailed()
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except build_ext_errors:
raise BuildExtFailed()
packages = [
"newrelic",
"newrelic.api",
"newrelic.bootstrap",
"newrelic.common",
"newrelic.core",
"newrelic.extras",
"newrelic.extras.framework_django",
"newrelic.extras.framework_django.templatetags",
"newrelic.hooks",
"newrelic.network",
"newrelic/packages",
"newrelic/packages/requests",
"newrelic/packages/requests/packages",
"newrelic/packages/requests/packages/charade",
"newrelic/packages/requests/packages/urllib3",
"newrelic/packages/requests/packages/urllib3/packages",
"newrelic/packages/requests/packages/urllib3/packages/ssl_match_hostname",
"newrelic/packages/simplejson",
"newrelic.samplers",
]
kwargs = dict(
name = "newrelic",
version = package_version,
description = "Python agent for New Relic",
author = "New Relic",
author_email = "[email protected]",
license = copyright,
url = "http://www.newrelic.com",
packages = packages,
package_data = { 'newrelic': ['newrelic.ini', 'LICENSE',
'packages/requests/LICENSE', 'packages/requests/NOTICE',
'packages/requests/cacert.pem', 'packages/simplejson/LICENSE.txt'] },
extra_path = ( "newrelic", "newrelic-%s" % package_version ),
scripts = [ 'scripts/newrelic-admin' ],
)
if with_setuptools:
kwargs['entry_points'] = {
'console_scripts': ['newrelic-admin = newrelic.admin:main'],
}
def run_setup(with_extensions):
kwargs_tmp = dict(kwargs)
if with_extensions:
monotonic_libraries = []
if sys.platform == 'linux2':
monotonic_libraries = ['rt']
kwargs_tmp['ext_modules'] = [
Extension("newrelic.packages.simplejson._speedups",
["newrelic/packages/simplejson/_speedups.c"]),
Extension("newrelic.common._monotonic",
["newrelic/common/_monotonic.c"],
libraries=monotonic_libraries),
Extension("newrelic.core._thread_utilization",
["newrelic/core/_thread_utilization.c"]),
]
kwargs_tmp['cmdclass'] = dict(build_ext=optional_build_ext)
setup(**kwargs_tmp)
WARNING = """
WARNING: The optional C extension components of the Python agent could
not be compiled. This can occur where a compiler is not present on the
target system or the Python installation does not have the corresponding
developer package installed. The Python agent will instead be installed
without the extensions. The consequence of this is that although the
Python agent will still run, JSON encoding/decoding speedups will not be
available, nor will some of the non core features of the Python agent.
"""
with_extensions = os.environ.get('NEW_RELIC_EXTENSIONS', None)
if with_extensions:
if with_extensions.lower() == 'true':
with_extensions = True
elif with_extensions.lower() == 'false':
with_extensions = False
else:
with_extensions = None
if hasattr(sys, 'pypy_version_info'):
with_extensions = False
if with_extensions is not None:
run_setup(with_extensions=with_extensions)
else:
try:
run_setup(with_extensions=True)
except BuildExtFailed:
print(75 * '*')
print(WARNING)
print("INFO: Trying to build without extensions.")
print()
print(75 * '*')
run_setup(with_extensions=False)
print(75 * '*')
print(WARNING)
print("INFO: Only pure Python agent was installed.")
print()
print(75 * '*')