subcoder
subcoder

Reputation: 85

Custom variables in Visual Studio Code settings.json

I have the following settings in my settings.json:

{
    "python.pythonPath": "/path/to/bin/python3.6",
    "python.formatting.yapfPath": "/path/to/bin/yapf",
    "code-runner.executorMap": {
        "python": "/path/to/bin/python3.6",
    }
}

What I'd like to have is something like:

{
    "venvPath": "/path/to/venv",
    "python.pythonPath": "${venvPath}/bin/python3.6",
    "python.formatting.yapfPath": "${venvPath}/bin/yapf",
    "code-runner.executorMap": {
        "python": "${python.pythonPath}",
    }
}

Is there a way to achieve that?

Upvotes: 4

Views: 3144

Answers (1)

CodeFukurou
CodeFukurou

Reputation: 44

Unfortunately as it stands there is no support for use of environment variables like that (see here). In the mean time I would suggest a .bat file that to write your settings.json file with your desired path. For your example you could do something like this:

set venvPath=/path/to/venv
echo {> settings.json
echo     "python.pythonPath": "%venvPath%/bin/python3.6",>> settings.json
echo     "python.formatting.yapfPath": "%venvPath%/bin/yapf",>>settings.json
echo     "code-runner.executorMap": {>> settings.json
echo         "python": "${python.pythonPath}",>> settings.json
echo     }>> settings.json
echo }>> settings.json

This will create the following settings.json file

{
    "python.pythonPath": "/path/to/venv/bin/python3.6",
    "python.formatting.yapfPath": "/path/to/venv/bin/yapf",
    "code-runner.executorMap": {
        "python": "${python.pythonPath}",
    }
}

Upvotes: 1

Related Questions