Skip to content

Commit 007b6ee

Browse files
fix lint
1 parent 29239e6 commit 007b6ee

File tree

3 files changed

+55
-48
lines changed

3 files changed

+55
-48
lines changed

.flake8

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[flake8]
2+
ignore = W,BLK,
3+
E24,E121,E123,E125,E126,E221,E226,E266,E704,
4+
E265,E722,E501,E731,E306,E401,E302,E222,E303,
5+
E402,E305,E261,E262,E203
6+
exclude =
7+
__pycache__,
8+
.eggs,
9+
.git,
10+
.tox,
11+
.nox,
12+
build,
13+
dist,
14+
src/test/python_tests/test_data

.vscode/settings.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66
},
77
"search.exclude": {
88
"out": true, // set this to false to include "out" folder in search results
9-
"dist": true // set this to false to include "dist" folder in search results
9+
"dist": true, // set this to false to include "dist" folder in search results
10+
".venv": true,
11+
".nox": true
1012
},
1113
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
12-
"typescript.tsc.autoDetect": "off"
13-
}
14+
"typescript.tsc.autoDetect": "off",
15+
"python.testing.pytestArgs": ["src/test/python_tests"],
16+
"python.testing.unittestEnabled": false,
17+
"python.testing.pytestEnabled": true,
18+
"python.testing.cwd": "${workspaceFolder}",
19+
"python.linting.flake8Enabled": true,
20+
"python.formatting.provider": "black",
21+
"editor.formatOnSave": true
22+
}

noxfile.py

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33
"""All the action we need during build"""
4+
import io
45
import json
56
import os
6-
import io
77
import pathlib
88
import re
99
import urllib.request as url_lib
1010
import zipfile
11-
from typing import List
1211

13-
import nox # pylint: disable=import-error
12+
import nox # pylint: disable=import-error
13+
1414

1515
def _install_bundle(session: nox.Session) -> None:
1616
session.install(
@@ -28,15 +28,6 @@ def _install_bundle(session: nox.Session) -> None:
2828
_install_package(f"{os.getcwd()}/bundled/libs", "debugpy")
2929

3030

31-
def _check_files(names: List[str]) -> None:
32-
root_dir = pathlib.Path(__file__).parent
33-
for name in names:
34-
file_path = root_dir / name
35-
lines: List[str] = file_path.read_text().splitlines()
36-
if any(line for line in lines if line.startswith("# TODO:")):
37-
raise Exception(f"Please update {os.fspath(file_path)}.")
38-
39-
4031
def _update_pip_packages(session: nox.Session) -> None:
4132
session.run("pip-compile", "--generate-hashes", "--upgrade", "./requirements.in")
4233
session.run(
@@ -46,6 +37,26 @@ def _update_pip_packages(session: nox.Session) -> None:
4637
"./src/test/python_tests/requirements.in",
4738
)
4839

40+
41+
@nox.session()
42+
def lint(session: nox.Session) -> None:
43+
"""Runs linter and formatter checks on python files."""
44+
45+
session.install("flake8")
46+
session.run("flake8", "noxfile.py")
47+
48+
# check formatting using black
49+
session.install("black")
50+
session.run("black", "--check", "noxfile.py")
51+
52+
# check import sorting using isort
53+
session.install("isort")
54+
session.run("isort", "--check", "noxfile.py")
55+
56+
# check typescript code
57+
session.run("npm", "run", "lint", external=True)
58+
59+
4960
@nox.session()
5061
def tests(session: nox.Session) -> None:
5162
"""Runs all the tests for the extension."""
@@ -117,56 +128,27 @@ def setup(session: nox.Session) -> None:
117128
"""Sets up the extension for development."""
118129
_setup_template_environment(session)
119130

120-
@nox.session()
121-
def validate_readme(session: nox.Session) -> None:
122-
"""Ensures the linter version in 'requirements.txt' matches 'readme.md'."""
123-
requirements_file = pathlib.Path(__file__).parent / "requirements.txt"
124-
readme_file = pathlib.Path(__file__).parent / "README.md"
125-
126-
lines = requirements_file.read_text(encoding="utf-8").splitlines(keepends=False)
127-
module = _get_module_name()
128-
linter_ver = list(line for line in lines if line.startswith(module))[0]
129-
name, version = linter_ver.split(" ")[0].split("==")
130-
131-
session.log(f"Looking for {name}={version} in README.md")
132-
content = readme_file.read_text(encoding="utf-8")
133-
if f"{name}={version}" not in content:
134-
raise ValueError(f"Linter info {name}={version} was not found in README.md.")
135-
session.log(f"FOUND {name}={version} in README.md")
136-
137-
138-
def _update_readme() -> None:
139-
requirements_file = pathlib.Path(__file__).parent / "requirements.txt"
140-
lines = requirements_file.read_text(encoding="utf-8").splitlines(keepends=False)
141-
module = _get_module_name()
142-
linter_ver = list(line for line in lines if line.startswith(module))[0]
143-
_, version = linter_ver.split(" ")[0].split("==")
144-
145-
readme_file = pathlib.Path(__file__).parent / "README.md"
146-
content = readme_file.read_text(encoding="utf-8")
147-
regex = r"\`([a-zA-Z0-9]+)=([0-9]+\.[0-9]+\.[0-9]+)\`"
148-
result = re.sub(regex, f"`{module}={version}`", content, 0, re.MULTILINE)
149-
content = readme_file.write_text(result, encoding="utf-8")
150-
151131

152132
@nox.session()
153133
def update_packages(session: nox.Session) -> None:
154134
"""Update pip and npm packages."""
155135
session.install("wheel", "pip-tools")
156136
_update_pip_packages(session)
157137
_update_npm_packages(session)
158-
_update_readme()
138+
159139

160140
def _contains(s, parts=()):
161141
return any(p for p in parts if p in s)
162142

143+
163144
def _get_pypi_package_data(package_name):
164145
json_uri = "https://pypi.org/pypi/{0}/json".format(package_name)
165146
# Response format: https://warehouse.readthedocs.io/api-reference/json/#project
166147
# Release metadata format: https://github.com/pypa/interoperability-peps/blob/master/pep-0426-core-metadata.rst
167148
with url_lib.urlopen(json_uri) as response:
168149
return json.loads(response.read())
169150

151+
170152
def _get_urls(data, version):
171153
return list(
172154
r["url"] for r in data["releases"][version] if _contains(r["url"], ("cp37",))
@@ -185,6 +167,7 @@ def _download_and_extract(root, url, version):
185167
print("\t" + zip_info.filename)
186168
wheel.extract(zip_info.filename, root)
187169

170+
188171
def _install_package(root, package_name, version="latest"):
189172
from packaging.version import parse as version_parser
190173

@@ -198,6 +181,7 @@ def _install_package(root, package_name, version="latest"):
198181
for url in _get_urls(data, use_version):
199182
_download_and_extract(root, url, use_version)
200183

184+
201185
@nox.session()
202186
def update_build_number(session: nox.Session) -> None:
203187
"""Updates build number for the extension."""
@@ -218,4 +202,4 @@ def update_build_number(session: nox.Session) -> None:
218202

219203
session.log(f"Updating version from {package_json['version']} to {version}")
220204
package_json["version"] = version
221-
package_json_path.write_text(json.dumps(package_json, indent=4), encoding="utf-8")
205+
package_json_path.write_text(json.dumps(package_json, indent=4), encoding="utf-8")

0 commit comments

Comments
 (0)