-
Notifications
You must be signed in to change notification settings - Fork 1
/
noxfile.py
152 lines (123 loc) · 4.32 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""All the action we need during build"""
from __future__ import annotations
import json
import os
import pathlib
import urllib.request as url_lib
import nox
def _install_bundle(session: nox.Session) -> None:
session.install(
"-v",
"-t",
"./bundled/libs",
"--no-cache-dir",
"--implementation",
"py",
"--no-deps",
"--upgrade",
"-r",
"./requirements.txt",
)
def _check_files(names: list[str]) -> None:
root_dir = pathlib.Path(__file__).parent
for name in names:
file_path = root_dir / name
lines: list[str] = file_path.read_text().splitlines()
if any(line for line in lines if line.startswith("# TODO:")):
raise Exception(f"Please update {os.fspath(file_path)}.")
def _update_pip_packages(session: nox.Session) -> None:
session.run(
"pip-compile",
"--generate-hashes",
"--resolver=backtracking",
"--upgrade",
"./requirements.in",
)
session.run(
"pip-compile",
"--generate-hashes",
"--resolver=backtracking",
"--upgrade",
"./src/test/python_tests/requirements.in",
)
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."
)
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")
session.run("npm", "install", external=True)
def _setup_template_environment(session: nox.Session) -> None:
session.install("wheel", "pip-tools")
session.run(
"pip-compile",
"--generate-hashes",
"--resolver=backtracking",
"--upgrade",
"./requirements.in",
)
session.run(
"pip-compile",
"--generate-hashes",
"--resolver=backtracking",
"--upgrade",
"./src/test/python_tests/requirements.in",
)
_install_bundle(session)
@nox.session()
def setup(session: nox.Session) -> None:
"""Sets up the template for development."""
_setup_template_environment(session)
@nox.session()
def tests(session: nox.Session) -> None:
"""Runs all the tests for the extension."""
session.install("-r", "src/test/python_tests/requirements.txt")
session.run("pytest", "-svv", "src/test/python_tests")
@nox.session()
def lint(session: nox.Session) -> None:
# check typescript code
session.run("npm", "run", "lint", external=True)
@nox.session()
def build_package(session: nox.Session) -> None:
"""Builds VSIX package for publishing."""
_check_files(["README.md", "LICENSE", "SECURITY.md", "SUPPORT.md"])
_setup_template_environment(session)
session.run("npm", "install", external=True)
session.run("npm", "run", "vsce-package", external=True)
@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)