Skip to content

Commit 9183405

Browse files
authored
Ship 2 versions of PTVSD in the extension (microsoft#7115)
* Install old PTVSD in CI & update ptvsd_launcher * Update ptvsd in requirements.txt * Parse requirements to install new ptvsd * Pass args properly * Add comment * Fix typo in ptvsd launcher * Add comment * Move install_ptvsd to pythonFiles folder * Move everything to a main function * Update comment
1 parent 15756ba commit 9183405

7 files changed

Lines changed: 72 additions & 15 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cd vscode-python
3636
npm ci
3737
python3 -m venv .venv
3838
# Activate the virtual environment as appropriate for your shell.
39-
python3 -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt
39+
npx gulp installPythonLibs
4040
# Optionally Update `launch.json` to set a value for the environment variable `CI_PYTHON_PATH` pointing to the fully qualified path of the above interpreter.
4141
```
4242
You may see warnings that ```The engine "vscode" appears to be invalid.```, you can ignore these.

‎build/ci/templates/build_compile_steps.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ steps:
6363
- bash: |
6464
python -m pip install -U pip
6565
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt
66+
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python/old_ptvsd --no-cache-dir --implementation py --no-deps --upgrade 'ptvsd==4.3.2'
6667
failOnStderr: true
6768
displayName: "pip install requirements"
6869
condition: and(succeeded(), eq(variables['build'], 'true'))
@@ -71,7 +72,8 @@ steps:
7172
displayName: "Install PTVSD wheels"
7273
inputs:
7374
scriptSource: "filePath"
74-
scriptPath: "./build/ci/install_ptvsd.py"
75+
scriptPath: "./pythonFiles/install_ptvsd.py"
76+
arguments: "--ci"
7577
failOnStderr: true
7678
condition: and(succeeded(), eq(variables['build'], 'true'))
7779

‎build/ci/templates/test_phases.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ steps:
179179
python -m pip install -U pip
180180
python -m pip install --upgrade -r build/test-requirements.txt
181181
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt
182+
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python/old_ptvsd --no-cache-dir --implementation py --no-deps --upgrade 'ptvsd==4.3.2'
182183
displayName: 'pip install system test requirements'
183184
condition: and(succeeded(), eq(variables['NeedsPythonTestReqs'], 'true'))
184185

‎gulpfile.js‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ gulp.task('verifyBundle', async () => {
231231
gulp.task('prePublishBundle', gulp.series('webpack', 'renameSourceMaps'));
232232
gulp.task('prePublishNonBundle', gulp.series('checkNativeDependencies', 'check-datascience-dependencies', 'compile', 'compile-webviews'));
233233

234-
gulp.task('installPythonLibs', async () => {
234+
gulp.task('installPythonRequirements', async () => {
235235
const requirements = fs
236236
.readFileSync(path.join(__dirname, 'requirements.txt'), 'utf8')
237237
.split('\n')
@@ -254,6 +254,41 @@ gulp.task('installPythonLibs', async () => {
254254
);
255255
});
256256

257+
// Install new PTVSD wheels for python 3.7
258+
// See https://github.com/microsoft/vscode-python/issues/7136
259+
gulp.task('installPtvsdWheels', async () => {
260+
const args = ['./pythonFiles/install_ptvsd.py']
261+
const success = await spawnAsync(process.env.CI_PYTHON_PATH || 'python3', args)
262+
.then(() => true)
263+
.catch(ex => {
264+
console.error("Failed to install new PTVSD wheels using 'python3'", ex);
265+
return false;
266+
});
267+
if (!success) {
268+
console.info("Failed to install new PTVSD wheels using 'python3', attempting to install using 'python'");
269+
await spawnAsync('python', args.concat(requirement)).catch(ex => console.error("Failed to install PTVSD 5.0 wheels using 'python'", ex));
270+
}
271+
});
272+
273+
// Install the last stable version of old PTVSD (which includes a middle layer adapter and requires ptvsd_launcher.py)
274+
// until all users have migrated to the new debug adapter + new PTVSD (specified in requirements.txt)
275+
// See https://github.com/microsoft/vscode-python/issues/7136
276+
gulp.task('installOldPtvsd', async () => {
277+
const args = ['-m', 'pip', '--disable-pip-version-check', 'install', '-t', './pythonFiles/lib/python/old_ptvsd', '--no-cache-dir', '--implementation', 'py', '--no-deps', '--upgrade', 'ptvsd==4.3.2']
278+
const success = await spawnAsync(process.env.CI_PYTHON_PATH || 'python3', args)
279+
.then(() => true)
280+
.catch(ex => {
281+
console.error("Failed to install PTVSD using 'python3'", ex);
282+
return false;
283+
});
284+
if (!success) {
285+
console.info("Failed to install PTVSD using 'python3', attempting to install using 'python'");
286+
await spawnAsync('python', args.concat(requirement)).catch(ex => console.error("Failed to install PTVSD using 'python'", ex));
287+
}
288+
});
289+
290+
gulp.task('installPythonLibs', gulp.series('installPythonRequirements', 'installOldPtvsd', 'installPtvsdWheels'));
291+
257292
function uploadExtension(uploadBlobName) {
258293
const azure = require('gulp-azure-storage');
259294
const rename = require('gulp-rename');
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,27 @@
33
from zipfile import ZipFile
44
import json
55
import urllib.request
6+
import sys
67

7-
ROOT_DIRNAME = path.dirname(path.dirname(path.dirname(path.abspath(__file__))))
8+
ROOT_DIRNAME = path.dirname(path.dirname(path.abspath(__file__)))
9+
REQUIREMENTS_PATH = path.join(ROOT_DIRNAME, "requirements.txt")
810
PYTHONFILES_PATH = path.join(ROOT_DIRNAME, "pythonFiles", "lib", "python")
911
PYPI_PTVSD_URL = "https://pypi.org/pypi/ptvsd/json"
1012

11-
if __name__ == "__main__":
12-
# Remove this when the version of PTVSD in requirements.txt gets updated.
13-
# (and add code leveraging the packaging module to parse requirements.txt) in #7002
14-
ptvsd_version = "5.0.0a3"
13+
14+
def install_ptvsd():
15+
# If we are in CI use the packaging module installed in PYTHONFILES_PATH.
16+
if len(sys.argv) == 2 and sys.argv[1] == "--ci":
17+
sys.path.insert(0, PYTHONFILES_PATH)
18+
from packaging.requirements import Requirement
19+
20+
with open(REQUIREMENTS_PATH, "r", encoding="utf-8") as requirements:
21+
for line in requirements:
22+
package_requirement = Requirement(line)
23+
if package_requirement.name != "ptvsd":
24+
continue
25+
requirement_specifier = package_requirement.specifier
26+
ptvsd_version = next(requirement_specifier.__iter__()).version
1527

1628
# Response format: https://warehouse.readthedocs.io/api-reference/json/#project
1729
with urllib.request.urlopen(PYPI_PTVSD_URL) as response:
@@ -23,7 +35,7 @@
2335
# Download only if it's a 3.7 wheel.
2436
if not wheel_info["python_version"].endswith(("37", "3.7")):
2537
continue
26-
filename = wheel_info["filename"].rpartition(".")[0] # Trim the file extension
38+
filename = wheel_info["filename"].rpartition(".")[0] # Trim the file extension.
2739
ptvsd_path = path.join(PYTHONFILES_PATH, filename)
2840

2941
with urllib.request.urlopen(wheel_info["url"]) as wheel_response:
@@ -38,3 +50,7 @@
3850
# Flatten the folder structure.
3951
zip_info.filename = zip_info.filename.split(prefix)[-1]
4052
wheel.extract(zip_info, ptvsd_path)
53+
54+
55+
if __name__ == "__main__":
56+
install_ptvsd()

‎pythonFiles/ptvsd_launcher.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
# Load the debugger package
1414
try:
15-
ptvs_lib_path = os.path.join(os.path.dirname(__file__), 'lib', 'python')
15+
ptvsd_lib_path = os.path.join(os.path.dirname(__file__), 'lib', 'python', 'old_ptvsd')
1616
if useCustomPtvsd:
17-
sys.path.append(ptvs_lib_path)
17+
sys.path.append(ptvsd_lib_path)
1818
else:
19-
sys.path.insert(0, ptvs_lib_path)
19+
sys.path.insert(0, ptvsd_lib_path)
2020
try:
2121
import ptvsd
2222
from ptvsd.__main__ import main
@@ -37,7 +37,7 @@
3737
input()
3838
sys.exit(1)
3939
finally:
40-
if ptvs_lib_path:
41-
sys.path.remove(ptvs_lib_path)
40+
if ptvsd_lib_path:
41+
sys.path.remove(ptvsd_lib_path)
4242

4343
main(ptvsdArgs)

‎requirements.txt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
jedi==0.15.1
22
parso==0.5.1
33
isort==4.3.21
4-
ptvsd==4.3.2
4+
ptvsd==5.0.0a3
5+
pyparsing==2.4.0
6+
six==1.12.0
7+
packaging==19.1

0 commit comments

Comments
 (0)