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

Don't set ${workspaceFolder} in settings.json #2459

Closed
segevfiner opened this issue Aug 28, 2018 · 8 comments
Closed

Don't set ${workspaceFolder} in settings.json #2459

segevfiner opened this issue Aug 28, 2018 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority

Comments

@segevfiner
Copy link

Environment data

  • VS Code version: 1.26.1
  • Extension version (available under the Extensions sidebar): 2018.7.1
  • OS and version: Windows 10.0.17134.228 x64
  • Python version (& distribution if applicable, e.g. Anaconda): CPython 3.7.0 x64
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv

Actual behavior

When python.pythonPath includes ${workspaceFolder}, tasks that use ${config:python.pythonPath} fail to start:

> Executing task: ${workspaceFolder}\venv\Scripts\python.exe setup.py build_ext --inplace <

The system cannot find the path specified.
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

Expected behavior

The tasks should start correctly. It's quite useful to use ${config:python.pythonPath} in your tasks so as to use the Python version used by vscode-python to run the tasks.

Steps to reproduce:

  1. Create a virtualenv under your workspace: virtualenv venv
  2. Select it as the Python interpreter of VS Code using the status bar. (python.pythonPath should be set to a path using ${workspaceFolder}).
  3. Create a task that uses ${config:python.pythonPath} to run anything you want, and try to run it.

Logs

Nothing relevant under default log level.

@bhrutledge
Copy link

bhrutledge commented Aug 29, 2018

I stumbled upon this issue by way of #1664.

My workspace settings (set automatically, I think):

{
    "python.pythonPath": "${workspaceFolder}/venv/bin/python"
}

What I tried:

{
    "label": "runserver",
    "type": "shell",
    "command": "${config:python.pythonPath} manage.py runserver",
    "problemMatcher": [],
    "group": {
        "kind": "build",
        "isDefault": true
    }
}

Output:

> Executing task: ${workspaceFolder}/venv/bin/python manage.py runserver <

/usr/local/bin/bash: /venv/bin/python: No such file or directory
The terminal process terminated with exit code: 127

Changing command to ${workspaceFolder}/venv/bin/python manage.py runserver works. Just using manage.py runserver doesn't work because the virtualenv isn't activated. Of course, if I were using pipenv, I'm guessing pipenv run manage.py runserver would do the job.

Aside: this makes me wonder if VS Code has a facility for defining a new task type, that would handle the virtualenv automatically.

@brettcannon
Copy link
Member

This issue was moved to microsoft/vscode#57551

@brettcannon
Copy link
Member

We don't' have anything to do directly with tasks.json, so I have reported this upstream to VS Code.

@bhrutledge
Copy link

Gotcha. Thanks for bumping this up the food chain.

I think one way this might still be an issue for this extension is that "python.pythonPath": "${workspaceFolder}/venv/bin/python" seems to be set automatically when the extension detects a virtual environment. But, that's incompatible with VS Code's variable substitution behavior as documented (and further discussed in microsoft/vscode#57551).

So, for this specific use case, it seems like automatically setting the python.pythonPath to either /Users/brian/Projects/my-project/venv/bin/python or just venv/bin/python would be preferable. But I'm guessing either of those could break other uses.

@brettcannon brettcannon changed the title When python.pythonPath includes ${workspaceFolder}, tasks that use ${config:python.pythonPath} fail to start Don't set ${workspaceFolder} in settings.json Aug 31, 2018
@brettcannon brettcannon reopened this Aug 31, 2018
@brettcannon
Copy link
Member

I've re-oriented the issue to change what the extension does.

@brettcannon brettcannon added the important Issue identified as high-priority label Aug 31, 2018
@brettcannon brettcannon added this to the Sep 2018 milestone Aug 31, 2018
@DonJayamanne DonJayamanne added needs proposal Need to make some design decisions and removed needs proposal Need to make some design decisions labels Sep 4, 2018
@brettcannon brettcannon modified the milestones: Sep 2018, September 2018 Sprint 1 Sep 6, 2018
@ericsnowcurrently ericsnowcurrently self-assigned this Sep 20, 2018
@ericsnowcurrently
Copy link
Member

Another point of reference (from the docs):

Is variable substitution supported in User and Workspace settings?
No, the predefined variables are not supported in strings in settings.json files.

@ericsnowcurrently
Copy link
Member

Just to be sure I've understood, we don't need to change package.json (since the only substitutions are in the launch and task configs), right? From what I understand, we only need to change the places where we are adding substitutions to settings (e.g. in python.pythonPath).

@brettcannon
Copy link
Member

Correct. The fact that we are injecting ${workspaceFolder} into people's python.pythonPath setting is what is breaking in the tasks.json usage.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 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 important Issue identified as high-priority
Projects
None yet
Development

No branches or pull requests

6 participants