Skip to content

Commit

Permalink
lsp: Pass user env through to the sphinx agent
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Jan 15, 2024
1 parent d95a599 commit 9d51bd5
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import typing

import aiosqlite
from pygls import IS_WIN
from pygls.client import JsonRPCClient
from pygls.protocol import JsonRPCProtocol

Expand Down Expand Up @@ -152,9 +151,7 @@ async def start(self, config: SphinxConfig):
command.extend([*config.python_command, "-m", "sphinx_agent"])
env = get_sphinx_env(config)

self.logger.debug("Sphinx agent env: %s", json.dumps(env, indent=2))
self.logger.debug("Starting sphinx agent: %s", " ".join(command))

await self.start_io(*command, env=env, cwd=config.cwd)

def _get_lsp_devtools_command(self) -> Optional[str]:
Expand Down Expand Up @@ -394,18 +391,15 @@ def _on_progress(params):

def get_sphinx_env(config: SphinxConfig) -> Dict[str, str]:
"""Return the set of environment variables to use with the Sphinx process."""
env = {"PYTHONPATH": os.pathsep.join([str(p) for p in config.python_path])}

passthrough = set(config.env_passthrough)
if IS_WIN and "SYSTEMROOT" not in passthrough:
passthrough.add("SYSTEMROOT")

for envname in passthrough:
value = os.environ.get(envname, None)
if value is not None:
if envname == "PYTHONPATH":
env["PYTHONPATH"] = f"{env['PYTHONPATH']}{os.pathsep}{value}"
else:
env[envname] = value

env = {
"PYTHONPATH": os.pathsep.join([str(p) for p in config.python_path]),
}
for envname, value in os.environ.items():
# Don't pass any vars we've explictly set.
if envname in env:
continue

env[envname] = value

return env

0 comments on commit 9d51bd5

Please sign in to comment.