-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PR: Improve selection of custom interpreter #7566
Conversation
Very nice @dalthviz! However, I'd like to have something similar to the working directory toolbar: a combobox to be able to enter by hand or with a file dialog a Python interpreter. The one in the working directory is called Besides, you'd need to create another method in |
Much, much better! Thanks @dalthviz! One last thing: Could you hide and/or remove the validation widget next to the file name (i.e. the one with the blue check mark)? Then I'd say this is ready. |
…t in the file combobox.
spyder/plugins/maininterpreter.py
Outdated
@@ -222,5 +230,20 @@ def set_umr_namelist(self): | |||
fixed_namelist = [] | |||
self.set_option('umr/namelist', fixed_namelist) | |||
|
|||
def set_custom_interpreters_list(self, executable): | |||
"""Update the list of interpreters used and the current one.""" | |||
custom_list = self.get_option('custom_list') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a method that takes this list and verifies the entries that still exist (with a simple osp.isfile
). The ones that don't need to be removed and a new list of interpreters needs to be saved with set_option
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this probably doesn't need to be done here, but above, where you create the filecombobox.
spyder/plugins/maininterpreter.py
Outdated
def set_custom_interpreters_list(self, executable): | ||
"""Update the list of interpreters used and the current one.""" | ||
custom_list = self.get_option('custom_list') | ||
if (executable, executable) not in custom_list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks confusing, i.e. naming two variables with the same name (execuatble
, executable
). Please change that.
spyder/plugins/maininterpreter.py
Outdated
pyexec_layout.addWidget(pyexec_file) | ||
self.cus_exec_combo = self.create_file_combobox( | ||
_('Recent custom interpreters'), | ||
self.get_option('custom_list'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here, before setting the custom list of interpreters, we need to validate that they still exist and remove the ones that don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to do the validation in the __init__
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that's ok too.
spyder/plugins/maininterpreter.py
Outdated
@@ -53,10 +54,11 @@ def __init__(self, parent, main): | |||
# the Python executable has already been set with pythonw.exe: | |||
self.set_option('executable', | |||
executable.replace("pythonw.exe", "python.exe")) | |||
self.set_custom_interpreters_list(executable, executable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be
if not self.get_option('default'):
self.set_custom_interpreters_list(executable, executable)
because we don't want the default interpreter to be part of the list of custom ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After trying this change I notice that we need at least one entry in the combobox. If not this triggers and error when loading the config (since there is no option to give to the current index in the combobox). The line where this happens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmh, I don't like this because the default interpreter is going to be part of the list of custom ones too. Besides, users would find strange that there's one entry in the custom interpreters list if they haven't selected none.
Couldn't you find a way to make configdialog
work with no interpreter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could add a validation in configdialog
on the line that I linked above to not raise and error, and also change a statement in python_executable_changed
since currently if an invalid interpreter is found it will put the default one as an option, and fallback to select the default interpreter option when the settings are applied with an empty custom interpreter probably.
Should I do this changes?
spyder/plugins/maininterpreter.py
Outdated
@@ -152,6 +161,7 @@ def python_executable_changed(self, pyexec): | |||
"make sure to select a valid one."), QMessageBox.Ok) | |||
self.pyexec_edit.setText(def_pyexec) | |||
return | |||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make this method to return True
at the end, then you need to change the behavior of the previous return
's to be return False
, and not simply return
(as it is right now). That's to be consistent.
spyder/plugins/maininterpreter.py
Outdated
if (display_value, value) not in custom_list: | ||
custom_list.append((display_value, value)) | ||
self.set_option('custom_list', custom_list) | ||
self.set_option('executable', value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line shouldn't be here but applied after this method is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true specially due to the comment I left in the __init__
method.
Ok, let's merge this one. Thanks @dalthviz! |
@ccordoba12 @dalthviz Just tested this on the latest Also, conversely, when selecting one or multiple new interpreters from the file browser dialog that aren't currently in the list, their path(s) is (are) not added to the list, even if the Apply button is clicked to set them, until the preferences dialog is closed and re-opened. |
@CAM-Gerlach, please open a new issue about it. |
@ccordoba12 In work. |
Pull Request Checklist
modified the
spyder/defaults
directory, or added new icons/assetsDescription of Changes
Improve custom interpreter selection.
Issue(s) Resolved
Fixes #7529