-
Notifications
You must be signed in to change notification settings - Fork 51
Platform-specific vsix #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
52db410
6c74285
f3a2e09
9aa1789
c97c370
8080291
5ce94a9
522acaa
f45e4fb
23c718c
cf22603
af0fc55
40f8f48
a1e6f0d
031893d
5bd40e6
05c7db9
45c5042
94452af
e42bdd3
7a41f9d
73cc6f9
4df0ca0
f5b654c
4e3726a
c7852dc
a84650b
5dd6b36
b233ac5
1669ea0
c9308ab
2b43b10
4f7e706
cf2ed03
5c95bd3
f64c727
1bac5b0
ebf13d8
95a257b
b436f0b
9070859
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"macOS": { | ||
"url": "https://files.pythonhosted.org/packages/bd/a3/5e37ce13c7dd850b72a52be544a058ed49606ebbbf8b95b2ba3c1db5620a/debugpy-1.7.0-cp311-cp311-macosx_11_0_universal2.whl", | ||
"hash": { | ||
"sha256": "538765a41198aa88cc089295b39c7322dd598f9ef1d52eaae12145c63bf9430a" | ||
} | ||
}, | ||
"win32": { | ||
"url": "https://files.pythonhosted.org/packages/52/59/3591e9f709b7ee4d3a926a8903a395669cd0e0279204a94b6acccf6ed6ee/debugpy-1.7.0-cp311-cp311-win32.whl", | ||
"hash": { | ||
"sha256": "18a69f8e142a716310dd0af6d7db08992aed99e2606108732efde101e7c65e2a" | ||
} | ||
}, | ||
"win64": { | ||
"url": "https://files.pythonhosted.org/packages/51/59/84ebd58d3e9de33a54ca8aa4532e03906e5458092dafe240264c2937a99b/debugpy-1.7.0-cp311-cp311-win_amd64.whl", | ||
"hash": { | ||
"sha256": "7515a5ba5ee9bfe956685909c5f28734c1cecd4ee813523363acfe3ca824883a" | ||
} | ||
}, | ||
"linux": { | ||
"url": "https://files.pythonhosted.org/packages/b4/fc/087324d46dab8e21e084ce2cf670fa7e524ab5e7691692438e4987bd3ecb/debugpy-1.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", | ||
"hash": { | ||
"sha256": "c7e8cf91f8f3f9b5fad844dd88427b85d398bda1e2a0cd65d5a21312fcbc0c6f" | ||
} | ||
}, | ||
"any": { | ||
"url": "https://files.pythonhosted.org/packages/39/2f/c8a8cfac6c7fa3d9e163a6bf46e6d27d027b7a1331028e99a6ef7fd3699d/debugpy-1.7.0-py2.py3-none-any.whl", | ||
"hash": { | ||
"sha256": "f6de2e6f24f62969e0f0ef682d78c98161c4dca29e9fb05df4d2989005005502" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
"""All the action we need during build""" | ||
import hashlib | ||
import io | ||
import json | ||
import os | ||
|
@@ -12,26 +13,6 @@ | |
import nox # pylint: disable=import-error | ||
|
||
|
||
def _install_bundle(session: nox.Session) -> None: | ||
session.install( | ||
"-t", | ||
"./bundled/libs", | ||
"--no-cache-dir", | ||
"--implementation", | ||
"py", | ||
"--no-deps", | ||
"--upgrade", | ||
"-r", | ||
"./requirements.txt", | ||
) | ||
session.install("packaging") | ||
_install_package(f"{os.getcwd()}/bundled/libs", "debugpy", "1.7.0") | ||
|
||
|
||
def _update_pip_packages(session: nox.Session) -> None: | ||
session.run("pip-compile", "--generate-hashes", "--upgrade", "./requirements.in") | ||
|
||
|
||
@nox.session() | ||
def lint(session: nox.Session) -> None: | ||
"""Runs linter and formatter checks on python files.""" | ||
|
@@ -58,81 +39,80 @@ def tests(session: nox.Session) -> None: | |
session.run("npm", "run", "test") | ||
|
||
|
||
def _get_package_data(package): | ||
json_uri = f"https://registry.npmjs.org/{package}" | ||
with url_lib.urlopen(json_uri) as response: | ||
return json.loads(response.read()) | ||
|
||
|
||
def _update_npm_packages(session: nox.Session) -> None: | ||
pinned = { | ||
"vscode-languageclient", | ||
"@types/vscode", | ||
"@types/node", | ||
} | ||
package_json_path = pathlib.Path(__file__).parent / "package.json" | ||
package_json = json.loads(package_json_path.read_text(encoding="utf-8")) | ||
|
||
for package in package_json["dependencies"]: | ||
if package not in pinned: | ||
data = _get_package_data(package) | ||
latest = "^" + data["dist-tags"]["latest"] | ||
package_json["dependencies"][package] = latest | ||
|
||
for package in package_json["devDependencies"]: | ||
if package not in pinned: | ||
data = _get_package_data(package) | ||
latest = "^" + data["dist-tags"]["latest"] | ||
package_json["devDependencies"][package] = latest | ||
|
||
# Ensure engine matches the package | ||
if ( | ||
package_json["engines"]["vscode"] | ||
!= package_json["devDependencies"]["@types/vscode"] | ||
): | ||
print( | ||
"Please check VS Code engine version and @types/vscode version in package.json." | ||
) | ||
@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") | ||
|
||
new_package_json = json.dumps(package_json, indent=4) | ||
# JSON dumps uses \n for line ending on all platforms by default | ||
if not new_package_json.endswith("\n"): | ||
new_package_json += "\n" | ||
package_json_path.write_text(new_package_json, encoding="utf-8") | ||
debugpy_info_json_path = pathlib.Path(__file__).parent / "debugpy_info.json" | ||
debugpy_info = json.loads(debugpy_info_json_path.read_text(encoding="utf-8")) | ||
|
||
target = os.environ.get("VSCETARGET", "") | ||
paulacamargo25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print("target:", target) | ||
if "darwin" in target: | ||
download_url(debugpy_info["macOS"]) | ||
elif "win32-ia32" == target: | ||
download_url(debugpy_info["win32"]) | ||
elif "win32-x64" == target: | ||
download_url(debugpy_info["win64"]) | ||
elif "linux-x64" == target: | ||
download_url(debugpy_info["linux"]) | ||
else: | ||
download_url(debugpy_info["any"]) | ||
|
||
session.run("npm", "audit", "fix", external=True) | ||
session.run("npm", "install", external=True) | ||
|
||
def download_url(value): | ||
with url_lib.urlopen(value["url"]) as response: | ||
data = response.read() | ||
hash_algorithm, hash_value = [ | ||
(key, value) for key, value in value["hash"].items() | ||
][0] | ||
if hashlib.new(hash_algorithm, data).hexdigest() != hash_value: | ||
raise ValueError("Failed hash verification for {}.".format(value["url"])) | ||
|
||
def _setup_template_environment(session: nox.Session) -> None: | ||
session.install("wheel", "pip-tools") | ||
_update_pip_packages(session) | ||
_install_bundle(session) | ||
print("Download: ", value["url"]) | ||
with zipfile.ZipFile(io.BytesIO(data), "r") as wheel: | ||
libs_dir = pathlib.Path.cwd() / "bundled" / "libs" | ||
for zip_info in wheel.infolist(): | ||
print("\t" + zip_info.filename) | ||
wheel.extract(zip_info.filename, libs_dir) | ||
|
||
|
||
@nox.session(python="3.7") | ||
def install_bundled_libs(session): | ||
"""Installs the libraries that will be bundled with the extension.""" | ||
session.install("wheel") | ||
_install_bundle(session) | ||
|
||
@nox.session() | ||
def update_build_number(session: nox.Session) -> None: | ||
"""Updates build number for the extension.""" | ||
if not len(session.posargs): | ||
session.log("No updates to package version") | ||
return | ||
|
||
@nox.session(python="3.7") | ||
def setup(session: nox.Session) -> None: | ||
"""Sets up the extension for development.""" | ||
_setup_template_environment(session) | ||
package_json_path = pathlib.Path(__file__).parent / "package.json" | ||
session.log(f"Reading package.json at: {package_json_path}") | ||
|
||
package_json = json.loads(package_json_path.read_text(encoding="utf-8")) | ||
|
||
@nox.session() | ||
def update_packages(session: nox.Session) -> None: | ||
"""Update pip and npm packages.""" | ||
session.install("wheel", "pip-tools") | ||
_update_pip_packages(session) | ||
_update_npm_packages(session) | ||
parts = re.split(r"\.|-", package_json["version"]) | ||
major, minor = parts[:2] | ||
|
||
version = f"{major}.{minor}.{session.posargs[0]}" | ||
version = version if len(parts) == 3 else f"{version}-{''.join(parts[3:])}" | ||
|
||
def _contains(s, parts=()): | ||
return any(p for p in parts if p in s) | ||
session.log(f"Updating version from {package_json['version']} to {version}") | ||
package_json["version"] = version | ||
package_json_path.write_text(json.dumps(package_json, indent=4), encoding="utf-8") | ||
|
||
|
||
def _get_pypi_package_data(package_name): | ||
|
@@ -143,59 +123,34 @@ def _get_pypi_package_data(package_name): | |
return json.loads(response.read()) | ||
|
||
|
||
def _get_urls(data, version): | ||
return list( | ||
r["url"] for r in data["releases"][version] if _contains(r["url"], ("cp37",)) | ||
) | ||
|
||
|
||
def _download_and_extract(root, url): | ||
if "manylinux" in url or "macosx" in url or "win_amd64" in url: | ||
root = os.getcwd() if root is None or root == "." else root | ||
print(url) | ||
with url_lib.urlopen(url) as response: | ||
data = response.read() | ||
with zipfile.ZipFile(io.BytesIO(data), "r") as wheel: | ||
for zip_info in wheel.infolist(): | ||
# Ignore dist info since we are merging multiple wheels | ||
if ".dist-info/" in zip_info.filename: | ||
continue | ||
print("\t" + zip_info.filename) | ||
wheel.extract(zip_info.filename, root) | ||
|
||
|
||
def _install_package(root, package_name, version="latest"): | ||
def _get_debugpy_info(version="latest", platform="none-any", cp="cp311"): | ||
from packaging.version import parse as version_parser | ||
|
||
data = _get_pypi_package_data(package_name) | ||
data = _get_pypi_package_data("debugpy") | ||
|
||
if version == "latest": | ||
use_version = max(data["releases"].keys(), key=version_parser) | ||
else: | ||
use_version = version | ||
|
||
for url in _get_urls(data, use_version): | ||
_download_and_extract(root, url) | ||
return list( | ||
{"url": r["url"], "hash": {"sha256": r["digests"]["sha256"]}} | ||
for r in data["releases"][use_version] | ||
if f"{cp}-{platform}" in r["url"] or f"py3-{platform}" in r["url"] | ||
)[0] | ||
|
||
|
||
@nox.session() | ||
def update_build_number(session: nox.Session) -> None: | ||
"""Updates build number for the extension.""" | ||
if len(session.posargs) == 0: | ||
session.log("No updates to package version") | ||
return | ||
|
||
package_json_path = pathlib.Path(__file__).parent / "package.json" | ||
session.log(f"Reading package.json at: {package_json_path}") | ||
|
||
package_json = json.loads(package_json_path.read_text(encoding="utf-8")) | ||
|
||
parts = re.split("\\.|-", package_json["version"]) | ||
major, minor = parts[:2] | ||
|
||
version = f"{major}.{minor}.{session.posargs[0]}" | ||
version = version if len(parts) == 3 else f"{version}-{''.join(parts[3:])}" | ||
|
||
session.log(f"Updating version from {package_json['version']} to {version}") | ||
package_json["version"] = version | ||
package_json_path.write_text(json.dumps(package_json, indent=4), encoding="utf-8") | ||
def create_debugpy_json(session: nox.Session, version="1.7.0", cp="cp311"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see where this is called (maybe it's meant to be manual), but is there a reason to hard-code the Debugpy and Python version? It seems like something that should be stored in the JSON file so that this file requires no changes when we upgrade to a new Debugpy version or Python version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really, i just wanted to have a default value just in case as , but i can remove this values. For other versions it would only be necessary to run the session with the parameters that we need through the terminal, this file will not need to be changed. |
||
platforms = [ | ||
("macOS", "macosx"), | ||
("win32", "win32"), | ||
("win64", "win_amd64"), | ||
("linux", "manylinux"), | ||
("any", "none-any"), | ||
] | ||
debugpy_info_json_path = pathlib.Path(__file__).parent / "debugpy_info.json" | ||
debugpy_info = {p: _get_debugpy_info(version, id, cp) for p, id in platforms} | ||
debugpy_info_json_path.write_text( | ||
json.dumps(debugpy_info, indent=4), encoding="utf-8" | ||
) |
Uh oh!
There was an error while loading. Please reload this page.