Skip to content

Create environment using venv or conda #19848

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

Merged
merged 31 commits into from
Sep 23, 2022

Conversation

karthiknadig
Copy link
Member

@karthiknadig karthiknadig commented Sep 16, 2022

Closes #19676
Closes #19850

@karthiknadig karthiknadig added the feature-request Request for new features or functionality label Sep 16, 2022
@karthiknadig karthiknadig self-assigned this Sep 16, 2022
@karthiknadig karthiknadig added the skip package*.json package.json and package-lock.json don't both need updating label Sep 16, 2022
@@ -549,3 +549,82 @@ export namespace SwitchToDefaultLS {
"The Microsoft Python Language Server has reached end of life. Your language server has been set to the default for Python in VS Code, Pylance.\n\nIf you'd like to change your language server, you can learn about how to do so [here](https://devblogs.microsoft.com/python/python-in-visual-studio-code-may-2021-release/#configuring-your-language-server).\n\nRead Pylance's license [here](https://marketplace.visualstudio.com/items/ms-python.vscode-pylance/license).",
);
}

export namespace CreateEnv {
Copy link
Member Author

Choose a reason for hiding this comment

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

@luabud Strings here need your input.

@karthiknadig karthiknadig marked this pull request as ready for review September 21, 2022 00:49
eleanorjboyd
eleanorjboyd previously approved these changes Sep 21, 2022
Copy link

@karrtikr karrtikr left a comment

Choose a reason for hiding this comment

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

Neatly done, most comments are similar related to wording.

Btw, are we not doing the "show log" hyperlink? @luabud

image


def get_venv_path(name: str) -> str:
if sys.platform == "win32":
return os.fspath(CWD / name / "Scripts" / "python.exe")

Choose a reason for hiding this comment

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

Any documentation for this assumption?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the same assumption we have in the extension. The docs here describe the "Scripts" or "bin" : https://docs.python.org/3/library/venv.html#creating-virtual-environments

Choose a reason for hiding this comment

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

Gotcha.

Maybe still add a one line comment linking the doc? I'm asking because it looks like we actually don't use that assumption in discovery and identification:

function getPyvenvConfigPathsFrom(interpreterPath: string): string[] {
const pyvenvConfigFile = 'pyvenv.cfg';
// Check if the pyvenv.cfg file is in the parent directory relative to the interpreter.
// env
// |__ pyvenv.cfg <--- check if this file exists
// |__ bin or Scripts
// |__ python <--- interpreterPath
const venvPath1 = path.join(path.dirname(path.dirname(interpreterPath)), pyvenvConfigFile);
// Check if the pyvenv.cfg file is in the directory as the interpreter.
// env
// |__ pyvenv.cfg <--- check if this file exists
// |__ python <--- interpreterPath
const venvPath2 = path.join(path.dirname(interpreterPath), pyvenvConfigFile);
// The paths are ordered in the most common to least common
return [venvPath1, venvPath2];
}

and this is the first time.

Copy link
Member Author

Choose a reason for hiding this comment

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

The purpose of the code here and in the discovery is different. In discovery we are tyring to find the .cfg file. in the create env, we created the env, so we know what type it is and where the python.exe will be. I can add the docs nonetheless.

Choose a reason for hiding this comment

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

Yes, I think the comment is misleading:

// envFolder
// |__ pyvenv.cfg  <--- check if this file exists
// |__ python  <--- interpreterPath

It seems to indicate python binary can be directly under the env folder.

Copy link

@karrtikr karrtikr left a comment

Choose a reason for hiding this comment

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

Thanks for addressing, LGTM. I still think we could do the hyperlink to log channel #19848 (review) given it so nicely shows the command progress, otherwise looks good.

@karthiknadig
Copy link
Member Author

I still think we could do the hyperlink to log channel

I will definitely add that in an update.

@karthiknadig karthiknadig merged commit 192c3ea into microsoft:main Sep 23, 2022
@karthiknadig karthiknadig deleted the create_environment branch September 23, 2022 21:57
eleanorjboyd pushed a commit to eleanorjboyd/vscode-python that referenced this pull request Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality skip package*.json package.json and package-lock.json don't both need updating
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Create Environment command. Investigate the possible flow for a Create Environment command
3 participants