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

vscode resolves paths with .. in them even if the directory doesn't exist / has invalid name #2226

Open
1 task done
DetachHead opened this issue Jan 3, 2022 · 5 comments
Labels
bug Something isn't working P2

Comments

@DetachHead
Copy link

VS Code version

1.63.2

Extension version

2021.12.1559732655

OS type

Windows

OS version

10

Python distribution

python.org

Python version

3.10

Language server

Default

Expected behaviour

error message because the directories did not exist - it should resolve the path the same way the operating system does:
image

Actual behaviour

no error, since it resolves to a directory that does exist: C:\Users\user\basedtyping\

this led to extremely confusing behavior when attempting to link to a typeshed path relative to the python interpreterPath:

{
    "python.analysis.typeshedPaths": [
        "${command:python.interpreterPath}/../../Lib/site-packages/mypy/typeshed"
     ]
}

which seems perfectly valid considering my folder structure is:

C:/users/user/
    basedtyping/
        .venv/
            Scripts/
                python.exe
            Lib/
            site-packages/
                mypy/
                    typeshed/

but instead the log showed this:

typeshedPath c:\Users\user\Lib\site-packages\mypy\typeshed is not a valid directory.

because it turns out python.analysis.typeshedPaths doesn't resolve ${command:python.interpreterPath} at all for some reason, so it was just treated as a directory called "${command:python.interpreterPath}", even though that's not even a valid directory name

Steps to reproduce

  1. in settings.json, set python.analysis.typeshedPaths to a path that doesn't exist:
    {
        "python.analysis.typeshedPaths": ["asdf/asdfasdf"]
    }
  2. go to the "output" tab and selete "Python Language Server"
  3. see the typeshedPath error:
    typeshedPath c:\Users\user\basedtyping\asdf\asdfasdf is not a valid directory.
    
  4. set python.analysis.typeshedPaths to go back up to a directory that does exist by using ..
    {
        "python.analysis.typeshedPaths": ["asdf/asdfasdf/../.."]
    }
  5. go to the "output" tab and selete "Python Language Server"

Logs

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@DetachHead DetachHead changed the title Jan 3, 2022
@ghost ghost assigned karthiknadig Jan 5, 2022
@karthiknadig
Copy link
Member

@DetachHead given the folder structure, I think it will work better if you use the workspaceFolder instead of the command:python.interpreterPath.

{
    "python.analysis.typeshedPaths": [
        "${workspaceFolder}/.venv/Lib/site-packages/mypy/typeshed"
     ]
}

command:python.interpreterPath I resolved in some cases only. You may have to file this request on VS Code since this resolution happens before python extension sees the settings.

@judej pylance should be able to detect that the folder is invalid and show a message that the path in invalid.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Jan 7, 2022
@github-actions github-actions bot added the triage label Jan 7, 2022
@DetachHead
Copy link
Author

given the folder structure, I think it will work better if you use the workspaceFolder instead of the command:python.interpreterPath.

Yeah that’s what I ended up doing for now (it works without the ${workspaceFolder} part tho because it’s already treated as relative to the workspace)

However that’s not ideal since I intend to commit settings.json and there’s no guarantee that everyone else is also using a venv let alone one with that path. Related: #2221

@judej judej added bug Something isn't working P2 labels Jan 10, 2022
@github-actions github-actions bot removed the triage label Jan 10, 2022
@judej
Copy link
Contributor

judej commented Oct 9, 2023

Closing old issue. If this is still a problem, please reopen with the information requested. thanks

@judej judej closed this as completed Oct 9, 2023
@DetachHead
Copy link
Author

@judej what information was requested that I didn't provide? Also I don't have permission to re-open it

@debonte debonte reopened this Oct 10, 2023
@debonte
Copy link
Contributor

debonte commented Oct 10, 2023

@DetachHead, sorry about that, seems we closed this incorrectly when cleaning up old issues.

@bschnurr bschnurr removed their assignment Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2
Projects
None yet
Development

No branches or pull requests

5 participants