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: Validate that Main Interpreter is really a Python interpreter #3842

Merged
merged 11 commits into from
Jan 7, 2017
9 changes: 4 additions & 5 deletions spyder/plugins/maininterpreter.py
Original file line number Diff line number Diff line change
@@ -161,18 +161,17 @@ def python_executable_switched(self, custom):
def is_python_interpreter(self, pyexec):
if not osp.isfile(pyexec):
return False
args = ["-c", "print('valid_python_interpreter')"]
try:
proc = programs.run_program(pyexec, args)
proc = programs.run_program(pyexec, ["-h"])
valid = str(proc.communicate()[0])
if not valid.startswith("b'valid_python_interpreter"):
if len(valid) > 2 and valid[2:].startswith("usage: {}".format(pyexec)):
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 match is still too weak. Please create a more complete function with some of my previous suggestions, add it to utils/programs.py and also add a test for it in utils/tests/test_programs.py

Copy link
Member

@goanpeca goanpeca Dec 21, 2016

Choose a reason for hiding this comment

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

And make sure to test it on Py27, py24 py34 and py35

Copy link
Member

Choose a reason for hiding this comment

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

Especially, I'd like to see a validation for the selected file being a binary

Copy link
Member

Choose a reason for hiding this comment

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

Py34, not 24 ;-)

Copy link
Member

Choose a reason for hiding this comment

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

oops

return True
else:
QMessageBox.warning(self, _('Warning'),
_("You selected an invalid Python interpreter for the "
"console so the previous interpreter will stay. Please "
"make sure to select a valid one."), QMessageBox.Ok)
return False
else:
return True
except:
QMessageBox.warning(self, _('Warning'),
_("You selected an invalid Python interpreter for the console "