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

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

Closed
GuillaumeDesforges opened this issue Nov 21, 2020 · 3 comments
Closed

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

GuillaumeDesforges opened this issue Nov 21, 2020 · 3 comments
Assignees
Labels
feature-request Request for new features or functionality

Comments

@GuillaumeDesforges
Copy link

GuillaumeDesforges commented Nov 21, 2020

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.

@GuillaumeDesforges GuillaumeDesforges added triage-needed Needs assignment to the proper sub-team feature-request Request for new features or functionality labels Nov 21, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Nov 23, 2020
@karrtikr
Copy link

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

@GuillaumeDesforges
Copy link
Author

GuillaumeDesforges commented Dec 16, 2020

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.

@karrtikr
Copy link

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.

@ghost ghost removed the triage label Dec 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

3 participants