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

mypy-type-checker.args not resolving environment variables? #334

Closed
nblum-mdmi opened this issue Dec 5, 2024 · 1 comment
Closed

mypy-type-checker.args not resolving environment variables? #334

nblum-mdmi opened this issue Dec 5, 2024 · 1 comment
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed

Comments

@nblum-mdmi
Copy link

Diagnostic Data

  • Python version (& distribution if applicable, e.g., Anaconda): Python 3.11.9 (CPython)
  • Type of virtual environment used (e.g., conda, venv, virtualenv, etc.): virtualenv
  • Operating system (and version): Windows 11
  • Version of tool extension you are using: v2024.1.13171012

Behaviour

Expected Behavior

Setting the following:

// settings.json
...
"mypy-type-checker.args": [
    "--python-executable",
    "${env:VIRTUAL_ENV}",
    "--strict",
    "--exclude",
    "scripts|_tests"
],
...

Mypy should resolve ${env:VIRTUAL_ENV} to that environment variable's value as described in the README when it runs.

Actual Behavior

Receive the following error:

[info] mypy: Invalid python executable '${env:VIRTUAL_ENV}': No such file or directory

It doesn't seem to be resolving the environment variable at all and is just treating it as a raw string?

Reproduction Steps:

Logs:

Click here for detailed logs
  2024-12-05 15:03:37.905 [info] [Trace - 3:03:37 PM] Sending notification 'textDocument/didSave'.
2024-12-05 15:03:37.906 [info] Params: {
    "textDocument": {
        "uri": "file:///c%3A/Users/NoahBlum/GitHub/█████████████████████████████████████████████████████████████.py"
    }
}


2024-12-05 15:03:37.917 [info] [Trace - 3:03:37 PM] Received notification 'window/logMessage'.
2024-12-05 15:03:37.918 [info] Params: {
    "type": 4,
    "message": "mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --python-executable ${env:VIRTUAL_ENV} --strict --exclude scripts|_tests --show-error-end c:\\Users\\NoahBlum\\GitHub\\██████████████████████████████████"
}


2024-12-05 15:03:37.918 [info] mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --python-executable ${env:VIRTUAL_ENV} --strict --exclude scripts|_tests --show-error-end c:\Users\NoahBlum\GitHub\█████████████████████████████████
2024-12-05 15:03:37.918 [info] mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --python-executable .\.venv\Scripts\python.exe --strict --exclude scripts|_tests --show-error-end c:\Users\NoahBlum\GitHub\█████████████████████████████████
2024-12-05 15:03:37.919 [info] [Trace - 3:03:37 PM] Received notification 'window/logMessage'.
2024-12-05 15:03:37.919 [info] Params: {
    "type": 4,
    "message": "CWD Server: c:\\Users\\NoahBlum\\GitHub\\██████████████████████████████████"
}


2024-12-05 15:03:37.919 [info] CWD Server: c:\Users\NoahBlum\GitHub\█████████████████████████████████
2024-12-05 15:03:37.920 [info] CWD Server: c:\Users\NoahBlum\GitHub\█████████████████████████████████
2024-12-05 15:03:38.965 [info] mypy: Invalid python executable '.\.venv\Scripts\python.exe': No such file or directory

2024-12-05 15:03:38.967 [info] file:///c%3A/Users/NoahBlum/GitHub/█████████████████████████████████████████████████████████████.py :

2024-12-05 15:03:38.981 [info] [Trace - 3:03:38 PM] Received notification 'window/logMessage'.
2024-12-05 15:03:38.982 [info] Params: {
    "type": 4,
    "message": "mypy: Invalid python executable '${env:VIRTUAL_ENV}': No such file or directory\n"
}


2024-12-05 15:03:38.982 [info] mypy: Invalid python executable '${env:VIRTUAL_ENV}': No such file or directory

2024-12-05 15:03:38.983 [info] [Trace - 3:03:38 PM] Received notification 'window/logMessage'.
2024-12-05 15:03:38.983 [info] Params: {
    "type": 4,
    "message": "file:///c%3A/Users/NoahBlum/GitHub/█████████████████████████████████████████████████████████████.py :\r\n"
}


2024-12-05 15:03:38.983 [info] file:///c%3A/Users/NoahBlum/GitHub/█████████████████████████████████████████████████████████████.py :

2024-12-05 15:03:38.984 [info] [Trace - 3:03:38 PM] Received notification 'textDocument/publishDiagnostics'.
2024-12-05 15:03:38.984 [info] Params: {
    "uri": "file:///c%3A/Users/NoahBlum/GitHub/█████████████████████████████████████████████████████████████.py",
    "diagnostics": []
}

Outcome When Attempting Debugging Steps:

Did running it from the command line work? Running in PowerShell seems to work fine.

Extra Details

@nblum-mdmi nblum-mdmi added the bug Issue identified by VS Code Team member as probable bug label Dec 5, 2024
@karthiknadig
Copy link
Member

@nblum-mdmi This will work only if you open VS Code itself from an activated environment. Otherwise,, VS Code will not see VIRTUAL_ENV and won't be able to substitute it.

Try this:

  1. From an external terminal go to your project folder.
  2. Run .\.venv\Scripts\activate
  3. Then run code .

This should start VS Code in an environment that has VIRTUAL_ENV.

@karthiknadig karthiknadig self-assigned this Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed
Projects
None yet
Development

No branches or pull requests

2 participants