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

PR: Improve selection of custom interpreter #7566

Merged
merged 8 commits into from
Aug 10, 2018

Conversation

dalthviz
Copy link
Member

@dalthviz dalthviz commented Jul 27, 2018

Pull Request Checklist

  • Read and followed this repo's Contributing Guidelines
  • Based your PR on the latest version of the correct branch (master or 3.x)
  • Followed PEP8 for code style
  • Ensured your pull request hasn't eliminated unrelated blank lines/spaces,
    modified the spyder/defaults directory, or added new icons/assets
  • Wrote at least one-line docstrings for any new functions
  • Added at least one unit test covering the changes, if at all possible
  • Described your changes and the motivation for them below
  • Noted what issue(s) this pull request resolves, creating one if needed
  • Included a screenshot, if this PR makes any visible changes to the UI

Description of Changes

Improve custom interpreter selection.

imagen

Issue(s) Resolved

Fixes #7529

@ccordoba12
Copy link
Member

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 PathComboBox, so you'd need to create another class called FileComboBox for files.

Besides, you'd need to create another method in SpyderConfigPage that creates and deals with the option selected by users in a FileComboBox.

@dalthviz
Copy link
Member Author

dalthviz commented Jul 28, 2018

A new preview:

imagen

@ccordoba12
Copy link
Member

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.

@dalthviz
Copy link
Member Author

New preview:

imagen

@@ -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')
Copy link
Member

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.

Copy link
Member

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.

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:
Copy link
Member

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.

pyexec_layout.addWidget(pyexec_file)
self.cus_exec_combo = self.create_file_combobox(
_('Recent custom interpreters'),
self.get_option('custom_list'),
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

@@ -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)
Copy link
Member

@ccordoba12 ccordoba12 Jul 30, 2018

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.

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

@dalthviz dalthviz Jul 31, 2018

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?

@@ -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
Copy link
Member

@ccordoba12 ccordoba12 Jul 30, 2018

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.

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)
Copy link
Member

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.

Copy link
Member

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.

@CAM-Gerlach CAM-Gerlach changed the title PR: Improve selection of custom interpreter. PR: Improve selection of custom interpreter Aug 8, 2018
@ccordoba12
Copy link
Member

Ok, let's merge this one. Thanks @dalthviz!

@ccordoba12 ccordoba12 merged commit 77cf810 into spyder-ide:3.x Aug 10, 2018
ccordoba12 added a commit that referenced this pull request Aug 10, 2018
@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented Aug 12, 2018

@ccordoba12 @dalthviz Just tested this on the latest 3.x on Windows 8.1, and there appears to be a UI bug with this: when selecting a new interpreter from the file browser (i.e. rather than choosing it from the dropdown list), and then hitting "Apply" and "OK", just "OK", "Apply" then closing the dialog, etc., the new setting does work (i.e. new consoles are opened in the environment the user selected). However, if I re-open preferences, the interpreter path displayed in the combobox is that of the interpreter I previously had selected before the aforementioned change, rather than the actual one. However, so long as one does not actually interact with this field, making other changes in the preferences and then saving makes the interpreter for new consoles stay the one the user selected, rather than the one displayed, and selecting interperters from the list does make them display correctly in the box once preferences is re-opened.

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.

@ccordoba12
Copy link
Member

@CAM-Gerlach, please open a new issue about it.

@CAM-Gerlach
Copy link
Member

@ccordoba12 In work.

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

Successfully merging this pull request may close these issues.

3 participants