Skip to content

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

Closed

Description

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.

Activity

  1. bhrutledge commented on Aug 29, 2018

    @bhrutledge

    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.

  2. brettcannon commented on Aug 30, 2018

    @brettcannon
    Member

    This issue was moved to microsoft/vscode#57551

  3. brettcannon commented on Aug 30, 2018

    @brettcannon
    Member

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

  4. bhrutledge commented on Aug 30, 2018

    @bhrutledge

    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.

  5. changed the title [-]When python.pythonPath includes ${workspaceFolder}, tasks that use ${config:python.pythonPath} fail to start[/-] [+]Don't set ${workspaceFolder} in settings.json[/+] on Aug 31, 2018
  6. brettcannon commented on Aug 31, 2018

    @brettcannon
    Member

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

  7. added this to the milestone on Aug 31, 2018
  8. 1 remaining item

  9. modified the milestones: , September 2018 Sprint 1 on Sep 6, 2018
  10. ericsnowcurrently commented on Sep 25, 2018

    @ericsnowcurrently

    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.
    
  11. ericsnowcurrently commented on Sep 25, 2018

    @ericsnowcurrently

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

  12. brettcannon commented on Sep 25, 2018

    @brettcannon
    Member

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

  13. locked as resolved and limited conversation to collaborators on Oct 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bugimportantIssue identified as high-priority

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions