Skip to content

Commit ef5e997

Browse files
Update noxfile and fix lint errors (#41)
1 parent 5554081 commit ef5e997

21 files changed

Lines changed: 884 additions & 375 deletions

.eslintrc.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55
"ecmaVersion": 6,
66
"sourceType": "module"
77
},
8-
"plugins": [
9-
"@typescript-eslint"
10-
],
8+
"plugins": ["@typescript-eslint", "prettier"],
119
"rules": {
10+
"prettier/prettier": "error",
1211
"@typescript-eslint/naming-convention": "warn",
1312
"@typescript-eslint/semi": "warn",
1413
"curly": "warn",
1514
"eqeqeq": "warn",
1615
"no-throw-literal": "warn",
1716
"semi": "off"
1817
},
19-
"ignorePatterns": [
20-
"out",
21-
"dist",
22-
"**/*.d.ts"
23-
]
18+
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
2419
}

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
# Install Python dependencies (including Ruff's native binary).
4949
- uses: actions/setup-python@v4
5050
with:
51-
python-version: "3.10"
51+
python-version: '3.10'
5252
- run: python -m pip install -t ./bundled/libs --implementation py --no-deps --upgrade -r ./requirements.txt
5353

5454
# Install Node.
@@ -73,7 +73,7 @@ jobs:
7373
publish:
7474
name: publish
7575
runs-on: ubuntu-latest
76-
needs: ["dist"]
76+
needs: ['dist']
7777
steps:
7878
- name: Install Nodejs
7979
uses: actions/setup-node@v3

bundled/tool/_debug_server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Licensed under the MIT License.
33
"""Debugging support for LSP."""
44

5+
from __future__ import annotations
6+
57
import os
68
import pathlib
79
import runpy

bundled/tool/jsonrpc.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Licensed under the MIT License.
33
"""Lightweight JSON-RPC over standard IO."""
44

5+
from __future__ import annotations
6+
57
import atexit
68
import io
79
import json
@@ -10,7 +12,7 @@
1012
import threading
1113
import uuid
1214
from concurrent.futures import ThreadPoolExecutor
13-
from typing import BinaryIO, Dict, Optional, Sequence, Union, cast
15+
from typing import BinaryIO, Sequence, cast
1416

1517
CONTENT_LENGTH = "Content-Length: "
1618
RUNNER_SCRIPT = str(pathlib.Path(__file__).parent / "runner.py")
@@ -48,7 +50,9 @@ def write(self, data):
4850
with self._lock:
4951
content = json.dumps(data)
5052
length = len(content.encode("utf-8"))
51-
self._writer.write(f"{CONTENT_LENGTH}{length}\r\n\r\n{content}".encode("utf-8"))
53+
self._writer.write(
54+
f"{CONTENT_LENGTH}{length}\r\n\r\n{content}".encode() # type: ignore
55+
)
5256
self._writer.flush()
5357

5458

@@ -116,16 +120,18 @@ def receive_data(self):
116120

117121
def create_json_rpc(readable: BinaryIO, writable: BinaryIO) -> JsonRpc:
118122
"""Creates JSON-RPC wrapper for the readable and writable streams."""
119-
return JsonRpc(cast(io.TextIOWrapper, readable), cast(io.TextIOWrapper, writable))
123+
return JsonRpc(
124+
cast(io.TextIOWrapper, readable), cast(io.TextIOWrapper, writable)
125+
)
120126

121127

122128
class ProcessManager:
123129
"""Manages sub-processes launched for running tools."""
124130

125131
def __init__(self):
126-
self._args: Dict[str, Sequence[str]] = {}
127-
self._processes: Dict[str, subprocess.Popen] = {}
128-
self._rpc: Dict[str, JsonRpc] = {}
132+
self._args: dict[str, Sequence[str]] = {}
133+
self._processes: dict[str, subprocess.Popen] = {}
134+
self._rpc: dict[str, JsonRpc] = {}
129135
self._lock = threading.Lock()
130136
self._thread_pool = ThreadPoolExecutor(10)
131137

@@ -139,7 +145,9 @@ def stop_all_processes(self):
139145
pass
140146
self._thread_pool.shutdown(wait=False)
141147

142-
def start_process(self, workspace: str, args: Sequence[str], cwd: str) -> None:
148+
def start_process(
149+
self, workspace: str, args: Sequence[str], cwd: str
150+
) -> None:
143151
"""Starts a process and establishes JSON-RPC communication over stdio."""
144152
proc = subprocess.Popen(
145153
args,
@@ -175,7 +183,7 @@ def get_json_rpc(self, workspace: str) -> JsonRpc:
175183
_process_manager = ProcessManager()
176184

177185

178-
def _get_json_rpc(workspace: str) -> Union[JsonRpc, None]:
186+
def _get_json_rpc(workspace: str) -> JsonRpc | None:
179187
try:
180188
return _process_manager.get_json_rpc(workspace)
181189
except StreamClosedException:
@@ -186,7 +194,7 @@ def _get_json_rpc(workspace: str) -> Union[JsonRpc, None]:
186194

187195
def get_or_start_json_rpc(
188196
workspace: str, interpreter: Sequence[str], cwd: str
189-
) -> Union[JsonRpc, None]:
197+
) -> JsonRpc | None:
190198
"""Gets an existing JSON-RPC connection or starts one and return it."""
191199
res = _get_json_rpc(workspace)
192200
if not res:
@@ -199,10 +207,10 @@ def get_or_start_json_rpc(
199207
class RpcRunResult:
200208
"""Object to hold result from running tool over RPC."""
201209

202-
def __init__(self, stdout: str, stderr: str, exception: Optional[str] = None):
210+
def __init__(self, stdout: str, stderr: str, exception: str | None = None):
203211
self.stdout: str = stdout
204212
self.stderr: str = stderr
205-
self.exception: Optional[str] = exception
213+
self.exception: str | None = exception
206214

207215

208216
def run_over_json_rpc(
@@ -212,10 +220,10 @@ def run_over_json_rpc(
212220
argv: Sequence[str],
213221
use_stdin: bool,
214222
cwd: str,
215-
source: str = None,
223+
source: str | None = None,
216224
) -> RpcRunResult:
217225
"""Uses JSON-RPC to execute a command."""
218-
rpc: Union[JsonRpc, None] = get_or_start_json_rpc(workspace, interpreter, cwd)
226+
rpc: JsonRpc | None = get_or_start_json_rpc(workspace, interpreter, cwd)
219227
if not rpc:
220228
raise Exception("Failed to run over JSON-RPC.")
221229

@@ -236,7 +244,9 @@ def run_over_json_rpc(
236244
data = rpc.receive_data()
237245

238246
if data["id"] != msg_id:
239-
return RpcRunResult("", f"Invalid result for request: {json.dumps(msg, indent=4)}")
247+
return RpcRunResult(
248+
"", f"Invalid result for request: {json.dumps(msg, indent=4)}"
249+
)
240250

241251
if "error" in data:
242252
if data.get("exception", False):

bundled/tool/runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Licensed under the MIT License.
33
"""Runner to use when running under a different interpreter."""
44

5+
from __future__ import annotations
6+
57
import os
68
import pathlib
79
import sys

0 commit comments

Comments
 (0)