10000 Leverage ms-python.python extension to resolve python interpreter path automatically by hackenbergstefan · Pull Request #39 · afri-bit/vsconan · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Leverage ms-python.python extension to resolve python interpreter path automatically #39

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 3 commits into from
Aug 2, 2024

Conversation

hackenbergstefan
Copy link
Contributor

If the ms-python.python extension is installed (which is true for most developers, I guess) VSConan can automatically resolve the Python interpreter path and Conan executable using the currently activated Python Environment.

@hackenbergstefan
< 10000 div class="timeline-comment-actions flex-shrink-0 d-flex flex-items-center">
Copy link
Contributor Author

Hi @afri-bit,
it looks like a lot of changes... But indeed, it's "just" changing some functions to async as resolution of Python interpreter is async.

@afri-bit
Copy link
Owner

Hi @hackenbergstefan,

sorry for the delayed reply, I was on vacation, I don't usually touch my computer during my vacation :)

Thanks for the pull request, I will take a look and come back to you :)

@hackenbergstefan
Copy link
Contributor Author

Hey @afri-bit,
did you already have time to review? 🙃

@afri-bit
Copy link
Owner

hi @hackenbergstefan,
sorry for the delay, i didn't expect my work to be more stressful after my holiday, but I will take a look at your PR and come back to you this week.

Copy link
Owner
@afri-bit afri-bit left a comment

Choose a reason for hiding this comment

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

Thanks again for the PR, sorry again for the delay.

Just reviewed you PR, please refer to the comments in the PR

@@ -108,17 +108,28 @@ export class SettingsPropertyManager {
profileObject = general.plainObjectToClass(ConanProfileConfiguration, selectedProfileObject);
}

let pythonInterpreter = await python.getCurrentPythonInterpreter();
if (pythonInterpreter !== undefined) {
Copy link
Owner

Choose a reason for hiding this comment

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

Need an if statement before entering this section, since the profileObject might be undefined, it leads to error in case of the undefined object, when you want to set the value to its attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tink profileObject?. already checks for undefined or none. But I'm not a typescript expert. At least the description explains like that: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#optional-chaining

Copy link
Owner
@afri-bit afri-bit Aug 1, 2024

Choose a reason for hiding this comment

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

I was expecting the same output as in the explanation but apparently the it didn't do the things as expected.
stack trace: TypeError: Cannot set properties of undefined (setting 'conanPythonInterpreter')

I would suggest to remove the ! and ? assertion from the profileObject and surround the whole code with simple if condition before entering the section of entering the python interpreter, see code below. With this we can make sure that it will return undefined in case the object doesn't exist

.
.
if(profileObject) {
    let pythonInterpreter = await python.getCurrentPythonInterpreter();
    if (pythonInterpreter !== undefined) {
        ...
    }
}

return profileObject

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not smart enough :P The if (! was the problem. profileObject? evaluates to false so if (!profileObject?...) is true 🤦‍♂️

profileObject!.conanPythonInterpreter = pythonInterpreter;
}
if (!profileObject?.conanExecutable) {
profileObject!.conanExecutable = path.join(path.dirname(pythonInterpreter), "conan");
Copy link
Owner

Choose a reason for hiding this comment

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

This might work in case of virtual environment, in case of system wide python, the path where conan executable is located, is completely in different place.
I would suggest to check if the conan binary exist after building the path, otherwise set to empty string as before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:+1

}
}

console.log(profileObject);
Copy link
Owner

Choose a reason for hiding this comment

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

Remove this line before merging later on :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ups :-D

let pythonInterpreter = await python.getCurrentPythonInterpreter();
if (pythonInterpreter !== undefined) {
if (!profileObject?.conanPythonInterpreter) {
profileObject!.conanPythonInterpreter = pythonInterpreter;
Copy link
Owner

Choose a reason for hiding this comment

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

As far as i understood, is that this line of code will be used, in case the user doesn't set the python interpreter inside the configuration, so the extension will be smart enough to get the python interpreter from the python extension, really nice

But we must provide the visibility of this information to the user, from where the python interpreter is used during the usage of the extension, otherwise, user might be confused due to hidden information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you suggest? Mentioning in the README and printing the value of pythonInterpreter on the extension's output.

Copy link
Owner

Choose a reason for hiding this comment

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

  • README is definitely the first step
  • The extension output is also good to show it there (I see you already did that 😃)

I am thinking to put the information maybe in the tooltip information from the toolbar where the selected profile is shown. But if the two bullet points from above are there, i think we can move on.

I will take care of the rest, since it is more or less nice to have before the user gets confused, where the extension takes the python interpreter from 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the tooltip idea! :-)
I've implemented.

Copy link
Owner
@afri-bit afri-bit left a comment

Choose a reason for hiding this comment

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

@hackenbergstefan
Approved 👍 Thanks for the contribution

@afri-bit afri-bit merged commit 930e458 into afri-bit:main Aug 2, 2024
@hackenbergstefan
Copy link
Contributor Author

Thanks for merging! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0