Visual Studio Code keeps changing my "python.pythonPath" - visual-studio-code

I have been using settings.json for a while now to share some project settings accross my different machines (which happen to be Linux, macOS and Windows). One of the settings I use is "python.pythonPath", which points to a interpreter inside the .venv created by the Poetry tool. Since Windows and linux-based operating system paths differ for virtualenvs, I need to set an environment variable with the proper path, e.g.: CLAYMEMOIRS_INTERPRETER.
I started noticing a problem where, whenever I launch visual studio code, my:
{
...
"python.pythonPath" : "${env:CLAYMEMOIRS_INTERPRETER}"
}
Gets automatically replaced with:
{
...
"python.pythonPath" : "c:\\GitHub\\claymemoirs\\.venv\\Scripts\\python.exe"
}
Which is the value of my environment variable. Anyone knows how I can prevent this behaviour? I did not do any updates or changed any plugins.

The problem persists, but newer releases indicate python.pythonPath is being deprecated in favor of python.defaultInterpreterPath. See here.
One of the reasons for deprecation is the questioned problem.
With the new python.defaultInterpreterPath set in the workspace settings file (.vscode/settings.json) you can use environment variables to set the project .venv path in a OS independant manner "${workspaceFolder}${env:CLAYMEMOIRS_INTERPRETER}". When someone from the team loads opens the project's folder in VSCode, the interpreter will appear on the selectlist, allowing developers to select the project interpreter without messing with other people's interpreters and, without changing the workspace path.

Related

How to prevent VSCode from changing files that do not belong to the project?

Assume I am working on a project folder my_project while using Python. I want to make sure, VS Code does not allow me to change files that do not belong to the project (they are outside my_project folder).
Example scenario: Once I was debugging a code in Python, I ended up in a file that belonged to my virtual environment and by mistake I pressed a key somewhere. This caused everything crashes afterward and was hard to catch (note it does not show in git status). If I would do the same thing on PyCharm it would show a pop up window warning me. Is the same thing possible for VS Code?

What is the alternative to python.pythonPath in settings.json?

In a Python tutorial I'm following, the Python path is linked to the python.pythonPath setting in the settings.json file of Visual Studio Code. However, the python.pythonPath does not exist anymore.
I tried to find the python.pythonPath variable or alternatives in the default settings.json file, but I could not find one.
What is the alternative to this settings variable?
According to the documentation on Github, the python.pythonPath setting is indeed not used anymore.
Instead, a new settings with the name python.defaultInterpreterPath has been introduced.
Note, however, that this setting is not exactly the same. The way it is processed by Visual Studio Code is changed as well. See the documentation linked above, or the Python settings reference:
python.defaultInterpreterPath:
Path to the default Python interpreter to be used by the Python extension on the first time it loads for a workspace, or the path to a folder containing the Python interpreter.
Can use variables like ${workspaceFolder} and ${workspaceFolder}/.venv.
Using a path to a folder allows anyone working with a project to create an environment in the .venv folder as appropriate to their operating system, rather than having to specify an exact platform-dependent path. The settings.json file can then be included in a source code repository.
Note: Changes to this setting made after an interpreter has been selected for a workspace will not be applied or considered by the Python extension. The Python extension doesn't automatically add or change this setting.

share settings between linux and windows

I have a question: I would like to share settings between two Visual Studio Code installations, one on Windows and another one on Linux.
Simply activating, the syncing of the settings is a bad idea since they contain platform-dependent paths, e.g., the location of the ssh config file. I did it and ended up with a broken VSC installation on linux: it could not find anything because the settings contained windows paths.
I ended disabling most of the syncings, up to the point where the syncing is useless.
Is there any way, a plugin, to easily share settings between installation on different OS platforms?

How can I create a local configs for Neovim extending the global init.vim?

Suppose that I have a map on my init.vim that I want to change the behaviour depending on the folder that I am. How could you do that?
A more concrete example: I have a map on my F12 that runs the project that I am. So if I am on a python project, this F12 will run an ipython on a floaternew window, with the current file already imported. Though, if I am on a cpp project, the same F12 will build using Make and running the binary on a floaternew window as well.
Nowadays, I have these two behaviours mapped on different key bindings. But It is going to very nice if I have only one binding to "run the project". Even if I need to open neovim with some parameter in each project, like neovim --local-config mylocalconfig.vim (extending init.vim with some behaviour)
I am kind inspired by a behaviour like direnv but with .vim files.
Any ideas?
There is an option in vim set exrc which enables reading vim config files from current directory, it also works in neovim.
From docs (:h exrc)
Enables the reading of .vimrc, .exrc and .gvimrc in the current
directory. If you switch this option on you should also consider
setting the 'secure' option (see |initialization|). Using a local
.exrc, .vimrc or .gvimrc is a potential security leak, use with care!
also see |.vimrc| and |gui-init|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.

Multiple configurations for VSCode

At the moment I'm working on a few projects at the same time using VSCode, one in react, another in angular and some good old javascript.
The problem is that I have a few extensions installed that conflict, for example, some code snippets that are the same for React and Angular.
Is it possible to have 3 visual studio code installed on a Mac with different extensions installed?
There are two options for such setup:
Portable installation - unzip VSCode in a folder and create a subfolder there called data. This will trigger the portable mode and all settings will be stored in that data folder. The downside is that you'll have to manually update every portable folder whenever new version comes out. More info here.
Custom config paths - create a shortcut for your VSCode installation, and add those parameters:
--user-data-dir <some-path> --extensions-dir <some-path>
You can put them wherever and have as much shortcuts as you want, they even run in parallel. Best part is once you update the installation, all the configs are upgraded too. More info here.
Both modes are incompatible, so you have to choose one.