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

python.pythonPath is automatically added to workspace settings #265

Closed
thernstig opened this issue Nov 20, 2017 · 19 comments · Fixed by #369
Closed

python.pythonPath is automatically added to workspace settings #265

thernstig opened this issue Nov 20, 2017 · 19 comments · Fixed by #369
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@thernstig
Copy link

Environment data

VS Code version: 1.18.1
Python Extension version: 0.8.0 (9 November 2017)
Python Version: 3.6.1
OS and version: Windows 10 Home, Version 1703, OS-version 15063.483

Actual behavior

At certain points when working in VS Code (starting VS Code is one example) it automatically adds the configuration "python.pythonPath" to the WORKSPACE SETTINGS file (vscode/settings.json).

Good to know is that the project has a .vscode/extensions.json file with the following content:

{
	"recommendations": [
		"ms-python.python"
	]
}

Also good to know is that I have "python.pythonPath" configured in my USER SETTINGS.

Expected behavior

It is not expected for the "python.pythonPath" to be automatically added to the .vscode/settings.json file.

Steps to reproduce:

  • Install "ms-python.python"
  • Add the following to .vscode/extensions.json:
{
	"recommendations": [
		"ms-python.python"
	]
}
  • Make sure your .vscode/settings.json (WORKSPACE SETTINGS) is empty
  • Close and then re-start VS Code
@DonJayamanne
Copy link

@thernstig
I'm unable to replicate this aat my end.

Note: the file .extensions.json will be used by vscode. The python extension does not use this file in any way or form.

Note:

At certain points when working in VS Code (starting VS Code is one example) it automatically adds the configuration "python.pythonPath" to the WORKSPACE SETTINGS file (vscode/settings.json).

The extension does not automatically add these settings. It only gets added when you manually select a python interpreter.

  • Please could you try disabling other extensions and repeating your steps
  • Please could you upload the sample folder (so I could try it at my end).
  • Please try to identify when this occurs (At certain points when working in VS Code).

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster feature-extension bug Issue identified by VS Code Team member as probable bug and removed bug Issue identified by VS Code Team member as probable bug labels Nov 20, 2017
@thernstig
Copy link
Author

  • I have disabled all addons except "ms-python.python". The problem still occurs.
  • This only started happening when I upgraded from version 1.17 to 1.18 and at the same time the python extension was upgraded (as part of the move to vscode-python). I am thus not sure if is the extension itself or VS Code that does this.

I managed to reproduce it every time:

  1. Start VS code and go to the Workspace Settings file (.vscode/settings.json).
  2. Do a cold start of VS Code (close and open again). You should end up in the last file you had in focus, which should be the Workspace Settings file (.vscode/settings.json).
  3. Now, open one of the Python files in the project. When I do this, it automatically modifies my .vscode/settings.json

Note that it is not of importance to be in the .vscode/settings.json file when closing/opening VS Code. It happens anyway if I have a python file in focus. I just felt that doing the steps above narrows it down a bit, as we then understand that it is when a python file gets in focus.

It is a private project, so I cannot upload the folder. I uploaded the online files that exist in my .vscode folder though.

vscode.zip

@DonJayamanne
Copy link

@thernstig thanks for the additional information. Please could you try the following:

the extension itself or VS Code that does this.

  1. Try disabling the Python extension as well and trying this again
  2. Next, create a brand new workspace and try to replicate the issue.
  3. Finally, please uninstall the Python extension and re-install it.

Thanks.

@brettcannon brettcannon added the bug Issue identified by VS Code Team member as probable bug label Nov 21, 2017
@thernstig
Copy link
Author

@DonJayamanne Late reply, busy schedule.

  1. Disabling the Python extension made the problem go away. Enabling it again made it come back.
  2. I could replicate the issue with a brand new workspace. All I created was one file called testing.py and had it in focus, without any interpreter set. As soon as I selected a python interpreter (I chose the installed one, not a venv) it automatically modified my settings.json.
  3. Reinstalling did not help. The problem kept happening. As soon I select a work space interpreter again, settings.json was modified (exactly like in step 2 above).

@DonJayamanne
Copy link

Reinstalling did not help. The problem kept happening. As soon I select a work space interpreter again, settings.json was modified (exactly like in step 2 above).

This is new information. Selecting a workspace will modify the settings file. That's where you're selection is stored. I.e. this is a user action.

You could either not change the workspace interpreter of change your default interpreter (in your current PATH).

@DonJayamanne DonJayamanne added closed-invalid and removed info-needed Issue requires more information from poster bug Issue identified by VS Code Team member as probable bug labels Nov 25, 2017
@thernstig
Copy link
Author

thernstig commented Nov 27, 2017

@DonJayamanne I am not sure I follow the logic here. I selected the default workspace interpreter. Why should the workspace settings file be automatically altered when a workspace is selected? I have not saved anything in that file.

It makes no sense to propage the workspace setting file to other users of the git repo for why I personally keep my virtual environment.

edit: Also note this has never happened before as long as I have used VS Code and python, this started to happen recently.

edit2: I did not select a workspace interpreter at first. Step 3 above was a new way I did this. The problem happens without me changing the interpreter as soon as I start VS code if I am inside a python file.

@brettcannon
Copy link
Member

The change needs to be saved, otherwise you would have to make the change every time you re-open VS Code.

And the change doesn't have to propagate to other users if you don't save your .vscode directory in git.

@thernstig
Copy link
Author

thernstig commented Nov 27, 2017

I have the same setting configured in my user settings so they are not needed in the workspace settings. I want to re-iterate that this auto-add-config to the workspace settings has not happened before.

@thernstig
Copy link
Author

Let's put it like this instead. Let's say I have a bunch of VS code workspace settings I want every developer of a project to use. It means I version handle the settings.json file.

Now, every developer has various places they put their virtual environment. This would mean that if the workspace settings (settings.json) has to be altered if a user changes their workspace interpreter, they would have to make sure to not check in the settings.json file everytime and revert the automatic change done by the python plugin.

Am I missing something there?

@brettcannon
Copy link
Member

No, I don't think you're missing anything. Unfortunately we don't control the configuration setup to provide you with an equivalent user-specific, workspace setting.

As for saving the config, I believe we added this in the 0.8.0 release as part of our support for multi-root.

@thernstig
Copy link
Author

thernstig commented Nov 28, 2017

@brettcannon I have set the pythonpath settings inside my user settings. That is why I get the option to select it as a interpreter. When it is selected, it also adds it to the workspace settings

Shouldn't it be so that if I select my workspace from the user settings, it should not automatically add it to the workspace settings?

The way it works now is it means I can never have a settings.json file for my workspace and thus all developer of the project. That cannot be the intention for VS code to work like that?

@brettcannon
Copy link
Member

No, we don't propagate settings from user settings to workspace settings for users as that simply isn't how VS Code does things.

@thernstig
Copy link
Author

Ok, I am not sure how I am supposed to have a settings.json file for my project anymore due to this. The Python extension changes where the interpreter is located for everyone in the project even though we all do not have virtual env in the same location. It means everyone always have to undo changes in settings.json before commiting to git. I have not seen any logical answer on how I should handle this, only that "it is supposed to work like that".

@brettcannon
Copy link
Member

You haven't seen an answer because we simply don't have one to provide, unfortunately. VS Code doesn't give us a mechanism to provide you with a solution that you're after. You could maybe try filing a bug against VS Code asking for what would essentially be a "global/team" workspace settings.json and a "personal" workspace settings.json file.

@thernstig
Copy link
Author

@brettcannon As I understand it, the current settings.json already is a "global/team" workspace setting in all its intention? For example, in this thread microsoft/vscode#851 the user bpasero (his team started VS Code when it was still called Monaco) says:

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).

I am not sure in what ever other way to put this. If I have already set my own user settings to python.pythonPath": "${workspaceRoot}/venv/Scripts/python.exe" and then select that interpreter, VS code should not add that very same config to the workspace settings settings.json. Just simply because it makes no sense in relation to the intention of the file. The only reason I could even select that interpreter from the venv was because it was in my user settings. There is no need to then add it to the workspace settings.

I'm giving up now, I just cannot stress how unintuitive it is. Please do not mistake my frustration with how it works with you guys, you are providing excellent support in even taking the time to answer. I am just at loss on what to do if my entire future workflow for projects require people to undo changes in settings.json. Your idea to file an issue about this might be good. It won't help for the time being unfortunately.

@DonJayamanne
Copy link

I am not sure in what ever other way to put this. If I have already set my own user settings to python.pythonPath": "${workspaceRoot}/venv/Scripts/python.exe"

@thernstig I'm sorry, but you're not making any sense here.
On the original post you mentioned that the settings.json is empty, now you're saying it has a value.

Make sure your .vscode/settings.json (WORKSPACE SETTINGS) is empty Close and then re-start VS Code

@thernstig
Copy link
Author

thernstig commented Dec 7, 2017

@DonJayamanne I believe I have been very thorough in highlighting the difference between user settings and workspace settings (by bolding it several times)

The first part you quote is for user settings and the second part you quote is for workspace settings

This bug breaks the entire logic of having the workspace settings version controlled since it automatically alters the workspace setting.

I will outline it again like this:

  • I start with a user setting of: "python.pythonPath": "${workspaceRoot}/venv/Scripts/python.exe"
  • I make sure my workspace setting is completely empty.
  • I make sure to have a python file opened (in focus) in VS code.
  • I restart VS code.
  • The plugin generates tags.
  • The plugin sets the python interpreter automatically to the one it finds in the user settings.
  • The plugin automatically adds/changes the workspace settings to: "python.pythonPath": "${workspaceRoot}\\venv\\Scripts\\python.exe"

Everytime I say "workspace setting" I am refering to the file inside the workspace folder under .vscode/settings.json

@DonJayamanne DonJayamanne reopened this Dec 7, 2017
@DonJayamanne
Copy link

DonJayamanne commented Dec 7, 2017

Ok, I understand the issue now. The problem is that we're automatically detecting the virtual environment and setting it, even though it has already been configured in the user settings.
I do apologize for the inconvenience and the confusion.
The good thing is we've now understand the problem and are confident we can fix this.

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug and removed closed-invalid labels Dec 7, 2017
@thernstig
Copy link
Author

That is great news. Thanks.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants