Skip to content

Commit ec9e135

Browse files
Platform-specific vsix (microsoft#89)
* Update nox file and pre release * update args * update value * see params * echo vars * fix args * fix args * Fix error obj to string * fix command line error * update args * update how access values * Add args * Send arguments * tried ith arguments * update value * remove args extra * update run * send as env * add to see other values * update env variables * use VSCETARGET * fix variable * Fix macOs error * Fix lint in nox file * Fix nox hash comparison * Fix default value * Remove unnecessary code * Update platform url and debugpy version * Fix dict key name * Remove vsix for all platforms * Fix pr comments * fix download function * fix hash code * Read from json pypypackage * add json file and session that creates it * Reformat nox file * resolve comments * fix lint error * update pipeline * fix build error * dont hardcode the hash
1 parent 224bc8f commit ec9e135

File tree

3 files changed

+147
-141
lines changed

3 files changed

+147
-141
lines changed

build/azure-pipeline.pre-release.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@ extends:
2828
template: azure-pipelines/extension/pre-release.yml@templates
2929
parameters:
3030
l10nSourcePaths: ./src
31+
buildPlatforms:
32+
- name: Linux
33+
packageArch: arm64
34+
vsceTarget: linux-arm64
35+
- name: Linux
36+
packageArch: arm
37+
vsceTarget: linux-armhf
38+
- name: Linux
39+
packageArch: x64
40+
vsceTarget: linux-x64
41+
- name: MacOS
42+
packageArch: arm64
43+
vsceTarget: darwin-arm64
44+
- name: MacOS
45+
packageArch: x64
46+
vsceTarget: darwin-x64
47+
- name: Windows
48+
packageArch: arm
49+
vsceTarget: win32-arm64
50+
- name: Windows
51+
packageArch: ia32
52+
vsceTarget: win32-ia32
53+
- name: Windows
54+
packageArch: x64
55+
vsceTarget: win32-x64
56+
3157
buildSteps:
3258
- task: NodeTool@0
3359
inputs:
@@ -47,14 +73,14 @@ extends:
4773
- script: python -m pip install -U pip
4874
displayName: Upgrade pip
4975

50-
- script: python -m pip install wheel
51-
displayName: Install wheel
52-
53-
- script: python -m pip install nox
54-
displayName: Install wheel
76+
- script: python -m pip install wheel nox
77+
displayName: Install wheel and nox
5578

56-
- script: python -m nox --session install_old_bundled_libs
79+
# update according packageArch
80+
- script: python -m nox --session install_bundled_libs
5781
displayName: Install Python dependencies
82+
env:
83+
VSCETARGET: ${{ variables.VSCETARGET }}
5884

5985
- script: python ./build/update_ext_version.py --for-publishing
6086
displayName: Update build number

debugpy_info.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"macOS": {
3+
"url": "https://files.pythonhosted.org/packages/bd/a3/5e37ce13c7dd850b72a52be544a058ed49606ebbbf8b95b2ba3c1db5620a/debugpy-1.7.0-cp311-cp311-macosx_11_0_universal2.whl",
4+
"hash": {
5+
"sha256": "538765a41198aa88cc089295b39c7322dd598f9ef1d52eaae12145c63bf9430a"
6+
}
7+
},
8+
"win32": {
9+
"url": "https://files.pythonhosted.org/packages/52/59/3591e9f709b7ee4d3a926a8903a395669cd0e0279204a94b6acccf6ed6ee/debugpy-1.7.0-cp311-cp311-win32.whl",
10+
"hash": {
11+
"sha256": "18a69f8e142a716310dd0af6d7db08992aed99e2606108732efde101e7c65e2a"
12+
}
13+
},
14+
"win64": {
15+
"url": "https://files.pythonhosted.org/packages/51/59/84ebd58d3e9de33a54ca8aa4532e03906e5458092dafe240264c2937a99b/debugpy-1.7.0-cp311-cp311-win_amd64.whl",
16+
"hash": {
17+
"sha256": "7515a5ba5ee9bfe956685909c5f28734c1cecd4ee813523363acfe3ca824883a"
18+
}
19+
},
20+
"linux": {
21+
"url": "https://files.pythonhosted.org/packages/b4/fc/087324d46dab8e21e084ce2cf670fa7e524ab5e7691692438e4987bd3ecb/debugpy-1.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
22+
"hash": {
23+
"sha256": "c7e8cf91f8f3f9b5fad844dd88427b85d398bda1e2a0cd65d5a21312fcbc0c6f"
24+
}
25+
},
26+
"any": {
27+
"url": "https://files.pythonhosted.org/packages/39/2f/c8a8cfac6c7fa3d9e163a6bf46e6d27d027b7a1331028e99a6ef7fd3699d/debugpy-1.7.0-py2.py3-none-any.whl",
28+
"hash": {
29+
"sha256": "f6de2e6f24f62969e0f0ef682d78c98161c4dca29e9fb05df4d2989005005502"
30+
}
31+
}
32+
}

noxfile.py

Lines changed: 83 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33
"""All the action we need during build"""
4+
import hashlib
45
import io
56
import json
67
import os
@@ -12,26 +13,6 @@
1213
import nox # pylint: disable=import-error
1314

1415

15-
def _install_bundle(session: nox.Session, version="latest") -> None:
16-
session.install(
17-
"-t",
18-
"./bundled/libs",
19-
"--no-cache-dir",
20-
"--implementation",
21-
"py",
22-
"--no-deps",
23-
"--upgrade",
24-
"-r",
25-
"./requirements.txt",
26-
)
27-
session.install("packaging")
28-
_install_package(f"{os.getcwd()}/bundled/libs", "debugpy", "1.7.0")
29-
30-
31-
def _update_pip_packages(session: nox.Session) -> None:
32-
session.run("pip-compile", "--generate-hashes", "--upgrade", "./requirements.in")
33-
34-
3516
@nox.session()
3617
def lint(session: nox.Session) -> None:
3718
"""Runs linter and formatter checks on python files."""
@@ -58,88 +39,80 @@ def tests(session: nox.Session) -> None:
5839
session.run("npm", "run", "test")
5940

6041

61-
def _get_package_data(package):
62-
json_uri = f"https://registry.npmjs.org/{package}"
63-
with url_lib.urlopen(json_uri) as response:
64-
return json.loads(response.read())
65-
66-
67-
def _update_npm_packages(session: nox.Session) -> None:
68-
pinned = {
69-
"vscode-languageclient",
70-
"@types/vscode",
71-
"@types/node",
72-
}
73-
package_json_path = pathlib.Path(__file__).parent / "package.json"
74-
package_json = json.loads(package_json_path.read_text(encoding="utf-8"))
75-
76-
for package in package_json["dependencies"]:
77-
if package not in pinned:
78-
data = _get_package_data(package)
79-
latest = "^" + data["dist-tags"]["latest"]
80-
package_json["dependencies"][package] = latest
81-
82-
for package in package_json["devDependencies"]:
83-
if package not in pinned:
84-
data = _get_package_data(package)
85-
latest = "^" + data["dist-tags"]["latest"]
86-
package_json["devDependencies"][package] = latest
87-
88-
# Ensure engine matches the package
89-
if (
90-
package_json["engines"]["vscode"]
91-
!= package_json["devDependencies"]["@types/vscode"]
92-
):
93-
print(
94-
"Please check VS Code engine version and @types/vscode version in package.json."
95-
)
96-
97-
new_package_json = json.dumps(package_json, indent=4)
98-
# JSON dumps uses \n for line ending on all platforms by default
99-
if not new_package_json.endswith("\n"):
100-
new_package_json += "\n"
101-
package_json_path.write_text(new_package_json, encoding="utf-8")
102-
103-
session.run("npm", "audit", "fix", external=True)
104-
session.run("npm", "install", external=True)
105-
106-
107-
def _setup_template_environment(session: nox.Session) -> None:
108-
session.install("wheel", "pip-tools")
109-
_update_pip_packages(session)
110-
_install_bundle(session)
111-
112-
113-
@nox.session(python="3.7")
42+
@nox.session()
11443
def install_bundled_libs(session):
11544
"""Installs the libraries that will be bundled with the extension."""
11645
session.install("wheel")
117-
_install_bundle(session)
46+
session.install(
47+
"-t",
48+
"./bundled/libs",
49+
"--no-cache-dir",
50+
"--implementation",
51+
"py",
52+
"--no-deps",
53+
"--require-hashes",
54+
"--only-binary",
55+
":all:",
56+
"-r",
57+
"./requirements.txt",
58+
)
59+
session.install("packaging")
11860

61+
debugpy_info_json_path = pathlib.Path(__file__).parent / "debugpy_info.json"
62+
debugpy_info = json.loads(debugpy_info_json_path.read_text(encoding="utf-8"))
63+
64+
target = os.environ.get("VSCETARGET", "")
65+
print("target:", target)
66+
if "darwin" in target:
67+
download_url(debugpy_info["macOS"])
68+
elif "win32-ia32" == target:
69+
download_url(debugpy_info["win32"])
70+
elif "win32-x64" == target:
71+
download_url(debugpy_info["win64"])
72+
elif "linux-x64" == target:
73+
download_url(debugpy_info["linux"])
74+
else:
75+
download_url(debugpy_info["any"])
11976

120-
@nox.session(python="3.6")
121-
def install_old_bundled_libs(session):
122-
"""Installs the libraries that will be bundled with the extension."""
123-
session.install("wheel")
124-
_install_bundle(session, "1.5.1")
12577

78+
def download_url(value):
79+
with url_lib.urlopen(value["url"]) as response:
80+
data = response.read()
81+
hash_algorithm, hash_value = [
82+
(key, value) for key, value in value["hash"].items()
83+
][0]
84+
if hashlib.new(hash_algorithm, data).hexdigest() != hash_value:
85+
raise ValueError("Failed hash verification for {}.".format(value["url"]))
12686

127-
@nox.session(python="3.7")
128-
def setup(session: nox.Session) -> None:
129-
"""Sets up the extension for development."""
130-
_setup_template_environment(session)
87+
print("Download: ", value["url"])
88+
with zipfile.ZipFile(io.BytesIO(data), "r") as wheel:
89+
libs_dir = pathlib.Path.cwd() / "bundled" / "libs"
90+
for zip_info in wheel.infolist():
91+
print("\t" + zip_info.filename)
92+
wheel.extract(zip_info.filename, libs_dir)
13193

13294

13395
@nox.session()
134-
def update_packages(session: nox.Session) -> None:
135-
"""Update pip and npm packages."""
136-
session.install("wheel", "pip-tools")
137-
_update_pip_packages(session)
138-
_update_npm_packages(session)
96+
def update_build_number(session: nox.Session) -> None:
97+
"""Updates build number for the extension."""
98+
if not len(session.posargs):
99+
session.log("No updates to package version")
100+
return
101+
102+
package_json_path = pathlib.Path(__file__).parent / "package.json"
103+
session.log(f"Reading package.json at: {package_json_path}")
104+
105+
package_json = json.loads(package_json_path.read_text(encoding="utf-8"))
106+
107+
parts = re.split(r"\.|-", package_json["version"])
108+
major, minor = parts[:2]
139109

110+
version = f"{major}.{minor}.{session.posargs[0]}"
111+
version = version if len(parts) == 3 else f"{version}-{''.join(parts[3:])}"
140112

141-
def _contains(s, parts=()):
142-
return any(p for p in parts if p in s)
113+
session.log(f"Updating version from {package_json['version']} to {version}")
114+
package_json["version"] = version
115+
package_json_path.write_text(json.dumps(package_json, indent=4), encoding="utf-8")
143116

144117

145118
def _get_pypi_package_data(package_name):
@@ -150,59 +123,34 @@ def _get_pypi_package_data(package_name):
150123
return json.loads(response.read())
151124

152125

153-
def _get_urls(data, version):
154-
return list(
155-
r["url"] for r in data["releases"][version] if _contains(r["url"], ("cp37",))
156-
)
157-
158-
159-
def _download_and_extract(root, url):
160-
if "manylinux" in url or "macosx" in url or "win_amd64" in url:
161-
root = os.getcwd() if root is None or root == "." else root
162-
print(url)
163-
with url_lib.urlopen(url) as response:
164-
data = response.read()
165-
with zipfile.ZipFile(io.BytesIO(data), "r") as wheel:
166-
for zip_info in wheel.infolist():
167-
# Ignore dist info since we are merging multiple wheels
168-
if ".dist-info/" in zip_info.filename:
169-
continue
170-
print("\t" + zip_info.filename)
171-
wheel.extract(zip_info.filename, root)
172-
173-
174-
def _install_package(root, package_name, version="latest"):
126+
def _get_debugpy_info(version="latest", platform="none-any", cp="cp311"):
175127
from packaging.version import parse as version_parser
176128

177-
data = _get_pypi_package_data(package_name)
129+
data = _get_pypi_package_data("debugpy")
178130

179131
if version == "latest":
180132
use_version = max(data["releases"].keys(), key=version_parser)
181133
else:
182134
use_version = version
183135

184-
for url in _get_urls(data, use_version):
185-
_download_and_extract(root, url)
136+
return list(
137+
{"url": r["url"], "hash": {"sha256": r["digests"]["sha256"]}}
138+
for r in data["releases"][use_version]
139+
if f"{cp}-{platform}" in r["url"] or f"py3-{platform}" in r["url"]
140+
)[0]
186141

187142

188143
@nox.session()
189-
def update_build_number(session: nox.Session) -> None:
190-
"""Updates build number for the extension."""
191-
if len(session.posargs) == 0:
192-
session.log("No updates to package version")
193-
return
194-
195-
package_json_path = pathlib.Path(__file__).parent / "package.json"
196-
session.log(f"Reading package.json at: {package_json_path}")
197-
198-
package_json = json.loads(package_json_path.read_text(encoding="utf-8"))
199-
200-
parts = re.split("\\.|-", package_json["version"])
201-
major, minor = parts[:2]
202-
203-
version = f"{major}.{minor}.{session.posargs[0]}"
204-
version = version if len(parts) == 3 else f"{version}-{''.join(parts[3:])}"
205-
206-
session.log(f"Updating version from {package_json['version']} to {version}")
207-
package_json["version"] = version
208-
package_json_path.write_text(json.dumps(package_json, indent=4), encoding="utf-8")
144+
def create_debugpy_json(session: nox.Session, version="1.7.0", cp="cp311"):
145+
platforms = [
146+
("macOS", "macosx"),
147+
("win32", "win32"),
148+
("win64", "win_amd64"),
149+
("linux", "manylinux"),
150+
("any", "none-any"),
151+
]
152+
debugpy_info_json_path = pathlib.Path(__file__).parent / "debugpy_info.json"
153+
debugpy_info = {p: _get_debugpy_info(version, id, cp) for p, id in platforms}
154+
debugpy_info_json_path.write_text(
155+
json.dumps(debugpy_info, indent=4), encoding="utf-8"
156+
)

0 commit comments

Comments
 (0)