Opened 7 years ago

Closed 8 months ago

#10555 closed enhancement (wontfix)

Add services to Sage.app

Reported by: iandrus Owned by: iandrus
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: user interface Keywords: mac app, services
Cc: kcrisman Merged in:
Authors: Reviewers: Karl-Dieter Crisman, Ivan Andrus
Report Upstream: N/A Work issues:
Branch: u/iandrus/mac-app-services (Commits) Commit: 9ba2de3cc00ccb2269c5a2348117dc3d824d06ff
Dependencies: Stopgaps:

Description

Add services to Sage.app like evaluating Sage code in place and creating a new notebook with selection.

Attachments (3)

trac_10555-extcode.2.patch (17.9 KB) - added by iandrus 7 years ago.
trac_10555-scripts.patch (2.3 KB) - added by iandrus 7 years ago.
trac_10555-extcode.patch (16.5 KB) - added by iandrus 6 years ago.
Updating for changes to 8473

Download all attachments as: .zip

Change History (31)

Changed 7 years ago by iandrus

comment:1 Changed 7 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:2 Changed 7 years ago by kcrisman

  • Cc kcrisman added

comment:3 follow-up: Changed 7 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 7 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.

Changed 7 years ago by iandrus

comment:5 Changed 7 years ago by kcrisman

  • Dependencies set to #8473, #11026

This depends on #8473 and #11026.

comment:6 Changed 6 years 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:7 Changed 6 years ago by iandrus

This patch should be fine. It only depends on #8473 for the "new notebook with selection" service. What it does is create a temporary txt file and then upload it to the server using the functionality of #11026.

comment:8 Changed 6 years ago by kcrisman

  • Reviewers set to Karl-Dieter Crisman
  • Status changed from needs_review to needs_work
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: Changed 6 years 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: Changed 6 years 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 6 years ago by iandrus

Updating for changes to 8473

comment:11 in reply to: ↑ 10 Changed 6 years ago by iandrus

Replying to kcrisman:

Replying to iandrus:

But will this patch still work, or does it need rebasing on #11026?

IIRC it applied with some fuzz, but I rebased it.

comment:12 follow-up: Changed 6 years 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 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 missing
    
    i.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 6 years 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 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.

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.txt
    
    never 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 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 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 missing

i.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 6 years 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 ;-)

comment:15 Changed 5 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:16 Changed 4 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:17 Changed 4 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:18 Changed 4 years ago by iandrus

  • Branch set to u/iandrus/mac-app-services
  • Commit set to 1fba3ee752aafb924a113edd81634f6d6e7dd2ee
  • Dependencies changed from #8473, #11026 to #15732

This is just a port of the changes I had before to the git workflow. I haven't yet tried to fix anything.


New commits:

ec5e1a9Ignore files from XCode
dcb6660Added files from new XCode
6eebbcdFixed a warning
eb13458Ensure that Sage is read/write
1fba3eeAdded services

comment:19 Changed 4 years ago by git

  • Commit changed from 1fba3ee752aafb924a113edd81634f6d6e7dd2ee to 64b793848e4e392673804335c4284d673f43a952

Branch pushed to git repo; I updated commit sha1. New commits:

64b7938Added documentation for services

comment:20 Changed 4 years ago by git

  • Commit changed from 64b793848e4e392673804335c4284d673f43a952 to 9ba2de3cc00ccb2269c5a2348117dc3d824d06ff

Branch pushed to git repo; I updated commit sha1. New commits:

3f07cd4Added message in the case that no output is produced
db6993eFixed improper unpacking of spkg files
a3d7c9eRemove spkg creation services since it's not really useful
32e2be3Allow running doctests for py and pyx files
9ba2de3Fixed services for files with spaces (and other special characters)

comment:21 Changed 4 years ago by iandrus

  • Status changed from needs_work to needs_review

I think the issues should be fixed now. Unless I forgot one while reading this ticket.

comment:22 Changed 4 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:23 Changed 3 years ago by kcrisman

  • Status changed from needs_review to positive_review

comment:24 Changed 3 years ago by kcrisman

  • Status changed from positive_review to needs_review

comment:25 Changed 13 months ago by novoselt

  • Status changed from needs_review to needs_work

Does not apply!

comment:26 Changed 10 months ago by iandrus

@kcrisman, do you think there is any value to these any more? Several of them (creating packages etc.) no longer make sense at all, and I wonder how useful the others ever were. I could try to update them, but I'm afraid it's really not worth it.

You can read the documentation of what they were intended to do at https://git.sagemath.org/sage.git/commit/?id=64b793848e4e392673804335c4284d673f43a952

Last edited 10 months ago by iandrus (previous) (diff)

comment:27 Changed 10 months ago by kcrisman

  • Authors Ivan Andrus deleted
  • Dependencies #15732 deleted
  • Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
  • Reviewers changed from Karl-Dieter Crisman to Karl-Dieter Crisman, Ivan Andrus
  • Status changed from needs_work to positive_review

Given the time that has passed and that it seems less likely people will be taking random text from other applications and putting it in Sage, I think that is okay.

comment:28 Changed 8 months ago by embray

  • Resolution set to wontfix
  • Status changed from positive_review to closed

Closing tickets in the sage-duplicate/invalid/wontfix module with positive_review (i.e. someone has confirmed they should be closed).

Note: See TracTickets for help on using tickets.