Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python.interpreters.include and python.interpreters.exclude settings #6398

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

sharon-wang
Copy link
Member

@sharon-wang sharon-wang commented Feb 19, 2025

Summary

Settings UI

image

Settings JSON

    "python.interpreters.include": [
        "/Users/sashimi/scratch",
        "a/relative/path",
        "/this/is/a/bogus/path"
    ],
    "python.interpreters.exclude": [
        "/usr/bin/python3",
        "/opt/homebrew",
        "/usr/local/bin"
    ]

Python Language Pack Output

Some log prefixes/messages to search for:

  • pythonRuntimeDiscoverer: to find out if any runtimes were filtered out during discovery
  • shouldIncludeInterpreter: whether or not the interpreter will be included based on the user settings
  • Not registering runtime ${extraData.pythonPath} as it is excluded via user settings.: if the runtime is not getting registered because the user excluded it
  • getAdditionalEnvDirs: native python finder -- list all the additional directories being searched, such as the user-included dirs

Release Notes

New Features

Bug Fixes

  • N/A

QA Notes

  • Please verify these options using both the JS and Native locators. Toggle between the locators by updating setting python.locator.
  • Positron will need to be restarted upon changing the python.interpreters.include/python.interpreters.exclude settings so that discovery can re-run with the settings applied
  • If an interpreter path is captured in both options, it will be included
  • If a user has a python install they want to include at path /1/2/3/4/5/3.10.4/bin/python, they should use /1/2/3/4/5 as the included directory.
  • Windows users can specify paths with either path separator
  • If a user starts an interpreter, then excludes or un-includes it and restarts Positron, it will still be selected upon restart
    • if they shut it down and then restart, it should no longer show

This option allows user-specified Python search paths to be included as part of Python installation discovery. This is useful when the Python interpreter is not installed in a standard location.

The option is a list of unique paths to include in the search for Python interpreters. The paths can be absolute or relative to the user's home directory. The default value is an empty list.
Copy link

github-actions bot commented Feb 19, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical

readme  valid tags

@sharon-wang sharon-wang marked this pull request as ready for review February 20, 2025 15:53
@sharon-wang sharon-wang requested review from seeM, isabelizimm and jmcphers and removed request for seeM and isabelizimm February 20, 2025 15:53
@sharon-wang
Copy link
Member Author

Opening this up for review, but I am working on adding a JS locator test for the new UserSpecifiedEnvironmentLocator that I'll push when done.

QUESTION: For the native locator, shall I just leave a note in nativePythonFinder.unit.test.ts to add
testing for python.interpreters.include once we switch over? Currently the test is skipped and I'm not sure off the top of my head how to switch the locator for the unit tests.

@sharon-wang sharon-wang requested review from melissa-barca and removed request for jmcphers February 20, 2025 16:48
Comment on lines 14 to 16
* Gets the list of interpreters that the user has explicitly included in the settings. Converts
* relative and aliased paths to absolute paths.
* @returns List of interpreters that the user has explicitly included in the settings.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we converting relative and aliases paths? It looks like we're just ignoring them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops good catch! I meant to resolve aliased paths and not include relative paths. I just pushed a commit to resolve aliased paths.

For relative paths, my thinking is that it's ambiguous where the paths are relative to. Are they relative to the home directory or to the project directory? Does it make sense for an admin to set a relative path as a default? I figured we can document that only absolute or absolute-but-aliased paths are valid here.


/**
* Check whether an interpreter should be included in the list of discovered interpreters.
* If an interpreter is both explicitly included and excluded, it will be included.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you confident this is the right approach? I'm wondering if we'd run into a situation where a Workbench admin has explicitly excluded an interpreter, but then a confused user tries to include it. We might want to consider implementing a way to log this use for admins, but we don't have monitoring implemented yet in Workbench for VS Code or Positron.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The language pack output will have a bit of info about why certain interpreters were included/excluded, but longer term, I'm hoping to better surface this information in a dedicated pane or something similar.

I think this approach makes sense for the Desktop user case, but let me think on the admin situation a bit! I feel like we will want a separate flag/option elsewhere, like an "admin policy" to enforce certain options

Copy link
Contributor

@seeM seeM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes LGTM! I tested locally and it seems to work well, except that the interpreters are still shown in the "Python: Select Interpreter" command. Is that expected?

Comment on lines 731 to 742

// --- Start Positron ---
/**
* Wraps the original filter function to include additional filtering logic.
* If no filter is provided, the returned function will only include the additional filtering logic.
* @param filter The original filter function
* @returns A new filter function that includes the original filter function and the additional filtering logic
*/
function filterWrapper(filter: ((i: PythonEnvironment) => boolean) | undefined) {
return (i: PythonEnvironment) => (filter ? filter(i) : true) && shouldIncludeInterpreter(i.path);
}
// --- End Positron ---
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seeM

the interpreters are still shown in the "Python: Select Interpreter" command. Is that expected?

Thank you for catching this! I checked the "include" case, but missed the "exclude" case for the quickpick. This should be fixed now!

Copy link
Contributor

@isabelizimm isabelizimm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: If I have started an interpreter, say, a pyenv interpreter, then I exclude ~/.pyenv, should I expect to see the interpreter on restart?

It will not show if I have shut down the interpreter, but if I leave it running and then quit/reopen Positron, the interpreter persists. This feels like the right choice, but just making sure it is intentional!

++ to @seeM comment, this does not affect the Python: Select Interpreter list. With the upcoming changes to our interpreter, we might want to make sure include/exclude works there as well

@@ -17,6 +17,7 @@ import * as workspaceApis from '../../client/common/vscodeApis/workspaceApis';

// --- Start Positron ---
// re-enable when Native Finder is used for discovery
// TODO: add test for python.interpreters.include here once we switch to Native Finder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine for now, I'll log an issue to turn these back on (probably for the next milestone)

@isabelizimm
Copy link
Contributor

isabelizimm commented Feb 21, 2025

oh gosh, I reviewed just a few mins too late! I see the Python: Select Interpreter changes 🚀

isabelizimm
isabelizimm previously approved these changes Feb 21, 2025
Copy link
Contributor

@isabelizimm isabelizimm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good with me once ci is green ✅

@sharon-wang
Copy link
Member Author

@isabelizimm

Question: If I have started an interpreter, say, a pyenv interpreter, then I exclude ~/.pyenv, should I expect to see the interpreter on restart?

It will not show if I have shut down the interpreter, but if I leave it running and then quit/reopen Positron, the interpreter persists. This feels like the right choice, but just making sure it is intentional!

Yes this feels right to me as well 👍 Thanks for calling this out! I added a note to the QA Notes section to mention this case

### Release Notes

<!--
Optionally, replace `N/A` with text to be included in the next release
notes.
The `N/A` bullets are ignored. If you refer to one or more Positron
issues,
these issues are used to collect information about the feature or
bugfix, such
as the relevant language pack as determined by Github labels of type
`lang: `.
  The note will automatically be tagged with the language.

These notes are typically filled by the Positron team. If you are an
external
  contributor, you may ignore this section.
-->

#### New Features

- N/A

#### Bug Fixes

- #3740 filters out unsupported (<3.8) Python versions from the `Python:
Select Interpreter` dropdown


### QA Notes

1. create a Python interpreter <3.8 (if you are a pyenv user, you can do
`pyenv install 3.6`)
2. go to `Python: Select Interpreter`
3. should not appear in dropdown
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.

4 participants