From 87b8d4b6e650d57e20916559a0c07c0da0c75140 Mon Sep 17 00:00:00 2001 From: Dmitriy Vasyura Date: Fri, 27 Nov 2026 00:25:21 -0800 Subject: [PATCH 1/4] Remove unused debugger extension and Python bundle dependencies Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/actions/build-vsix/action.yml | 2 +- .github/actions/lint/action.yml | 2 +- noxfile.py | 17 --- package-lock.json | 135 ++---------------- package.json | 4 +- requirements.in | 7 - requirements.txt | 10 -- .../configuration/resolvers/base.unit.test.ts | 3 +- 8 files changed, 12 insertions(+), 168 deletions(-) delete mode 100644 requirements.in delete mode 100644 requirements.txt diff --git a/.github/actions/build-vsix/action.yml b/.github/actions/build-vsix/action.yml index fb2e2027..62f4c417 100644 --- a/.github/actions/build-vsix/action.yml +++ b/.github/actions/build-vsix/action.yml @@ -26,7 +26,7 @@ runs: uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-build-vsix-${{ hashFiles('**/requirements.txt') }} + key: ${{ runner.os }}-pip-build-vsix-${{ hashFiles('noxfile.py') }} restore-keys: | ${{ runner.os }}-pip-build-vsix- diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml index 84469a6f..75b0fba3 100644 --- a/.github/actions/lint/action.yml +++ b/.github/actions/lint/action.yml @@ -40,7 +40,7 @@ runs: uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-lint-${{ hashFiles('**/requirements.txt') }} + key: ${{ runner.os }}-pip-lint-${{ hashFiles('noxfile.py') }} restore-keys: | ${{ runner.os }}-pip-lint- diff --git a/noxfile.py b/noxfile.py index 7ddabc90..a94bc15b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -119,29 +119,12 @@ def lint(session: nox.Session) -> None: @nox.session() def tests(session: nox.Session) -> None: """Runs all the tests for the extension.""" - session.install("-r", "./requirements.txt") session.run("npm", "run", "test") @nox.session() def install_bundled_libs(session): """Installs the libraries that will be bundled with the extension.""" - session.install("wheel") - session.install( - "-t", - "./bundled/libs", - "--no-cache-dir", - "--implementation", - "py", - "--no-deps", - "--require-hashes", - "--only-binary", - ":all:", - "-r", - "./requirements.txt", - ) - session.install("packaging") - target = os.environ.get("VSCETARGET", "") print("target:", target) diff --git a/package-lock.json b/package-lock.json index 75105cac..807d0ce3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "2026.7.0-dev", "license": "MIT", "dependencies": { - "@vscode/debugadapter": "^1.65.0", "@vscode/debugprotocol": "^1.65.0", "@vscode/extension-telemetry": "^1.5.2", "@vscode/python-extension": "^1.0.6", @@ -17,8 +16,7 @@ "fs-extra": "^11.2.0", "iconv-lite": "^0.6.3", "jsonc-parser": "^3.0.0", - "lodash": "^4.18.1", - "vscode-languageclient": "^8.0.2" + "lodash": "^4.18.1" }, "devDependencies": { "@types/chai": "^4.1.2", @@ -1272,17 +1270,6 @@ "node": ">=20.0.0" } }, - "node_modules/@vscode/debugadapter": { - "version": "1.65.0", - "resolved": "https://registry.npmjs.org/@vscode/debugadapter/-/debugadapter-1.65.0.tgz", - "integrity": "sha512-l9jdX0GFoFVAc7O4O8iVnCjO0pgxbx+wJJXCaYSuglGtYwMNcJdc7xm96cuVx4LWzSqneIjvjzbuzZtoVZhZzQ==", - "dependencies": { - "@vscode/debugprotocol": "1.65.0" - }, - "engines": { - "node": ">=14" - } - }, "node_modules/@vscode/debugprotocol": { "version": "1.65.0", "resolved": "https://registry.npmjs.org/@vscode/debugprotocol/-/debugprotocol-1.65.0.tgz", @@ -1930,7 +1917,8 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true }, "node_modules/baseline-browser-mapping": { "version": "2.11.21", @@ -5002,6 +4990,7 @@ "version": "7.8.6", "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.6.tgz", "integrity": "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==", + "dev": true, "license": "ISC", "bin": { "semver": "bin/semver.js" @@ -5687,61 +5676,6 @@ "url": "https://bevry.me/fund" } }, - "node_modules/vscode-jsonrpc": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.1.0.tgz", - "integrity": "sha512-6TDy/abTQk+zDGYazgbIPc+4JoXdwC8NHU9Pbn4UJP1fehUyZmM4RHp5IthX7A6L5KS30PRui+j+tbbMMMafdw==", - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/vscode-languageclient": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.1.0.tgz", - "integrity": "sha512-GL4QdbYUF/XxQlAsvYWZRV3V34kOkpRlvV60/72ghHfsYFnS/v2MANZ9P6sHmxFcZKOse8O+L9G7Czg0NUWing==", - "dependencies": { - "minimatch": "^5.1.0", - "semver": "^7.3.7", - "vscode-languageserver-protocol": "3.17.3" - }, - "engines": { - "vscode": "^1.67.0" - } - }, - "node_modules/vscode-languageclient/node_modules/brace-expansion": { - "version": "2.1.7", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz", - "integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==", - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/vscode-languageclient/node_modules/minimatch": { - "version": "5.1.9", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.9.tgz", - "integrity": "sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw==", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/vscode-languageserver-protocol": { - "version": "3.17.3", - "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.3.tgz", - "integrity": "sha512-924/h0AqsMtA5yK22GgMtCYiMdCOtWTSGgUOkgEDX+wk2b0x4sAfLiO4NxBxqbiVtz7K7/1/RgVrVI0NClZwqA==", - "dependencies": { - "vscode-jsonrpc": "8.1.0", - "vscode-languageserver-types": "3.17.3" - } - }, - "node_modules/vscode-languageserver-types": { - "version": "3.17.3", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.3.tgz", - "integrity": "sha512-SYU4z1dL0PyIMd4Vj8YOqFvHu7Hz/enbWtpfnVbJHU4Nd1YNYx8u0ennumc6h48GQNeOLxmwySmnADouT/AuZA==" - }, "node_modules/watchpack": { "version": "2.5.1", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.5.1.tgz", @@ -6844,14 +6778,6 @@ "tslib": "^2.6.2" } }, - "@vscode/debugadapter": { - "version": "1.65.0", - "resolved": "https://registry.npmjs.org/@vscode/debugadapter/-/debugadapter-1.65.0.tgz", - "integrity": "sha512-l9jdX0GFoFVAc7O4O8iVnCjO0pgxbx+wJJXCaYSuglGtYwMNcJdc7xm96cuVx4LWzSqneIjvjzbuzZtoVZhZzQ==", - "requires": { - "@vscode/debugprotocol": "1.65.0" - } - }, "@vscode/debugprotocol": { "version": "1.65.0", "resolved": "https://registry.npmjs.org/@vscode/debugprotocol/-/debugprotocol-1.65.0.tgz", @@ -7336,7 +7262,8 @@ "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true }, "baseline-browser-mapping": { "version": "2.11.21", @@ -9459,7 +9386,8 @@ "semver": { "version": "7.8.6", "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.6.tgz", - "integrity": "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==" + "integrity": "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==", + "dev": true }, "serialize-javascript": { "version": "7.1.4", @@ -9888,53 +9816,6 @@ "integrity": "sha1-id8ekhsU03UVqrXkLtSsBRXKssE=", "dev": true }, - "vscode-jsonrpc": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.1.0.tgz", - "integrity": "sha512-6TDy/abTQk+zDGYazgbIPc+4JoXdwC8NHU9Pbn4UJP1fehUyZmM4RHp5IthX7A6L5KS30PRui+j+tbbMMMafdw==" - }, - "vscode-languageclient": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.1.0.tgz", - "integrity": "sha512-GL4QdbYUF/XxQlAsvYWZRV3V34kOkpRlvV60/72ghHfsYFnS/v2MANZ9P6sHmxFcZKOse8O+L9G7Czg0NUWing==", - "requires": { - "minimatch": "^5.1.0", - "semver": "^7.3.7", - "vscode-languageserver-protocol": "3.17.3" - }, - "dependencies": { - "brace-expansion": { - "version": "2.1.7", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz", - "integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==", - "requires": { - "balanced-match": "^1.0.0" - } - }, - "minimatch": { - "version": "5.1.9", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.9.tgz", - "integrity": "sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw==", - "requires": { - "brace-expansion": "^2.0.1" - } - } - } - }, - "vscode-languageserver-protocol": { - "version": "3.17.3", - "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.3.tgz", - "integrity": "sha512-924/h0AqsMtA5yK22GgMtCYiMdCOtWTSGgUOkgEDX+wk2b0x4sAfLiO4NxBxqbiVtz7K7/1/RgVrVI0NClZwqA==", - "requires": { - "vscode-jsonrpc": "8.1.0", - "vscode-languageserver-types": "3.17.3" - } - }, - "vscode-languageserver-types": { - "version": "3.17.3", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.3.tgz", - "integrity": "sha512-SYU4z1dL0PyIMd4Vj8YOqFvHu7Hz/enbWtpfnVbJHU4Nd1YNYx8u0ennumc6h48GQNeOLxmwySmnADouT/AuZA==" - }, "watchpack": { "version": "2.5.1", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.5.1.tgz", diff --git a/package.json b/package.json index eded0f89..a4a1214a 100644 --- a/package.json +++ b/package.json @@ -818,7 +818,6 @@ "webpack-cli": "^4.9.2" }, "dependencies": { - "@vscode/debugadapter": "^1.65.0", "@vscode/debugprotocol": "^1.65.0", "@vscode/extension-telemetry": "^1.5.2", "@vscode/python-extension": "^1.0.6", @@ -826,7 +825,6 @@ "fs-extra": "^11.2.0", "iconv-lite": "^0.6.3", "jsonc-parser": "^3.0.0", - "lodash": "^4.18.1", - "vscode-languageclient": "^8.0.2" + "lodash": "^4.18.1" } } diff --git a/requirements.in b/requirements.in deleted file mode 100644 index e19db50f..00000000 --- a/requirements.in +++ /dev/null @@ -1,7 +0,0 @@ -# This file is used to generate requirements.txt. -# To update requirements.txt, run the following commands. -# Use Python 3.7 when creating the environment or using pip-tools -# 1) pip install pip-tools -# 2) pip-compile --generate-hashes --upgrade ./requirements.in - -packaging diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 6d22f396..00000000 --- a/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.9 -# by the following command: -# -# pip-compile --generate-hashes ./requirements.in -# -packaging==24.2 \ - --hash=sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759 \ - --hash=sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f - # via -r ./requirements.in diff --git a/src/test/unittest/configuration/resolvers/base.unit.test.ts b/src/test/unittest/configuration/resolvers/base.unit.test.ts index 14765f6d..4e241742 100644 --- a/src/test/unittest/configuration/resolvers/base.unit.test.ts +++ b/src/test/unittest/configuration/resolvers/base.unit.test.ts @@ -8,8 +8,7 @@ import { expect } from 'chai'; import * as path from 'path'; import * as sinon from 'sinon'; -import { DebugConfiguration, Uri, WorkspaceFolder } from 'vscode'; -import { CancellationToken } from 'vscode-jsonrpc'; +import { CancellationToken, DebugConfiguration, Uri, WorkspaceFolder } from 'vscode'; import { BaseConfigurationResolver } from '../../../../extension/debugger/configuration/resolvers/base'; import * as helper from '../../../../extension/debugger/configuration/resolvers/helper'; import * as vscodeapi from '../../../../extension/common/vscodeapi'; From ae1e490655846f7992bd34320c2a09f9edf0970b Mon Sep 17 00:00:00 2001 From: Dmitriy Vasyura Date: Fri, 27 Nov 2026 22:20:17 -0800 Subject: [PATCH 2/4] Replace stale bundled libraries after extracting debugpy wheels Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- noxfile.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index a94bc15b..9184a8d2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -6,6 +6,7 @@ import os import pathlib import re +import shutil import tempfile import zipfile @@ -139,13 +140,15 @@ def download_debugpy_via_pip(session: nox.Session, requests: list[dict]) -> None index URLs (e.g., Azure Artifacts feed) instead of direct PyPI URLs. """ libs_dir = pathlib.Path.cwd() / "bundled" / "libs" - libs_dir.mkdir(parents=True, exist_ok=True) if not requests: raise ValueError("No debugpy wheel requests were provided.") version = requests[0]["version"] - with tempfile.TemporaryDirectory(prefix="debugpy_wheels_") as tmp_dir: + libs_dir.parent.mkdir(parents=True, exist_ok=True) + with tempfile.TemporaryDirectory( + prefix="debugpy_wheels_", dir=libs_dir.parent + ) as tmp_dir: tmp_path = pathlib.Path(tmp_dir) for req in requests: @@ -206,12 +209,18 @@ def download_debugpy_via_pip(session: nox.Session, requests: list[dict]) -> None f"pip download produced no debugpy wheels for version {version}." ) + staged_libs = tmp_path / "libs" for wheel_path in wheel_paths: print("Downloaded:", wheel_path.name) with zipfile.ZipFile(wheel_path, "r") as wheel: for zip_info in wheel.infolist(): print("\t" + zip_info.filename) - wheel.extract(zip_info.filename, libs_dir) + wheel.extract(zip_info.filename, staged_libs) + + # Replace the generated bundle only after all wheels have been extracted. + if libs_dir.exists(): + shutil.rmtree(libs_dir) + staged_libs.rename(libs_dir) @nox.session() From 83dd47d9be79bf50c908f03c3a94a575acfa4399 Mon Sep 17 00:00:00 2001 From: Dmitriy Vasyura Date: Fri, 27 Nov 2026 22:46:53 -0800 Subject: [PATCH 3/4] Restore the previous debugger bundle when replacement fails Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .gitignore | 1 + .vscodeignore | 1 + build/test_bundled_libs.py | 47 ++++++++++++++++++++++++++++++++++++++ noxfile.py | 40 +++++++++++++++++++++++++------- 4 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 build/test_bundled_libs.py diff --git a/.gitignore b/.gitignore index d82b0989..bafa1939 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ node_modules .venv/ .nox/ bundled/libs/ +bundled/.debugpy-build/ **/__pycache__ **/.pytest_cache **/.vs diff --git a/.vscodeignore b/.vscodeignore index 39c0e6bf..7bbfbd15 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -18,6 +18,7 @@ vsc-extension-quickstart.md **/__pycache__/** **/.pyc bundled/libs/bin/** +bundled/.debugpy-build/** noxfile.py .pytest_cache/** .pylintrc diff --git a/build/test_bundled_libs.py b/build/test_bundled_libs.py new file mode 100644 index 00000000..3accbe50 --- /dev/null +++ b/build/test_bundled_libs.py @@ -0,0 +1,47 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import tempfile +import unittest +import zipfile +from pathlib import Path +from unittest.mock import Mock, patch + +import noxfile + + +class BundleReplacementTests(unittest.TestCase): + def test_failed_install_restores_previous_bundle_and_allows_retry(self): + with tempfile.TemporaryDirectory() as tmp, patch.object( + Path, "cwd", return_value=Path(tmp) + ): + libs = Path(tmp) / "bundled" / "libs" + libs.mkdir(parents=True) + old = libs / "old.py" + old.write_bytes(b"old") + requests = noxfile._build_debugpy_wheel_requests( + "", noxfile.DEBUGPY_VERSION + ) + + def download(*args): + dest = Path(args[args.index("--dest") + 1]) + with zipfile.ZipFile(dest / "debugpy-test.whl", "w") as wheel: + wheel.writestr("debugpy/new.py", b"new") + + session = Mock() + session.run.side_effect = download + rename = Path.rename + + def fail_install(source, target): + if source.name == "libs" and target == libs: + raise PermissionError("install blocked") + return rename(source, target) + + with patch.object(Path, "rename", fail_install): + with self.assertRaisesRegex(PermissionError, "install blocked"): + noxfile.download_debugpy_via_pip(session, requests) + + self.assertEqual(old.read_bytes(), b"old") + noxfile.download_debugpy_via_pip(session, requests) + self.assertFalse(old.exists()) + self.assertEqual((libs / "debugpy" / "new.py").read_bytes(), b"new") diff --git a/noxfile.py b/noxfile.py index 9184a8d2..5c80f0df 100644 --- a/noxfile.py +++ b/noxfile.py @@ -7,6 +7,7 @@ import pathlib import re import shutil +import sys import tempfile import zipfile @@ -120,6 +121,17 @@ def lint(session: nox.Session) -> None: @nox.session() def tests(session: nox.Session) -> None: """Runs all the tests for the extension.""" + session.run( + sys.executable, + "-m", + "unittest", + "discover", + "-s", + "build", + "-p", + "test_bundled_libs.py", + external=True, + ) session.run("npm", "run", "test") @@ -145,10 +157,14 @@ def download_debugpy_via_pip(session: nox.Session, requests: list[dict]) -> None raise ValueError("No debugpy wheel requests were provided.") version = requests[0]["version"] - libs_dir.parent.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory( - prefix="debugpy_wheels_", dir=libs_dir.parent - ) as tmp_dir: + work_dir = libs_dir.parent / ".debugpy-build" + work_dir.mkdir(parents=True, exist_ok=True) + previous_libs = work_dir / "previous" + if previous_libs.exists(): + raise FileExistsError( + f"Recover or remove the previous debugger bundle at {previous_libs} before retrying." + ) + with tempfile.TemporaryDirectory(prefix="debugpy_wheels_", dir=work_dir) as tmp_dir: tmp_path = pathlib.Path(tmp_dir) for req in requests: @@ -217,10 +233,18 @@ def download_debugpy_via_pip(session: nox.Session, requests: list[dict]) -> None print("\t" + zip_info.filename) wheel.extract(zip_info.filename, staged_libs) - # Replace the generated bundle only after all wheels have been extracted. - if libs_dir.exists(): - shutil.rmtree(libs_dir) - staged_libs.rename(libs_dir) + # Keep the backup outside tmp_dir so even a failed rollback can't discard it. + if not libs_dir.exists(): + staged_libs.rename(libs_dir) + return + + libs_dir.rename(previous_libs) + try: + staged_libs.rename(libs_dir) + except OSError: + previous_libs.rename(libs_dir) + raise + shutil.rmtree(previous_libs) @nox.session() From 8a11979e59d3d679955a76ba427734ea3ea4fb89 Mon Sep 17 00:00:00 2001 From: Dmitriy Vasyura Date: Fri, 27 Nov 2026 23:23:04 -0800 Subject: [PATCH 4/4] Retry debugger backup cleanup when the installed bundle is present Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- build/test_bundled_libs.py | 53 +++++++++++++++++++++++++++++++++----- noxfile.py | 8 +++--- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/build/test_bundled_libs.py b/build/test_bundled_libs.py index 3accbe50..b321080d 100644 --- a/build/test_bundled_libs.py +++ b/build/test_bundled_libs.py @@ -10,6 +10,12 @@ import noxfile +def download_test_wheel(*args): + dest = Path(args[args.index("--dest") + 1]) + with zipfile.ZipFile(dest / "debugpy-test.whl", "w") as wheel: + wheel.writestr("debugpy/new.py", b"new") + + class BundleReplacementTests(unittest.TestCase): def test_failed_install_restores_previous_bundle_and_allows_retry(self): with tempfile.TemporaryDirectory() as tmp, patch.object( @@ -23,13 +29,8 @@ def test_failed_install_restores_previous_bundle_and_allows_retry(self): "", noxfile.DEBUGPY_VERSION ) - def download(*args): - dest = Path(args[args.index("--dest") + 1]) - with zipfile.ZipFile(dest / "debugpy-test.whl", "w") as wheel: - wheel.writestr("debugpy/new.py", b"new") - session = Mock() - session.run.side_effect = download + session.run.side_effect = download_test_wheel rename = Path.rename def fail_install(source, target): @@ -45,3 +46,43 @@ def fail_install(source, target): noxfile.download_debugpy_via_pip(session, requests) self.assertFalse(old.exists()) self.assertEqual((libs / "debugpy" / "new.py").read_bytes(), b"new") + + def test_retry_cleans_leftover_backup_when_bundle_is_installed(self): + with tempfile.TemporaryDirectory() as tmp, patch.object( + Path, "cwd", return_value=Path(tmp) + ): + libs = Path(tmp) / "bundled" / "libs" + libs.mkdir(parents=True) + (libs / "installed.py").write_bytes(b"installed") + backup = libs.parent / ".debugpy-build" / "previous" + backup.mkdir(parents=True) + (backup / "locked.py").write_bytes(b"left over") + + session = Mock() + session.run.side_effect = download_test_wheel + noxfile.download_debugpy_via_pip( + session, + noxfile._build_debugpy_wheel_requests("", noxfile.DEBUGPY_VERSION), + ) + + self.assertFalse(backup.exists()) + self.assertEqual((libs / "debugpy" / "new.py").read_bytes(), b"new") + + def test_retry_preserves_only_remaining_bundle(self): + with tempfile.TemporaryDirectory() as tmp, patch.object( + Path, "cwd", return_value=Path(tmp) + ): + backup = Path(tmp) / "bundled" / ".debugpy-build" / "previous" + backup.mkdir(parents=True) + old = backup / "old.py" + old.write_bytes(b"recover me") + + session = Mock() + with self.assertRaises(FileExistsError): + noxfile.download_debugpy_via_pip( + session, + noxfile._build_debugpy_wheel_requests("", noxfile.DEBUGPY_VERSION), + ) + + session.run.assert_not_called() + self.assertEqual(old.read_bytes(), b"recover me") diff --git a/noxfile.py b/noxfile.py index 5c80f0df..e9ce18cf 100644 --- a/noxfile.py +++ b/noxfile.py @@ -161,9 +161,11 @@ def download_debugpy_via_pip(session: nox.Session, requests: list[dict]) -> None work_dir.mkdir(parents=True, exist_ok=True) previous_libs = work_dir / "previous" if previous_libs.exists(): - raise FileExistsError( - f"Recover or remove the previous debugger bundle at {previous_libs} before retrying." - ) + if not libs_dir.is_dir(): + raise FileExistsError( + f"Recover or remove the previous debugger bundle at {previous_libs} before retrying." + ) + shutil.rmtree(previous_libs) with tempfile.TemporaryDirectory(prefix="debugpy_wheels_", dir=work_dir) as tmp_dir: tmp_path = pathlib.Path(tmp_dir)