Skip to content

feat: implement automatic python discovery for zero-config extension#19

Open
Mohamed-Sobea wants to merge 4 commits into
brian-team:mainfrom
Mohamed-Sobea:feat/auto-python-discovery
Open

feat: implement automatic python discovery for zero-config extension#19
Mohamed-Sobea wants to merge 4 commits into
brian-team:mainfrom
Mohamed-Sobea:feat/auto-python-discovery

Conversation

@Mohamed-Sobea
Copy link
Copy Markdown

@Mohamed-Sobea Mohamed-Sobea commented Apr 13, 2026

Overview

This PR implements automatic Python interpreter discovery as discussed in Issue #13. The goal was to remove the requirement for users to manually configure the python.interpreterpath setting.

Changes

  • Added ms-python.python as an extension dependency in package.json.
  • Refactored activate() to utilize the official Python Extension API for environment discovery.
  • Created a getPythonPath helper to dynamically fetch the active environment.

Testing

  • Verified that the extension successfully launches the Language Server in a clean environment without any manual settings.

Demo:
testOfZeroConfig

Closes #13

@mstimberg
Copy link
Copy Markdown
Member

Hi @Mohamed-Sobea Thanks for the work on this, and sorry for the late reply/review (I was down with a cold…). This looks basically good to me, although it isn't quite working for me, but that might also have to do with some semi-broken virtual environment setup on my machine. It would be great (also for testing) if this would be even more powerful though, i.e. it would automatically reload the language server when the activated python environment changes. I guess there is some kind of hook from the Python extension that we can use for that? Oh, and something rather trivial: the package.json still defines the (now unused) Brian.python.interpreterpath configuration option.

@Mohamed-Sobea
Copy link
Copy Markdown
Author

Mohamed-Sobea commented Apr 22, 2026

Hi @mstimberg, I hope you're feeling much better now.
and thanks for the review. auto restart idea makes total sense. I will work on that now.

@Mohamed-Sobea
Copy link
Copy Markdown
Author

Mohamed-Sobea commented Apr 24, 2026

Hi Marcel @mstimberg,

I’ve implemented the hook we discussed. I found the onDidChangeActiveEnvironmentPath event and used it to trigger the server restart.

Changes:

  • I removed getPythonPath function. Instead, I now fetch the Python API directly within activate() to set up the event listener and handle the discovery in one place.

  • I’ve deleted the Brian.python.interpreterpath from package.json as no longer needed.

About 'not working' issue:
While testing I faced an AttributeError (specifically about TextDocumentContentChangePartial in lsprotocol). It seems like a version conflict between the latest pygls and lsprotocol libraries. I’ll look for the server dependencies issue later.

this is a screenshot of the logs showing the extension successfully detecting and launching from a local virtual environment (stranger_test/.venv) and the AttributeError .
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Automatic Python Environment Discovery

2 participants