Ticket #10555 (needs_work enhancement)
Add services to Sage.app
| Reported by: | iandrus | Owned by: | iandrus |
|---|---|---|---|
| Priority: | major | Milestone: | sage-5.10 |
| Component: | user interface | Keywords: | mac app,services |
| Cc: | kcrisman | Work issues: | |
| Report Upstream: | N/A | Reviewers: | Karl-Dieter Crisman |
| Authors: | Ivan Andrus | Merged in: | |
| Dependencies: | #8473, #11026 | Stopgaps: |
Description
Add services to Sage.app like evaluating Sage code in place and creating a new notebook with selection.
Attachments
Change History
comment:1 Changed 2 years ago by iandrus
- Status changed from new to needs_review
Shoot. Somehow it uploaded 2 copies of the exact same patch. Oh well.
Apply trac_10555-extcode.patch requires #8473
comment:3 follow-up: ↓ 4 Changed 2 years ago by kcrisman
I'm not sure exactly what's been added here - I always find the code for the app inscrutable, no thanks to Apple, I guess. What things should one test here? (A list of all things added would be great, maybe some typical use cases.)
comment:4 in reply to: ↑ 3 Changed 2 years ago by iandrus
Replying to kcrisman:
I'm not sure exactly what's been added here - I always find the code for the app inscrutable, no thanks to Apple, I guess. What things should one test here? (A list of all things added would be great, maybe some typical use cases.)
I thought I had added the documentation, but it's in another repository, so it needs a different patch. *sigh*
I think most of them (and their use cases) are fairly self-explanatory, at least after you read the documentation. If not, then please let me know.
One potential problem is having more than one Sage.app and it getting confused about which version it should use for the service. Actually, I'll add that to the documentation... I'm not sure of a work around at the moment.
comment:6 Changed 11 months ago by kcrisman
#8473 is solved, see the sagenb upstream pull request.
Putting this to "needs info" because I don't know whether this patch will be compatible with the new notebook.
comment:8 Changed 11 months ago by kcrisman
- Status changed from needs_review to needs_work
- Reviewers set to Karl-Dieter Crisman
On Mac OS 10.6 you will have to enable those you wish to use in System Preferences > Keyboard > Keyboard Shortcuts > Services.
I can't get this to work. I thought maybe it was because I had multiple Sages, but even deleting them (though not emptying the Trash) didn't help. Maybe I'm doing something not quite right. Perhaps the instructions aren't as complete as they need to be.
But otherwise the infrastructure for this seems to be right on track! Putting as 'needs work', but feel free to correct me if I just forgot something.
comment:9 follow-up: ↓ 10 Changed 10 months ago by iandrus
- Milestone changed from sage-5.3 to sage-5.1
I think it might be related to having several Sage.app's and some don't have the services. In particular if you build a new version I don't think it always picks up changes (because of caching), especially if the version number hasn't changed. If you are building in Xcode rather than with sage -bdist the version wouldn't change. You might consider restarting, or just running /System/Library/CoreServices/pbs which should rebuild the services list. If that works, then we should probably add it to the README.
comment:10 in reply to: ↑ 9 ; follow-up: ↓ 11 Changed 10 months ago by kcrisman
Replying to iandrus:
I think it might be related to having several Sage.app's and some don't have the services. In particular if you build a new version I don't think it always picks up changes (because of caching), especially if the version number hasn't changed. If you are building in Xcode rather than with sage -bdist the version wouldn't change. You might consider restarting, or just running /System/Library/CoreServices/pbs which should rebuild the services list. If that works, then we should probably add it to the README.
Okay, I'll try this. It will take a while because of having to do the restart or whatever.
But will this patch still work, or does it need rebasing on #11026?
Changed 10 months ago by iandrus
-
attachment
trac_10555-extcode.patch
added
Updating for changes to 8473
comment:11 in reply to: ↑ 10 Changed 10 months ago by iandrus
comment:12 follow-up: ↓ 13 Changed 10 months ago by kcrisman
- Milestone changed from sage-5.1 to sage-5.3
or just running /System/Library/CoreServices/pbs which should rebuild the services list. If that works, then we should probably add it to the README.
Awww yeahhhh. Yup, this works, so you definitely should add this to the instructions.
Unfortunately, apparently it has trouble deciding on an app. I highlighted some text (2+2), right-clicked, chose preparse, and got
Running... /Users/.../sage-4.4.4-mcbc/data/extcode/sage/ext/mac-app/Sage.app/Contents/Resources/script: line 14: cd: /tmp/sage-map-app: No such file or directory Setting environment variables /Users/.../sage-4.4.4-mcbc/data/extcode/sage/ext/mac-app/Sage.app/Contents/Resources/script: line 18: ./local/bin/sage-env: No such file or directory
I didn't even know I had a Sage app in there! And in fact, I don't - I just have the usual data/extcode stuff. This was a surprise. Yes, I have the correct binary picked for the actual existing Sage app (I used it to test #10556 just now and which sage was always what it was supposed to be).
Moving this binary off the Desktop and into Downloads fixed the problem. Not sure what that was about. But if you can't even have a command-line Sage somewhere around for this, that's a little different from the other issues we've seen with multiple Sage.app's.
Trying the services:
- Preparse was almost eery. Seemed to work fine.
- Trying to evaluate 2+3 and replace it:
The “Evaluate Code in Sage (and replace)” service could not be used because the “Sage-click-path-services” application did not provide valid data. Try using the service differently, or contact the vendor for an updated version of “Sage-click-path-services.”
Whether the server was on or not did not seem to matter. Oh wait, I needed to use print ... well, maybe that should be even bigger? Is it possible to detect the word print? Or maybe since we don't really do that with the menu shortcut we don't need to here. What do you think?
- With trying to get it to execute in a new terminal session:
sage: arrow2d(headpoint=None, tailpoint=None); exit 'Use Ctrl-D (i.e. EOF), %Exit, or %Quit to exit without confirmation.' sage:
Wow! Where did that come from? I know that sort of message has been bandied about elsewhere - has that been built in all the time in the app? I haven't seen it in prior testing, that I recall, though that was a long time ago. Awesome. Except for the fact that in this case it doesn't actually exit, since it's inside Sage. That probably will need a little tweaking.
- As for trying the new worksheet file, this didn't seem to work as well.
http://localhost:8000/upload_worksheet?url=file://localhost/var/folders/Yy/YytEJm5VEB0+pBRD7JNLe++++TQ/-Tmp-/sage.fp5w.txt
never opened, it just sat like a bump in the browser URL area.
- Uncompressing Sage packages is weird. It creates the directory, but with a [space]2 after it. This also causes problems in compressing.
- Unpacking spkg command just quits mid-word in the "preview of command" popup (I really like this in these things) and there is no scroll bar to indicate it goes on. You have to pull on the popup window and make it bigger.
And then there is this issue.
/Users/.../sage-5.1.beta1-flask/sage --pkg_nc /Users/.../brian-1.2.1.p0 2
which clearly isn't going to work, because there is no brian-1.2.1.p0, there is only brian-1.2.1.p0\ 2. Whatever escaping I do, I then get this error message that you shouldn't have weird characters anyway, and then it tells me also that 2.spkg can't be created. And then even when I make a normal thing, I getCreating Sage package /Users/.../brian-1.2.1.p1 tar: brian-1.2.1.p1: Cannot stat: No such file or directory tar: Error exit delayed from previous errors. Created package brian-1.2.1.p1.spkg. NAME: brian VERSION: 1.2.1.p1 SIZE: 0K HG REPO: Error reading repository SPKG.txt: File is missingi.e. this part is broken, because I shouldn't have to think to use it. - What sort of files should give the service for testing? I can't get it for .rst or .py files. Maybe that's because I don't have Sage as the "default open" for such files. It does work for folders. It does work for .sage files. But you'd think that even for things that weren't default to open in Sage.app, they should still do what I ask.
Overall, it looks cool. I certainly now think that Services are useful in general! Hadn't really tried much before. But I don't know that these services are quite ready for prime-time yet.
comment:13 in reply to: ↑ 12 Changed 10 months ago by iandrus
Replying to kcrisman:
or just running /System/Library/CoreServices/pbs which should rebuild the services list. If that works, then we should probably add it to the README.
Awww yeahhhh. Yup, this works, so you definitely should add this to the instructions.
Done.
Unfortunately, apparently it has trouble deciding on an app. I highlighted some text (2+2), right-clicked, chose preparse, and got
Running... /Users/.../sage-4.4.4-mcbc/data/extcode/sage/ext/mac-app/Sage.app/Contents/Resources/script: line 14: cd: /tmp/sage-map-app: No such file or directory Setting environment variables /Users/.../sage-4.4.4-mcbc/data/extcode/sage/ext/mac-app/Sage.app/Contents/Resources/script: line 18: ./local/bin/sage-env: No such file or directoryI didn't even know I had a Sage app in there! And in fact, I don't - I just have the usual data/extcode stuff. This was a surprise. Yes, I have the correct binary picked for the actual existing Sage app (I used it to test #10556 just now and which sage was always what it was supposed to be).
Moving this binary off the Desktop and into Downloads fixed the problem. Not sure what that was about. But if you can't even have a command-line Sage somewhere around for this, that's a little different from the other issues we've seen with multiple Sage.app's.
Yes, this is a big problem. That's an old Sage! IIRC I used to include a Sage.app that wasn't fully functional, and then just replaced a few things instead of building it. So old versions of Sage can be a problem. Choosing which Sage.app to use is problematic in general though. AFAICT it's not documented anywhere and subject to change etc. I think it's supposed to use the one with the biggest version, but if you build in Xcode the version is just SAGE_VERSION. In my experience it will use a running app over one that's not running.
You can find all versions of Sage.app on your system with
mdfind "kMDItemCFBundleIdentifier == 'org.sagemath.Sage'"
perhaps that should be documented. I would like to have some concrete suggestions before I document it though.
Trying the services:
- Preparse was almost eery. Seemed to work fine.
Eery in what way? A good way?
- Trying to evaluate 2+3 and replace it:
The “Evaluate Code in Sage (and replace)” service could not be used because the “Sage-click-path-services” application did not provide valid data. Try using the service differently, or contact the vendor for an updated version of “Sage-click-path-services.”Whether the server was on or not did not seem to matter. Oh wait, I needed to use print ... well, maybe that should be even bigger? Is it possible to detect the word print? Or maybe since we don't really do that with the menu shortcut we don't need to here. What do you think?
Hmm. It didn't cause an error for me. Do you see anything in Console.app? As for requiring print, I agree. I just call sage -c. It's hard though because you may not want to see all the output from a longer session, and just adding print won't work if there is more than one statement. I don't suppose long chunks of code is a primary use case though.
- With trying to get it to execute in a new terminal session:
sage: arrow2d(headpoint=None, tailpoint=None); exit 'Use Ctrl-D (i.e. EOF), %Exit, or %Quit to exit without confirmation.' sage:Wow! Where did that come from? I know that sort of message has been bandied about elsewhere - has that been built in all the time in the app? I haven't seen it in prior testing, that I recall, though that was a long time ago. Awesome. Except for the fact that in this case it doesn't actually exit, since it's inside Sage. That probably will need a little tweaking.
I didn't see that because I use the "don't exit" variant. I don't think it should be that hard to fix, though perhaps a bit ugly.
- As for trying the new worksheet file, this didn't seem to work as well.
http://localhost:8000/upload_worksheet?url=file://localhost/var/folders/Yy/YytEJm5VEB0+pBRD7JNLe++++TQ/-Tmp-/sage.fp5w.txtnever opened, it just sat like a bump in the browser URL area.
It's not getting URL encoded. I'll fix that.
- Uncompressing Sage packages is weird. It creates the directory, but with a [space]2 after it. This also causes problems in compressing.
Okay I see that too. I know it worked before, so I wonder what changed.
- Unpacking spkg command just quits mid-word in the "preview of command" popup (I really like this in these things) and there is no scroll bar to indicate it goes on. You have to pull on the popup window and make it bigger.
I have to admit, I don't know what you are talking about with the "preview of command" popup. Are you on Lion? Maybe they added something wrt services.
And then there is this issue.
/Users/.../sage-5.1.beta1-flask/sage --pkg_nc /Users/.../brian-1.2.1.p0 2which clearly isn't going to work, because there is no brian-1.2.1.p0, there is only brian-1.2.1.p0\ 2. Whatever escaping I do, I then get this error message that you shouldn't have weird characters anyway, and then it tells me also that 2.spkg can't be created. And then even when I make a normal thing, I get
Creating Sage package /Users/.../brian-1.2.1.p1 tar: brian-1.2.1.p1: Cannot stat: No such file or directory tar: Error exit delayed from previous errors. Created package brian-1.2.1.p1.spkg. NAME: brian VERSION: 1.2.1.p1 SIZE: 0K HG REPO: Error reading repository SPKG.txt: File is missingi.e. this part is broken, because I shouldn't have to think to use it.
Okay, I probably never tried it with spaces in the name. Thanks
- What sort of files should give the service for testing? I can't get it for .rst or .py files. Maybe that's because I don't have Sage as the "default open" for such files. It does work for folders. It does work for .sage files. But you'd think that even for things that weren't default to open in Sage.app, they should still do what I ask.
Which service? The creating an spkg service? That should only show up for directories.
Thanks for all the testing, I know it's a thankless job and I'm sorry nothing works. :-( I'm not sure when I can get to fixing these since I _really_ need to work on my thesis and they probably aren't simple fixes.
comment:14 Changed 10 months ago by kcrisman
I'm not sure when I can get to fixing these since I _really_ need to work on my thesis and they probably aren't simple fixes.
Then you should forget about it. This is much lower priority, since one can just do cut and paste and open it. #11026 was so much more awesome than anything here. When you finish your degree you'll have time for this... or maybe not ;-)
