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

Fixes #2306: Add a restart method #2312

Merged
merged 5 commits into from
Apr 21, 2015
Merged

Fixes #2306: Add a restart method #2312

merged 5 commits into from
Apr 21, 2015

Conversation

goanpeca
Copy link
Member

@goanpeca goanpeca commented Apr 9, 2015

Fixes #2306

Description

Add a restart method. Used the restart image as the ones used by the consoles. The shortcut for restarting is set as Shift+Alt+R.

Tasks

  • Windows (Py2 & Py3) (Tested on Windows 7)
  • Linux (Py2 & Py3) (Tested on Ubuntu 14.04)
  • OSX (Py2 & Py3)

@goanpeca goanpeca changed the title Add restart method and shortcut to Spyder Add restart method and shortcut to Spyder. Solves #2306 Apr 9, 2015
@goanpeca goanpeca changed the title Add restart method and shortcut to Spyder. Solves #2306 Add restart method and shortcut to Spyder. Apr 9, 2015
@goanpeca goanpeca added this to the v3.0 milestone Apr 9, 2015

if any([not spyder_args, not pid, not is_bootstrap, not spyder_folder]):
error = "This script can only be called from within a Spyder instance"
raise Exception(error)
Copy link
Contributor

Choose a reason for hiding this comment

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

RuntimeException is maybe cleaner

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes sure

@goanpeca
Copy link
Member Author

@Nodd, I included your suggestions and completed support on Linux and Windows. Still need Mac check and python3 check.

There is no way around the shell = True on Linux, at least the way I did this PR, but it works as expected, you do not see any terminals when restarting from the installed app, and if running from a terminal on bootstrap mode, the new instance gets run in that same terminal (which is what I would expect)

@Nodd
Copy link
Contributor

Nodd commented Apr 10, 2015

shell=True is not a problem per se, but it's usually better to avoid it when possible.

@goanpeca
Copy link
Member Author

@Nodd, indeed I understand

The docs say:

"Warning Using shell=True can be a security hazard. See the warning under Frequently Used Arguments for details."

But I do not think the example they give as a security hazard applies to this case in particular.

@goanpeca goanpeca changed the title Add restart method and shortcut to Spyder. Implement #2306: Add restart method and shortcut to Spyder Apr 10, 2015
@goanpeca goanpeca changed the title Implement #2306: Add restart method and shortcut to Spyder Implement #2306: Add a restart method to Spyder Apr 10, 2015
@Nodd
Copy link
Contributor

Nodd commented Apr 10, 2015

It's also a bit slower but it doesn't apply here either.

system = platform.system().lower()

startupinfo = None
if 'win' in system:
Copy link
Contributor

Choose a reason for hiding this comment

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

This picks up darwin, you can use win32 here or put darwin first.

@blink1073
Copy link
Contributor

I tested this on OSX. It works after I made the two changes highlighted above.

@goanpeca
Copy link
Member Author

Thanks @blink1073 😄

Did you check with python3 as well? I will push the changes shortly

@goanpeca
Copy link
Member Author

Ok so I checked with Py3 on linux as well and made corrections as suggested by @blink1073.

Thanks @blink1073, and @Nodd for comments 😸

Any suggestions/comments/concerns @ccordoba12?

@blink1073
Copy link
Contributor

@goanpeca, I had used Python 3. Python 2 works now as well on OSX.

@goanpeca
Copy link
Member Author

@blink1073 Ok great, then I guess is up to @ccordoba12 and @SylvainCorlay now ;-) to give some feedback

@goanpeca goanpeca changed the title Implement #2306: Add a restart method to Spyder Implements #2306: Add a restart method to Spyder Apr 11, 2015
@goanpeca goanpeca changed the title Implements #2306: Add a restart method to Spyder Implements #2306: Add a restart method Apr 11, 2015
@goanpeca
Copy link
Member Author

@ccordoba12, have you had time to check this?

@@ -477,6 +477,7 @@ def is_ubuntu():
'_/save current layout': "Shift+Alt+S",
'_/toggle default layout': "Shift+Alt+Home",
'_/layout preferences': "Shift+Alt+P",
'_/restart': "Shift+Ctrl+R",
Copy link
Member

Choose a reason for hiding this comment

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

Shift+Ctrl+<foo> is used to focus plugins. Could you think of a different shortcut?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I can try... @Nodd, ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

Shift+Ctrl+Alt+AltGr+Meta+R ?
A bit more seriously, the other shortcuts use Shift+Alt, so it should be OK.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ctrl+Shift+Alt+R ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Shift+Alt+R only ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.. why not, @ccordoba12 ?

Copy link
Member

Choose a reason for hiding this comment

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

That's ok for me

@ccordoba12
Copy link
Member

Ok, first (quick) review is over :-)

try:
subprocess.Popen(command, shell=shell, env=env,
startupinfo=startupinfo)
self.console.quit()
Copy link
Member Author

Choose a reason for hiding this comment

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

@ccordoba12 here is where it is closed

Copy link
Member

Choose a reason for hiding this comment

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

Ok, thanks for pointing it out! ;-)

But why not call self.closing() instead of self.console.quit()? That's the method I was looking for in my review :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops... Got it

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm @ccordoba12, self.closing() return True, or False... but does not close... so how does it work?

@goanpeca goanpeca changed the title Implements #2306: Add a restart method Fixes #2306: Add a restart method Apr 19, 2015
@goanpeca
Copy link
Member Author

@ccordoba12, made suggested corrections

@goanpeca goanpeca self-assigned this Apr 19, 2015

# Maybe --new-instance should always be included to cope with corner cases
# where someone has one running version without and and another with
# If the user the one without (--new...) it would not start
Copy link
Member

Choose a reason for hiding this comment

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

Do you plan to address this comment?

Also, could reworded a bit? It's not easy to understand what it means :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think it is a good idea to enforce upon restart the use of new instance? to avoid any weird cases? For most use cases it wont make a difference, but if for some reason people are using that option, then it would help.

Thoughts?

@ccordoba12
Copy link
Member

New review done :-) This is shaping nicely!

@goanpeca
Copy link
Member Author

@ccordoba12 added latest suggestions ;-)

env['SPYDER_ARGS'] = spyder_args
env['SPYDER_PID'] = str(pid)
env['SPYDER_IS_BOOTSTRAP'] = str(is_bootstrap)
env['SPYDER_FOLDER'] = spyder_folder
Copy link
Member

Choose a reason for hiding this comment

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

It seems to me there is no need to pass SPYDER_FOLDER as an env var because it can be computed from the __file__ attribute of spyder_restart.py.

Copy link
Member

Choose a reason for hiding this comment

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

The other env vars are fine by the way :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

True!

@goanpeca
Copy link
Member Author

@ccordoba12 added latest suggestions.

import sys
import time

from spyderlib.py3compat import to_text_string
Copy link
Member

Choose a reason for hiding this comment

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

I just tested this PR and it's not working with bootstrap because of this line.

The thing is this assumes Spyder is installed in your virtualenv or globally. But that's almost always not true (at least for me :-), when you're using bootstrap.

The only alternative I see is to copy/paste to_text_string here and use it below. It's a simple function, so I don't see any problem with that :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, fixed!

@goanpeca
Copy link
Member Author

@ccordoba12 can you check again :-) ?

@ccordoba12
Copy link
Member

Great! This is working for me now :-)

ccordoba12 added a commit that referenced this pull request Apr 21, 2015
Add restart functionality to the application
@ccordoba12 ccordoba12 merged commit 3e619c4 into spyder-ide:master Apr 21, 2015
@goanpeca goanpeca deleted the restart branch April 21, 2015 21:36
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.

Enhancement: Add restart functionality to spyder.
5 participants