forked from microsoft/debugpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
191 lines (155 loc) · 6.1 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
#!/usr/bin/env python
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.
import os
import os.path
import setuptools
import subprocess
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import versioneer # noqa
del sys.path[0]
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "src"))
import debugpy
import debugpy._vendored
del sys.path[0]
PYDEVD_ROOT = debugpy._vendored.project_root("pydevd")
DEBUGBY_ROOT = os.path.dirname(os.path.abspath(debugpy.__file__))
def get_buildplatform():
if "-p" in sys.argv:
return sys.argv[sys.argv.index("-p") + 1]
return None
def cython_build():
print("Compiling extension modules (set SKIP_CYTHON_BUILD=1 to omit)")
subprocess.call(
[
sys.executable,
os.path.join(PYDEVD_ROOT, "setup_cython.py"),
"build_ext",
"-i",
]
)
def iter_vendored_files():
# Add pydevd files as data files for this package. They are not
# treated as a package of their own, because we don't actually
# want to provide pydevd - just use our own copy internally.
for project in debugpy._vendored.list_all():
for filename in debugpy._vendored.iter_packaging_files(project):
yield filename
# bdist_wheel determines whether the package is pure or not based on ext_modules.
# However, all pydevd native modules are prebuilt and packaged as data, so they
# should not be in the list.
#
# The proper way to handle this is by overriding has_ext_modules. However, due to
# https://bugs.python.org/issue32957, in setuptools 57.0.0 and below, it is not
# always called when it should be, with ext_modules tested directly instead.
#
# So, for non-pure builds, we provide a customized empty list for ext_modules that
# tests as truthful - this causes the package to be treated as non-pure on all
# relevant setuptools versions.
class ExtModules(list):
def __bool__(self):
return True
def override_build(cmds):
def finalize_options(self):
# Mark all packages as pure if requested to build a universal wheel.
# Otherwise, bdist_wheel will silently ignore the request.
bdist_wheel = self.distribution.get_command_obj("bdist_wheel", 0)
if bdist_wheel is not None and bdist_wheel.universal:
self.distribution.ext_modules = []
self.distribution.has_ext_modules = lambda: False
original(self)
try:
build = cmds["build"]
except KeyError:
from distutils.command.build import build
original = build.finalize_options
build.finalize_options = finalize_options
def override_build_py(cmds):
# Filter platform-specific binaries in data files for binary builds.
def finalize_options(self):
original(self)
# Don't filter anything for universal wheels.
if not self.distribution.ext_modules:
return
plat = self.get_finalized_command("build").plat_name
data_files = self.data_files
def is_applicable(filename):
def tail_is(*suffixes):
return any((filename.endswith(ext) for ext in suffixes))
if tail_is(".dylib"):
return plat.startswith("macosx")
if tail_is(".exe", ".dll", ".pdb", ".pyd"):
return plat in ("win32", "win-amd64")
if tail_is("-i386-linux-gnu.so", "_linux_x86.so"):
return plat == "linux-i686"
if tail_is("-x86_64-linux-gnu.so", "_linux_amd64.so"):
return plat == "linux-x86_64"
return True
self.data_files = [
(package, src_dir, build_dir, list(filter(is_applicable, filenames)))
for package, src_dir, build_dir, filenames in data_files
]
try:
build_py = cmds["build_py"]
except KeyError:
from setuptools.command.build_py import build_py
original = build_py.finalize_options
build_py.finalize_options = finalize_options
with open("DESCRIPTION.md", "r") as fh:
long_description = fh.read()
if __name__ == "__main__":
if not os.getenv("SKIP_CYTHON_BUILD"):
cython_build()
extras = {}
platforms = get_buildplatform()
if platforms is not None:
extras["platforms"] = platforms
cmds = versioneer.get_cmdclass()
override_build(cmds)
override_build_py(cmds)
setuptools.setup(
name="debugpy",
version=versioneer.get_version(),
description="An implementation of the Debug Adapter Protocol for Python", # noqa
long_description=long_description,
long_description_content_type="text/markdown",
license="MIT",
author="Microsoft Corporation",
author_email="ptvshelp@microsoft.com",
url="https://aka.ms/debugpy",
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*",
classifiers=[
"Development Status :: 5 - Production/Stable",
"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",
"Topic :: Software Development :: Debuggers",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
"Operating System :: POSIX",
"License :: OSI Approved :: Eclipse Public License 2.0 (EPL-2.0)",
"License :: OSI Approved :: MIT License",
],
package_dir={"": "src"},
packages=[
"debugpy",
"debugpy.adapter",
"debugpy.common",
"debugpy.launcher",
"debugpy.server",
"debugpy._vendored",
],
package_data={
"debugpy": ["ThirdPartyNotices.txt"],
"debugpy._vendored": list(iter_vendored_files()),
},
ext_modules=ExtModules(),
has_ext_modules=lambda: True,
cmdclass=cmds,
**extras
)