all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 899dea70577479072b9eaafc35c328e7314b5839 11700 bytes (raw)
name: gnu/packages/patches/python-debugpy-unbundle-pydevd.patch 	 # note: path name is non-authoritative(*)

  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
 
Allow using pydevd as a regular dependency.
Submitted upstream at: https://github.com/microsoft/debugpy/pull/1586

diff --git a/setup.py b/setup.py
index 1bfba237..afffc6b2 100644
--- a/setup.py
+++ b/setup.py
@@ -11,6 +11,8 @@ import subprocess
 import sys
 
 
+BUNDLE_DEBUGPY = not (os.getenv("BUNDLE_DEBUGPY").strip().lower() == "0")
+
 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
 import versioneer  # noqa
 
@@ -18,12 +20,14 @@ del sys.path[0]
 
 sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "src"))
 import debugpy
-import debugpy._vendored
+
+if BUNDLE_DEBUGPY:
+    import debugpy._vendored
 
 del sys.path[0]
 
-
-PYDEVD_ROOT = debugpy._vendored.project_root("pydevd")
+if BUNDLE_DEBUGPY:
+    PYDEVD_ROOT = debugpy._vendored.project_root("pydevd")
 DEBUGBY_ROOT = os.path.dirname(os.path.abspath(debugpy.__file__))
 
 
@@ -46,7 +50,7 @@ def get_buildplatform():
 # relevant setuptools versions.
 class ExtModules(list):
     def __bool__(self):
-        return True
+        return BUNDLE_DEBUGPY
 
 
 def override_build(cmds):
@@ -147,7 +151,28 @@ if __name__ == "__main__":
 
     cmds = versioneer.get_cmdclass()
     override_build(cmds)
-    override_build_py(cmds)
+    if BUNDLE_DEBUGPY:
+        override_build_py(cmds)
+
+    data = {"debugpy": ["ThirdPartyNotices.txt"]}
+    packages = [
+        "debugpy",
+        "debugpy.adapter",
+        "debugpy.common",
+        "debugpy.launcher",
+        "debugpy.server",
+    ]
+    if BUNDLE_DEBUGPY:
+        data.update(
+            {
+                "debugpy._vendored": [
+                    # pydevd extensions must be built before this list can
+                    # be computed properly, so it is populated in the
+                    # overridden build_py.finalize_options().
+                ]
+            }
+        )
+        packages.append("debugpy._vendored")
 
     setuptools.setup(
         name="debugpy",
@@ -177,23 +202,10 @@ if __name__ == "__main__":
             "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": [
-                # pydevd extensions must be built before this list can be computed properly,
-                # so it is populated in the overridden build_py.finalize_options().
-            ],
-        },
+        packages=packages,
+        package_data=data,
         ext_modules=ExtModules(),
-        has_ext_modules=lambda: True,
+        has_ext_modules=lambda: BUNDLE_DEBUGPY,
         cmdclass=cmds,
         **extras
     )
diff --git a/src/debugpy/__init__.py b/src/debugpy/__init__.py
index 975bec79..512219d7 100644
--- a/src/debugpy/__init__.py
+++ b/src/debugpy/__init__.py
@@ -24,6 +24,13 @@ __all__ = [  # noqa
 
 import sys
 
+try:
+    import debugpy._vendored  # noqa
+
+    is_pydevd_bundled = True
+except ImportError:
+    is_pydevd_bundled = False
+
 assert sys.version_info >= (3, 7), (
     "Python 3.6 and below is not supported by this version of debugpy; "
     "use debugpy 1.5.1 or earlier."
diff --git a/src/debugpy/_vendored/force_pydevd.py b/src/debugpy/_vendored/force_pydevd.py
index cfd89275..99622f8c 100644
--- a/src/debugpy/_vendored/force_pydevd.py
+++ b/src/debugpy/_vendored/force_pydevd.py
@@ -3,7 +3,6 @@
 # for license information.
 
 from importlib import import_module
-import os
 import warnings
 
 from . import check_modules, prefix_matcher, preimport, vendored
@@ -17,23 +16,12 @@ if _unvendored:
     # raise ImportError(msg)
     warnings.warn(msg + ':\n {}'.format('\n  '.join(_unvendored)))
 
-# If debugpy logging is enabled, enable it for pydevd as well
-if "DEBUGPY_LOG_DIR" in os.environ:
-    os.environ[str("PYDEVD_DEBUG")] = str("True")
-    os.environ[str("PYDEVD_DEBUG_FILE")] = os.environ["DEBUGPY_LOG_DIR"] + str("/debugpy.pydevd.log")
-
-# Disable pydevd frame-eval optimizations only if unset, to allow opt-in.
-if "PYDEVD_USE_FRAME_EVAL" not in os.environ:
-    os.environ[str("PYDEVD_USE_FRAME_EVAL")] = str("NO")
-
 # Constants must be set before importing any other pydevd module
-# # due to heavy use of "from" in them.
+# due to heavy use of "from" in them.
 with warnings.catch_warnings():
     warnings.simplefilter("ignore", category=DeprecationWarning)
     with vendored('pydevd'):
         pydevd_constants = import_module('_pydevd_bundle.pydevd_constants')
-# We limit representation size in our representation provider when needed.
-pydevd_constants.MAXIMUM_VARIABLE_REPRESENTATION_SIZE = 2 ** 32
 
 # Now make sure all the top-level modules and packages in pydevd are
 # loaded.  Any pydevd modules that aren't loaded at this point, will
@@ -50,32 +38,3 @@ with warnings.catch_warnings():
         'pydevd_plugins',
         'pydevd',
     ])
-
-# When pydevd is imported it sets the breakpoint behavior, but it needs to be
-# overridden because by default pydevd will connect to the remote debugger using
-# its own custom protocol rather than DAP.
-import pydevd  # noqa
-import debugpy  # noqa
-
-
-def debugpy_breakpointhook():
-    debugpy.breakpoint()
-
-
-pydevd.install_breakpointhook(debugpy_breakpointhook)
-
-# Ensure that pydevd uses JSON protocol
-from _pydevd_bundle import pydevd_constants
-from _pydevd_bundle import pydevd_defaults
-pydevd_defaults.PydevdCustomization.DEFAULT_PROTOCOL = pydevd_constants.HTTP_JSON_PROTOCOL
-
-# Enable some defaults related to debugpy such as sending a single notification when
-# threads pause and stopping on any exception.
-pydevd_defaults.PydevdCustomization.DEBUG_MODE = 'debugpy-dap'
-
-# This is important when pydevd attaches automatically to a subprocess. In this case, we have to
-# make sure that debugpy is properly put back in the game for users to be able to use it.
-pydevd_defaults.PydevdCustomization.PREIMPORT = '%s;%s' % (
-    os.path.dirname(os.path.dirname(debugpy.__file__)), 
-    'debugpy._vendored.force_pydevd'
-)
diff --git a/src/debugpy/server/__init__.py b/src/debugpy/server/__init__.py
index 42d5367f..a27c6bf4 100644
--- a/src/debugpy/server/__init__.py
+++ b/src/debugpy/server/__init__.py
@@ -2,6 +2,70 @@
 # Licensed under the MIT License. See LICENSE in the project root
 # for license information.
 
+from __future__ import absolute_import, division, print_function, unicode_literals
+
+from importlib import import_module
+import os
+
 # "force_pydevd" must be imported first to ensure (via side effects)
 # that the debugpy-vendored copy of pydevd gets used.
-import debugpy._vendored.force_pydevd  # noqa
+import debugpy
+
+# If debugpy logging is enabled, enable it for pydevd as well
+if "DEBUGPY_LOG_DIR" in os.environ:
+    os.environ[str("PYDEVD_DEBUG")] = str("True")
+    os.environ[str("PYDEVD_DEBUG_FILE")] = os.environ["DEBUGPY_LOG_DIR"] + str(
+        "/debugpy.pydevd.log"
+    )
+
+# Disable pydevd frame-eval optimizations only if unset, to allow opt-in.
+if "PYDEVD_USE_FRAME_EVAL" not in os.environ:
+    os.environ[str("PYDEVD_USE_FRAME_EVAL")] = str("NO")
+
+BUNDLE_DEBUGPY = bool(os.getenv("BUNDLE_DEBUGPY"))
+
+# Constants must be set before importing any other pydevd module
+# due to heavy use of "from" in them.
+if BUNDLE_DEBUGPY:
+    try:
+        import debugpy._vendored.force_pydevd  # noqa
+    except Exception as e:
+        raise e
+else:
+    pydevd_constants = import_module("_pydevd_bundle.pydevd_constants")
+
+# We limit representation size in our representation provider when needed.
+pydevd_constants.MAXIMUM_VARIABLE_REPRESENTATION_SIZE = 2**32
+
+# When pydevd is imported it sets the breakpoint behavior, but it needs to be
+# overridden because by default pydevd will connect to the remote debugger using
+# its own custom protocol rather than DAP.
+import pydevd  # noqa
+import debugpy  # noqa
+
+
+def debugpy_breakpointhook():
+    debugpy.breakpoint()
+
+
+pydevd.install_breakpointhook(debugpy_breakpointhook)
+
+# Ensure that pydevd uses JSON protocol
+from _pydevd_bundle import pydevd_constants
+from _pydevd_bundle import pydevd_defaults
+
+pydevd_defaults.PydevdCustomization.DEFAULT_PROTOCOL = (
+    pydevd_constants.HTTP_JSON_PROTOCOL
+)
+
+# Enable some defaults related to debugpy such as sending a single notification when
+# threads pause and stopping on any exception.
+pydevd_defaults.PydevdCustomization.DEBUG_MODE = "debugpy-dap"
+
+# This is important when pydevd attaches automatically to a subprocess. In this case, we have to
+# make sure that debugpy is properly put back in the game for users to be able to use it.
+if not BUNDLE_DEBUGPY:
+    pydevd_defaults.PydevdCustomization.PREIMPORT = "%s;%s" % (
+        os.path.dirname(os.path.dirname(debugpy.__file__)),
+        "debugpy._vendored.force_pydevd",
+    )
diff --git a/src/debugpy/server/attach_pid_injected.py b/src/debugpy/server/attach_pid_injected.py
index a8df6e1e..06e49600 100644
--- a/src/debugpy/server/attach_pid_injected.py
+++ b/src/debugpy/server/attach_pid_injected.py
@@ -6,6 +6,7 @@
 
 import os
 
+import debugpy
 
 __file__ = os.path.abspath(__file__)
 _debugpy_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
@@ -28,25 +29,29 @@ def attach(setup):
                 def on_critical(msg):
                     print(msg, file=sys.stderr)
 
-                pydevd_attach_to_process_path = os.path.join(
-                    _debugpy_dir,
-                    "debugpy",
-                    "_vendored",
-                    "pydevd",
-                    "pydevd_attach_to_process",
-                )
-                assert os.path.exists(pydevd_attach_to_process_path)
-                sys.path.insert(0, pydevd_attach_to_process_path)
+                if not debugpy.is_pydevd_bundled:
+                    from pydevd_attach_to_process import attach_script
+                else:
+                    pydevd_attach_to_process_path = os.path.join(
+                        _debugpy_dir,
+                        "debugpy",
+                        "_vendored",
+                        "pydevd",
+                        "pydevd_attach_to_process",
+                    )
+                    assert os.path.exists(pydevd_attach_to_process_path)
+                    sys.path.insert(0, pydevd_attach_to_process_path)
 
-                # NOTE: that it's not a part of the pydevd PYTHONPATH
-                import attach_script
+                    # NOTE: that it's not a part of the pydevd PYTHONPATH
+                    import attach_script
 
                 attach_script.fix_main_thread_id(
                     on_warn=on_warn, on_exception=on_exception, on_critical=on_critical
                 )
 
-                # NOTE: At this point it should be safe to remove this.
-                sys.path.remove(pydevd_attach_to_process_path)
+                if debugpy.is_pydevd_bundled:
+                    # NOTE: At this point it should be safe to remove this.
+                    sys.path.remove(pydevd_attach_to_process_path)
             except:
                 import traceback
 
diff --git a/tests/tests/test_vendoring.py b/tests/tests/test_vendoring.py
index 9cf44220..3188eb9e 100644
--- a/tests/tests/test_vendoring.py
+++ b/tests/tests/test_vendoring.py
@@ -3,6 +3,12 @@
 # for license information.
 
 
+import pytest
+
+import debugpy
+
+
+@pytest.mark.skipif(not debugpy.is_pydevd_bundled, reason="pydevd is not bundled")
 def test_vendoring(pyfile):
     @pyfile
     def import_debugpy():
-- 
2.41.0


debug log:

solving 899dea70577 ...
found 899dea70577 in https://yhetil.org/guix/20240517054144.15296-1-ngraves@ngraves.fr/ ||
	https://yhetil.org/guix/20240518100040.13601-2-ngraves@ngraves.fr/
found 7a6ad544896 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 7a6ad544896bfda560769ce1bfa8ab7f1e8b9555	gnu/packages/patches/python-debugpy-unbundle-pydevd.patch

applying [1/1] https://yhetil.org/guix/20240517054144.15296-1-ngraves@ngraves.fr/
diff --git a/gnu/packages/patches/python-debugpy-unbundle-pydevd.patch b/gnu/packages/patches/python-debugpy-unbundle-pydevd.patch
index 7a6ad544896..899dea70577 100644

1:125: trailing whitespace.
 
1:187: trailing whitespace.
 
1:192: trailing whitespace.
 
1:211: trailing whitespace.
 
1:244: trailing whitespace.
-    os.path.dirname(os.path.dirname(debugpy.__file__)), 
Checking patch gnu/packages/patches/python-debugpy-unbundle-pydevd.patch...
Applied patch gnu/packages/patches/python-debugpy-unbundle-pydevd.patch cleanly.
warning: squelched 3 whitespace errors
warning: 8 lines add whitespace errors.

skipping https://yhetil.org/guix/20240518100040.13601-2-ngraves@ngraves.fr/ for 899dea70577
index at:
100644 899dea70577479072b9eaafc35c328e7314b5839	gnu/packages/patches/python-debugpy-unbundle-pydevd.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.