Skip to content

Improve configuration for search paths  #6544

Closed

Description

Parts of this question was already answered several times, so be patient when reading. :)
Our usual workspace structure is:

rootDir/:
    - project.vscode-workspace
    - sources/:
        - main.py
        - someSrcFile.py
        - ...
        - common/:
            - commFileOne.py
            - ...

Nothing unusual here.
Than, we have another folder with common python modules in remote location - this location is added by modules (inserting to sys.path). I will call this location remoteDir.

<some remote location>
remoteDir/:
    - remoteModule.py
    - ...

When running main.py from VS Code, we specify launch configuration with cwd changed to rootDir/sources. It runs OK, files from common and remoteDir are accessible (since sys.path is manually modified).

To implement autocomplete (either Intellisense Python Language Server or JEDI) and Pylint, this directories are not seen by default - .vscode-workspace file is not in sources folder. I am aware of PYTHONPATH variable in .env file - I added sources and remoteDir to PYTHONPATH variable and VS Code autocomplete and pylint works as expected.

The problem is that this PYTHONPATH variable affects the code and is bound to this IDE, which I don't like - one could easily develop code with VS Code (which has specified PYTHONPATH) and forget to handle sys.path, not knowing that the code now can't be executed without this IDE and it's .env settings.
Example: A newbie come to our department, take prepared VS Code workspace and create a new module in common folder, which must be executed also in standalone mode. In this module, he wants to use functions from remoteDir. Since PYTHONPATH is already set in .env, he doesn't know that he actually have to manually handle sys.path - autocomplete and pylint just works out of the box. Also, using VS Code, he can run main.py or his new script without problems. But, if he (or someone else) run this script from a command line: cd ./sources/common; python hisCommonFile.py, this will fail. Why - because nothing specify PYTHONPATH variable, and he doesn't have sys.path handled properly.

The question is: how to properly configure folder paths for autocomplete and pylint in VS Code, that wouldn't have any effect on how code is executed? I don't expect autocomplete and linter would interactively resolve modified sys.path - seems like there should be something similar to PYTHONPATH, but would be only applied to autocomplete/pylint VS Code tasks, not launch configurations.

Just for a clarification: I know this might be a silly example. Our case is a little more complex than described above, but the problem is somewhat simillar - I miss includeFolders=[] in both autocomplete and pylint settings section, or better, some common settings. autocomplete.extraPaths only solve problems for autocomplete (if it is working, last time I was checking It didn't work properly), not pylint - again, duplicated settings.

Activity

  1. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Jul 11, 2019
  2. brettcannon commented on Jul 31, 2019

    @brettcannon
    Member

    Thank you for the suggestion! We have marked this issue as "needs decision" to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many 👍 votes your idea gets to help us make our decision.

  3. removed their assignment
    on Sep 19, 2019
  4. changed the title [-]Workspace settings, autocomplete, pylint and environment settings [/-] [+]Improve configuration for search paths [/+] on Jul 8, 2020
  5. removed their assignment
    on May 12, 2022
  6. luabud commented on Dec 14, 2023

    @luabud
    Member

    Karthik Nadig (@karthiknadig) correct me if I'm wrong but I believe this may be possible now with the following extensions and settings:

  7. karthiknadig commented on Dec 14, 2023

    @karthiknadig
    Member

    Pylint extension automatically adds paths from python.analysis.extraPaths to PYTHONPATH when running pylint.

  8. luabud commented on Dec 14, 2023

    @luabud
    Member

    Awesome, thanks!

    I think this can be closed now but let us know if you still have any issues and we can reopen :)

  9. locked as resolved and limited conversation to collaborators on Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-editor-*User-facing catch-allfeature-requestRequest for new features or functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions