Skip to content

Select a Python Interpreter without modifying the workspace's settings.json #2125

Closed

Description

Be default, a local pipenv environemnt is searched for and if found, is marked as the python interpreter. But it also then adds a line to settings.json indicating the path for the virtual environment which can cause issues for configs shared among a team. The python.pythonPath variable will not be constant for each user working on the repo (eg "python.pythonPath": "/home/daniel/.local/share/virtualenvs/ontariofresh_backend-NQNAEc6t/bin/python", note my home directory in the path) and thus prevents the settings.json file from being committed to the remote repository.

Ideally, it would behave just as it does now, but just implicitly sets the python interpreter as the one found without explicitly writing it out to settings.json.

Environment data

  • VS Code version: 1.25.0
  • Extension version (available under the Extensions sidebar): 2018.6.0
  • OS and version: ubuntu 18.04
  • Python version (& distribution if applicable, e.g. Anaconda): 2.7.15
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pipenv

Actual behavior

The installed pipenv virtual environment is found and selected as the python interpreter and the path to that environment is added to settings.json.

Expected behavior

The installed pipenv virtual environment is found and selected as the python interpreter and the path to that environment is not added to settings.json.

Activity

  1. changed the title [-]`settings.json` is modified on startup when using pipenv[/-] on Jul 10, 2018
  2. brettcannon commented on Jul 10, 2018

    @brettcannon
    Member

    [I edited your ✉️ ⬆️ to come off as more 😃 and less 😠 ]

    Yes, VS Code's lack of "workspace-personal" on top of a "workspace-global" config can be a problem in this situation.

  3. Tiedye commented on Jul 10, 2018

    @Tiedye
    Author

    Ha sorry, didn't realize I was coming off as 😠

  4. brettcannon commented on Jul 10, 2018

    @brettcannon
    Member

    Daniel Whitney (@Tiedye) No problem! It was basically phrasing as "this is bad!" can be off-putting because it comes off as a demand instead of a request.

  5. brettcannon commented on Jul 10, 2018

    @brettcannon
    Member

    Daniel Whitney (@Tiedye) a work-around for this is to set PIPENV_VENV_IN_PROJECT and the extension will automatically pick up the .venv directory that gets created. And you can set python.pythonPath to ${workspaceFolder}/.venv to be consistent within your project without any hard-coded, absolute paths.

  6. Tiedye commented on Jul 10, 2018

    @Tiedye
    Author

    Awesome! That works. Should the issue be left open? Or is this more of a vs-code issue at this point.

  7. brettcannon commented on Jul 11, 2018

    @brettcannon
    Member

    We can leave this issue open to consider coming up with a solution that negates the need to force you to set an environment variable (at worst we could document this for users).

    As for getting personal workspace settings, I believe there is a VS Code issue on this topic so if you can find it and upvote it then that might help get it implemented.

  8. Tiedye commented on Jul 12, 2018

    @Tiedye
    Author
  9. mungojam commented on Jul 19, 2018

    @mungojam

    set PIPENV_VENV_IN_PROJECT

    I'm thinking of using this workaround too as I can easily roll out environment variables to all our devs. The unfortunate thing about it is that the .venv isn't in the default .gitignore in our version of GitHub Enterprise so we'll need to remember to add it to every repo. It is in the public github.com version

  10. thernstig commented on Jul 28, 2018

    @thernstig

    Brett Cannon (@brettcannon) Is that the only workaround or could you opt not to update .vscode/settings.json in some way and still use the Pipenv virtualenv's pythonPath?

    It's great that VS code is working on a general fix in microsoft/vscode#15909 though. I am wondering however if it is customary for extensions to automatically update a workspace's settings? As settings.json is aimed to be shared amongst team members of a project it becomes problematic if it is updated with individual settings, such as in this issue.

  11. brettcannon commented on Jul 30, 2018

    @brettcannon
    Member

    Tobias Hernstig (@thernstig) I don't know if there's any customary practice that has been established by the VS Code extension community. For us we do it because there's a visible startup cost in searching for a person's environment, so writing it out short circuits that search.

  12. thernstig commented on Aug 1, 2018

    @thernstig

    Brett Cannon (@brettcannon) Part of the reason I am making that comment is because we had this same discussion for issue #265. There I referred to the issue microsoft/vscode#851 on VS Code, where bpasero (his team started VS Code when it was still called Monaco) made this comment about .vscode/settings.json

    These things are workspace related settings so they are stored in the workspace folder with the intent to share them to other people (e.g. a launch configuration is typically OS and path independent).

    In relation to that, I was thinking that polluting .vscode/settings.json with user-specific settings must be some kind of antipattern?

    Adding specific settings to .vscode/settings.json breaks the convention of sharing workspace specific settings for projects. I think this is a huge issue for teams utilizing this feature.

    Every user in our project now has to do a git checkout .vscode/settings.json everytime before commit in order to not commit their personal venv path.

  13. 54 remaining items

  14. drozzy commented on Feb 18, 2021

    @drozzy

    But aren't you guys part of microsoft?

  15. SteelPhase commented on Feb 18, 2021

    @SteelPhase

    Doesn't this have a workaround using the following setting, or am I mistaken?

    "python.experiments.optInto": [
        "DeprecatePythonPath - experiment"
    ]
  16. drozzy commented on Feb 18, 2021

    @drozzy

    SteelPhase (@SteelPhase) I didn't know about that, I guess it's still experimental. Seems like it's meant exactly for this purpose. Thanks. I'll wait until it's officially released.

  17. brettcannon commented on Feb 18, 2021

    @brettcannon
    Member

    Andriy Drozdyuk (@drozzy) being part of Microsoft does not mean we get to tell the VS Code team what to do 😉 . You can go to github.com/microsoft/vscode and open a feature request if you want (although I suspect one already exists so I would check first).

    SteelPhase (@SteelPhase) yep, that will get you what you want for now.

  18. kariharju commented on Jun 3, 2021

    @kariharju

    Hi,
    A long thread so sorry if I missed an answer to this.
    We have a system that is building isolated python environments (trying our hardest to specifically avoid polluting target machines with multiple python installations 😉)
    Our extension, related to this just stopped working on some people as a part of the A/B testing and we are looking for a way forward.

    We would just need an API (or any way) to set the interpreter path of this extension from another extension.
    As of now, we have not found a way.. are we missing something?

  19. brettcannon commented on Jun 3, 2021

    @brettcannon
    Member

    Kari Harju (@kariharju) you have a couple of options:

    We are actually hoping to have this whole situation resolved in a release or two in a way that should make everyone happy (famous last words, I know 😉).

  20. kariharju commented on Jun 8, 2021

    @kariharju

    Hi, yeah I know these things are not easy to get done.

    I forgot to upvote #16370 (I came from the "same source" 😉).

    Basically, we don't care about the internals as much as the fact that we could just somehow get isolated python environments up-n-running with this extension (as pretty much every Python developer using VsCode has this one installed as it is kind of a default).

    In enterprise-scale automation scenarios having the end-user or even the developer's machine "polluted" by multiple Python installations is a no-go. So not all Python environments are installed on the OS level and having a way to point a Python environment location to this extension would be a crucial thing to have.

  21. linette-zyy commented on Jun 28, 2021

    @linette-zyy

    This issue is also reproduced on this build.
    image
    After change Python Interpreter, the file settings.json is not generated in .vscode in current folder/workspace.

  22. brettcannon commented on Jun 28, 2021

    @brettcannon
    Member

    Please see #12313 (comment) for an explanation of the change we are slowly rolling out to users to address this.

  23. brettcannon commented on Jul 28, 2021

    @brettcannon
    Member
  24. locked as resolved and limited conversation to collaborators on Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-environmentsexperimentingfeature-request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions