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

Add PYTHONPATH to environment variables if the Python extension makes it available #4045

Merged
merged 2 commits into from
Jun 8, 2023

Conversation

mattseddon
Copy link
Member

@mattseddon mattseddon commented Jun 6, 2023

Closes #1791

This PR uses the ms-python.python extension's new API to grab their PYTHONPATH variable and add it to the environment variables used to create DVC processes. In order for users to set this up they need to add a file containing PYTHONPATH=. This can be a .env file at the root of the workspace (default for the extension) or they need to set the python.envFile configuration option.

Demo (fixes issue in magnetic-tiles-defect)

Screen.Recording.2023-06-06.at.4.53.48.pm.mov

@mattseddon mattseddon added the product PR that affects product label Jun 6, 2023
@mattseddon mattseddon self-assigned this Jun 6, 2023
@mattseddon mattseddon added this to In progress in VS Code May 23 via automation Jun 6, 2023
@mattseddon mattseddon marked this pull request as ready for review June 6, 2023 09:36
@@ -77,25 +77,24 @@ export class DvcViewer extends Disposable implements ICli {
}

private viewProcess(name: string, cwd: string, args: Args) {
const options = getOptions({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

const options = getOptions(
this.config.getPythonBinPath(),
this.config.getCliPath(),
const options = getOptions({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

Copy link
Contributor

@julieg18 julieg18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add PYTHONPATH to environment variables if the Python extension makes it available

Is PYTHONPATH moved to stable or is it still deprecated?

@shcheklein
Copy link
Member

In order for users to set this up they need to add a file containing PYTHONPATH=. This can be a .env file at the root of the workspace (default for the extension) or they need to set the python.envFile configuration option.

I'm still lost on why PYTHONPATH is required. #1791 seems to be broader - it's about other envs, other variables, etc. Unless I'm missing something.

@mattseddon
Copy link
Member Author

Add PYTHONPATH to environment variables if the Python extension makes it available

Is PYTHONPATH moved to stable or is it still deprecated?

It has been moved to stable:

@mattseddon
Copy link
Member Author

In order for users to set this up they need to add a file containing PYTHONPATH=. This can be a .env file at the root of the workspace (default for the extension) or they need to set the python.envFile configuration option.

I'm still lost on why PYTHONPATH is required. #1791 seems to be broader - it's about other envs, other variables, etc. Unless I'm missing something.

#1815 is the ticket that spawned #1791. Under #1791 two separate users detailed the same issue (here and here). They want to use relative imports for the modules within their project. By using this API we will respect whatever they've set for PYTHONPATH through either a .env file or the terminal.integrated.env.* settings (details here: https://code.visualstudio.com/docs/python/environments#_use-of-the-pythonpath-variable). Outside of that, no one has really complained about environment activation which leads me to think that this is a good enough solution to close the ticket.

@mattseddon
Copy link
Member Author

We can leave the ticket open but this is still useful IMO.

@mattseddon mattseddon enabled auto-merge (squash) June 8, 2023 23:39
@codeclimate
Copy link

codeclimate bot commented Jun 8, 2023

Code Climate has analyzed commit f401d36 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

The test coverage on the diff in this pull request is 96.7% (85% is the threshold).

This pull request will bring the total coverage in the repository to 95.2% (0.0% change).

View more on Code Climate.

@mattseddon mattseddon merged commit 860a59a into main Jun 8, 2023
7 checks passed
@mattseddon mattseddon deleted the use-python-PYTHONPATH branch June 8, 2023 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product PR that affects product
Projects
No open projects
VS Code May 23
In progress
Development

Successfully merging this pull request may close these issues.

Improve Python environment activation
3 participants