|
4 | 4 |
|
5 | 5 | import asyncio |
6 | 6 | import logging |
7 | | -import os |
8 | 7 | import pathlib |
9 | | -import subprocess |
10 | 8 | import sys |
11 | 9 | import typing |
12 | 10 | from uuid import uuid4 |
@@ -80,10 +78,10 @@ def __init__( |
80 | 78 | self._events = EventSource(self.logger) |
81 | 79 | """The sphinx client can emit events.""" |
82 | 80 |
|
83 | | - self._startup_task: asyncio.Task | None = None |
| 81 | + self._startup_task: asyncio.Task[Any] | None = None |
84 | 82 | """The startup task.""" |
85 | 83 |
|
86 | | - self._stderr_forwarder: asyncio.Task | None = None |
| 84 | + self._stderr_forwarder: asyncio.Task[Any] | None = None |
87 | 85 | """A task that forwards the server's stderr to the test process.""" |
88 | 86 |
|
89 | 87 | def __repr__(self): |
@@ -204,11 +202,10 @@ async def start(self) -> SphinxClient: |
204 | 202 |
|
205 | 203 | try: |
206 | 204 | self._set_state(ClientState.Starting) |
207 | | - command = get_start_command(self.config, self.logger) |
208 | | - env = get_sphinx_env(self.config) |
| 205 | + sphinx = self.config.sphinx_command |
209 | 206 |
|
210 | | - self.logger.debug("Starting sphinx agent: %s", " ".join(command)) |
211 | | - await self.start_io(*command, env=env, cwd=self.config.cwd) |
| 207 | + self.logger.debug("Python command: %r", sphinx.command) |
| 208 | + await self.start_io(*sphinx.command, env=sphinx.env, cwd=sphinx.cwd) |
212 | 209 |
|
213 | 210 | params = types.CreateApplicationParams( |
214 | 211 | command=self.config.build_command, |
@@ -337,49 +334,3 @@ def _on_progress(params): |
337 | 334 | logger.info("%s", params) |
338 | 335 |
|
339 | 336 | return client |
340 | | - |
341 | | - |
342 | | -def get_sphinx_env(config: SphinxConfig) -> dict[str, str]: |
343 | | - """Return the set of environment variables to use with the Sphinx process.""" |
344 | | - |
345 | | - env = { |
346 | | - "PYTHONUNBUFFERED": "1", |
347 | | - "PYTHONPATH": os.pathsep.join([str(p) for p in config.python_path]), |
348 | | - } |
349 | | - for envname, value in os.environ.items(): |
350 | | - # Don't pass any vars we've explictly set. |
351 | | - if envname in env: |
352 | | - continue |
353 | | - |
354 | | - env[envname] = value |
355 | | - |
356 | | - return env |
357 | | - |
358 | | - |
359 | | -def get_start_command(config: SphinxConfig, logger: logging.Logger): |
360 | | - """Return the command to use to start the sphinx agent.""" |
361 | | - |
362 | | - command = [] |
363 | | - |
364 | | - if len(config.python_command) == 0: |
365 | | - raise ValueError("No python environment configured") |
366 | | - |
367 | | - if config.enable_dev_tools: |
368 | | - # Assumes that the user has `lsp-devtools` available on their PATH |
369 | | - # TODO: Windows support |
370 | | - result = subprocess.run( |
371 | | - ["command", "-v", "lsp-devtools"], # noqa: S607 |
372 | | - capture_output=True, |
373 | | - check=False, |
374 | | - ) |
375 | | - |
376 | | - if result.returncode == 0: |
377 | | - lsp_devtools = result.stdout.decode("utf8").strip() |
378 | | - command.extend([lsp_devtools, "agent", "--"]) |
379 | | - |
380 | | - else: |
381 | | - stderr = result.stderr.decode("utf8").strip() |
382 | | - logger.debug("Unable to locate lsp-devtools command\n%s", stderr) |
383 | | - |
384 | | - command.extend([*config.python_command, "-m", "sphinx_agent"]) |
385 | | - return command |
0 commit comments