Skip to content

Run Python formatters/linters/... in an environment #14794

Description

Current situation

I have a specific setup for defining my development environment (I use Nix).

What I can do for now is create an environment, which is supposed to have Python, black, flake8, ...
This environment can be built and oaded to the shell using the nix-shell command in the terminal for instance.
I can run python -m black in this shell without issue.

Once the Python environment is built with Nix, it is defined statically, which means that I do have an executable /nix/store/somehash/bin/python that corresponds to my environment (it is actually a wrapper in bash that sets the right environment variables before starting Python).
When I use this Python wrapper, the VS Code Python extension should pickup the same environment and have no issue running for instance the formatter through python -m black for instance.

Feature I would like

I would like the Python extension to either:

  • properly run such a wrapped Python executable bash in order to pickup the environment variables
    or
  • allow the Python extension to run its commands in a shell, for instance the one specified by terminal.integrated.automationShell

Investigation

I did my own investigation, and found out that

the formatter is run using this:

.exec(executionInfo, { cwd, throwOnStdErr: false, token }, document.uri)

return pythonExecutionService.execModule(executionInfo.moduleName!, executionInfo.args, options);

const result = await this.deps.exec(executable.command, executable.args, opts);

public execObservable(file: string, args: string[], options: SpawnOptions = {}): ObservableExecutionResult<string> {

So I guess you spawn the process. Don't know why it doesn't pickup the environment variables the bash Python wrapper defines.

Activity

  1. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Nov 23, 2020
  2. karrtikr commented on Nov 25, 2020

    @karrtikr

    Thanks for the report! We just wanted to quickly acknowledge we received it and we will triage this as soon as we can.

  3. GuillaumeDesforges commented on Dec 16, 2020

    @GuillaumeDesforges
    Author

    I just noticed that the Python extension is able to pick up on the PATH made by Python venv. Would it be possible to allow to customize the hook (e.g. in my case use nix-shell shell.nix instead of source .venv/bin/activate) ? This would also allow to support other tools that provide shells such as Poetry.

  4. karrtikr commented on Dec 16, 2020

    @karrtikr

    Apologies for the late response, the notification got skipped. #8870 should help you out to customize the hook. FWIW we also have #8372 to add poetry support explicitly. Please upvote these issues to bump the priority, closing in favor of that.

  5. ghost removed on Dec 16, 2020
  6. locked as resolved and limited conversation to collaborators on Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-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