Skip to content

Commit cd10e38

Browse files
authored
Download get-pip.py during build (#21589)
1 parent d3b8985 commit cd10e38

11 files changed

Lines changed: 86 additions & 27102 deletions

File tree

.github/actions/build-vsix/action.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ runs:
2929
cache: 'pip'
3030
cache-dependency-path: |
3131
requirements.txt
32-
build/debugger-install-requirements.txt
32+
build/build-install-requirements.txt
3333
pythonFiles/jedilsp_requirements/requirements.txt
3434
3535
- name: Upgrade Pip
@@ -46,10 +46,11 @@ runs:
4646
with:
4747
options: '-t ./pythonFiles/lib/python --implementation py'
4848

49-
- name: Install debugpy
49+
- name: Install debugpy and get-pip
5050
run: |
51-
python -m pip --disable-pip-version-check install -r build/debugger-install-requirements.txt
51+
python -m pip --disable-pip-version-check install packaging
5252
python ./pythonFiles/install_debugpy.py
53+
python ./pythonFiles/download_get_pip.py
5354
shell: bash
5455

5556
- name: Install Jedi LSP

.github/workflows/build.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ jobs:
147147
with:
148148
python-version: ${{ matrix.python }}
149149

150+
- name: Download get-pip.py
151+
run: |
152+
python -m pip install wheel
153+
python -m pip install -r build/build-install-requirements.txt
154+
python ./pythonFiles/download_get_pip.py
155+
shell: bash
156+
150157
- name: Install debugpy
151158
run: |
152159
# We need to have debugpy so that tests relying on it keep passing, but we don't need install_debugpy's logic in the test phase.
@@ -172,7 +179,7 @@ jobs:
172179
- name: Install debugpy wheels (Python ${{ matrix.python }})
173180
run: |
174181
python -m pip install wheel
175-
python -m pip --disable-pip-version-check install -r build/debugger-install-requirements.txt
182+
python -m pip install -r build/build-install-requirements.txt
176183
python ./pythonFiles/install_debugpy.py
177184
shell: bash
178185
if: matrix.test-suite == 'debugger'

.github/workflows/pr-check.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ jobs:
127127
# We need to have debugpy so that tests relying on it keep passing, but we don't need install_debugpy's logic in the test phase.
128128
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy
129129
130+
- name: Download get-pip.py
131+
run: |
132+
python -m pip install wheel
133+
python -m pip install -r build/build-install-requirements.txt
134+
python ./pythonFiles/download_get_pip.py
135+
shell: bash
136+
130137
- name: Install base Python requirements
131138
uses: brettcannon/pip-secure-install@v1
132139
with:
@@ -147,7 +154,7 @@ jobs:
147154
- name: Install debugpy wheels (Python ${{ matrix.python }})
148155
run: |
149156
python -m pip install wheel
150-
python -m pip --disable-pip-version-check install -r build/debugger-install-requirements.txt
157+
python -m pip --disable-pip-version-check install -r build/build-install-requirements.txt
151158
python ./pythonFiles/install_debugpy.py
152159
shell: bash
153160
if: matrix.test-suite == 'debugger'

build/azure-pipeline.pre-release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ extends:
5353
displayName: Install wheel
5454

5555
- script: |
56-
python -m pip --disable-pip-version-check install -r build/debugger-install-requirements.txt
56+
python -m pip --disable-pip-version-check install -r build/build-install-requirements.txt
5757
python ./pythonFiles/install_debugpy.py
58-
displayName: Install debugpy
58+
python ./pythonFiles/download_get_pip.py
59+
displayName: Install debugpy and get-pip.py
5960
6061
- script: |
6162
python -m pip install --no-deps --require-hashes --only-binary :all: -t ./pythonFiles/lib/python --implementation py -r ./requirements.txt

build/azure-pipeline.stable.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ extends:
4848
displayName: Install wheel
4949

5050
- script: |
51-
python -m pip --disable-pip-version-check install -r build/debugger-install-requirements.txt
51+
python -m pip --disable-pip-version-check install -r build/build-install-requirements.txt
5252
python ./pythonFiles/install_debugpy.py
53-
displayName: Install debugpy
53+
python ./pythonFiles/download_get_pip.py
54+
displayName: Install debugpy and get-pip.py
5455
5556
- script: |
5657
python -m pip install --no-deps --require-hashes --only-binary :all: -t ./pythonFiles/lib/python --implementation py -r ./requirements.txt
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Requirements needed to run install_debugpy.py and download_get_pip.py
2+
packaging

build/debugger-install-requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

gulpfile.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ gulp.task('installDebugpy', async () => {
286286
'-t',
287287
'./pythonFiles/lib/temp',
288288
'-r',
289-
'./build/debugger-install-requirements.txt',
289+
'./build/build-install-requirements.txt',
290290
];
291291
await spawnAsync(process.env.CI_PYTHON_PATH || 'python', depsArgs, undefined, true)
292292
.then(() => true)
@@ -295,7 +295,7 @@ gulp.task('installDebugpy', async () => {
295295
return false;
296296
});
297297

298-
// Install new DEBUGPY with wheels for python 3.7
298+
// Install new DEBUGPY with wheels for python
299299
const wheelsArgs = ['./pythonFiles/install_debugpy.py'];
300300
const wheelsEnv = { PYTHONPATH: './pythonFiles/lib/temp' };
301301
await spawnAsync(process.env.CI_PYTHON_PATH || 'python', wheelsArgs, wheelsEnv, true)
@@ -305,6 +305,16 @@ gulp.task('installDebugpy', async () => {
305305
return false;
306306
});
307307

308+
// Download get-pip.py
309+
const getPipArgs = ['./pythonFiles/download_get_pip.py'];
310+
const getPipEnv = { PYTHONPATH: './pythonFiles/lib/temp' };
311+
await spawnAsync(process.env.CI_PYTHON_PATH || 'python', getPipArgs, getPipEnv, true)
312+
.then(() => true)
313+
.catch((ex) => {
314+
console.error("Failed to download get-pip wheels using 'python'", ex);
315+
return false;
316+
});
317+
308318
rmrf.sync('./pythonFiles/lib/temp');
309319
});
310320

pythonFiles/download_get_pip.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import json
5+
import os
6+
import pathlib
7+
import urllib.request as url_lib
8+
from packaging.version import parse as version_parser
9+
10+
EXTENSION_ROOT = pathlib.Path(__file__).parent.parent
11+
GET_PIP_DEST = EXTENSION_ROOT / "pythonFiles"
12+
PIP_PACKAGE = "pip"
13+
PIP_VERSION = "latest" # Can be "latest", or specific version "23.1.2"
14+
15+
16+
def _get_package_data():
17+
json_uri = "https://pypi.org/pypi/{0}/json".format(PIP_PACKAGE)
18+
# Response format: https://warehouse.readthedocs.io/api-reference/json/#project
19+
# Release metadata format: https://github.com/pypa/interoperability-peps/blob/master/pep-0426-core-metadata.rst
20+
with url_lib.urlopen(json_uri) as response:
21+
return json.loads(response.read())
22+
23+
24+
def _download_and_save(root, version):
25+
root = os.getcwd() if root is None or root == "." else root
26+
url = f"https://raw.githubusercontent.com/pypa/get-pip/{version}/public/get-pip.py"
27+
print(url)
28+
with url_lib.urlopen(url) as response:
29+
data = response.read()
30+
get_pip_file = pathlib.Path(root) / "get-pip.py"
31+
get_pip_file.write_bytes(data)
32+
33+
34+
def main(root):
35+
data = _get_package_data()
36+
37+
if PIP_VERSION == "latest":
38+
use_version = max(data["releases"].keys(), key=version_parser)
39+
else:
40+
use_version = PIP_VERSION
41+
42+
_download_and_save(root, use_version)
43+
44+
45+
if __name__ == "__main__":
46+
main(GET_PIP_DEST)

0 commit comments

Comments
 (0)