Bug 348128 - The sage backend does not starts with sage 6.7
Summary: The sage backend does not starts with sage 6.7
Status: RESOLVED FIXED
Alias: None
Product: cantor
Classification: Applications
Component: sage-backend (show other bugs)
Version: unspecified
Platform: Kubuntu Linux
: NOR major
Target Milestone: ---
Assignee: Alexander Rieder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-23 07:35 UTC by Nuno
Modified: 2017-05-09 13:18 UTC (History)
8 users (show)

See Also:
Latest Commit:
Version Fixed In: 16.04
Sentry Crash Report:


Attachments
Fixes bug 348128 using non-capturing regex groups. (626 bytes, patch)
2016-02-08 13:45 UTC, matpen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nuno 2015-05-23 07:35:19 UTC
When starting the sage backend, a "starting" information window pops-up but it never passes this phase. I suspect that it may be a login problem as when I start the sage notebook from the prompt, it asks for a username/password.

Reproducible: Always

Steps to Reproduce:
1. Cantor -> File -> New -> Sage
2.
3.

Actual Results:  
A starting window that keeps open without a new session been lunched

Expected Results:  
A new session in sage.
Comment 1 Dirk Sarpe 2015-06-03 07:34:46 UTC
Not 100% sure if it is the same problem, but it sounds similar. With sage 6.6 (provided via the aims ppa) upon initializing a new sage session through cantor a window with "Initializing Session" starts and stays until manually closed. The worksheet stays blank.

I tried with the following path settings for sage in cantor:
/usr/bin/sage
/usr/bin/sagemath
/usr/lib/sagemath/sage (the former one link to this one)

~$ cantor --version
Qt: 4.8.6
KDE Development Platform: 4.14.2
Cantor: 0.5

~$ apt-cache policy cantor-backend-sage 
cantor-backend-sage:
  Installed: 4:4.14.2-0ubuntu1~ubuntu14.04~ppa1
  Candidate: 4:4.14.2-0ubuntu1~ubuntu14.04~ppa1
  Version table:
 *** 4:4.14.2-0ubuntu1~ubuntu14.04~ppa1 0
        500 http://ppa.launchpad.net/kubuntu-ppa/backports/ubuntu/ trusty/main amd64 Packages
        100 /var/lib/dpkg/status
[…]

~$ apt-cache policy sagemath-upstream-binary 
sagemath-upstream-binary:
  Installed: 6.7ppa10revert6.6.aims6-2
  Candidate: 6.7ppa10revert6.6.aims6-2
  Version table:
 *** 6.7ppa10revert6.6.aims6-2 0
        500 http://ppa.launchpad.net/aims/sagemath/ubuntu/ trusty/main amd64 Packages
        100 /var/lib/dpkg/status
Comment 2 Louis Moureaux 2015-11-11 23:06:21 UTC
I get the same behaviour as Dirk Sarpe on Arch Linux, with SageMath version 6.9 and Cantor 0.6. From the command line output, Sage gets started, but Cantor doesn't see it. The last line printed to the terminal is:
tmp path:  "/home/<me>/.sage/temp/<localhost's name>/<some number>"
I don't know whether it comes from SageMath or from Cantor itself.
Before that, the "sage:" prompt gets printed with its escape characters escaped (QByteArray dump?)
Comment 3 matpen 2016-01-31 09:17:16 UTC
Same behaviour on Ubuntu 15.10 with Cantor 0.6 and sage backend installed via repo, and sage 6.9 installed via aims ppa. Sage works fine when used from command line and via notebook. Also Cantor works well with Maxima backend. When run from terminal, the output is similar to the one reported here: https://forum.kde.org/viewtopic.php?f=21&t=126679
Comment 4 Filipe Saraiva 2016-02-05 14:04:03 UTC
A fix to this bug is going to be committed soon!
Comment 5 Filipe Saraiva 2016-02-06 19:39:32 UTC
Git commit 5d185d21431a989055ab4a1501584dbb3ea17842 by Filipe Saraiva, on behalf of Fernando Teles.
Committed on 06/02/2016 at 19:38.
Pushed by filipesaraiva into branch 'master'.

After version 6.5, Sage changed its name to SageMath. So, Cantor supports
to newer versions was broken. I changed a string to resolve this issue.
FIXED-IN: 16.04
CLOSES: D903
DONE: T1029
CCMAIL: fernandotalves@gmail.com

M  +1    -1    src/backends/sage/sagesession.cpp

http://commits.kde.org/cantor/5d185d21431a989055ab4a1501584dbb3ea17842
Comment 6 Louis Moureaux 2016-02-06 22:57:34 UTC
Thank you for this fix, you rock !
Comment 7 jackdyson31 2016-02-08 12:43:46 UTC
Hi Fillipe and Fernando,

Thank you so much for sorting this out - I have just one ask :

I use Ubuntu LTS 14.04 running the excellent KDE desktop. I have (and am locked at) Cantor 0.5. Would be possible to rebuild Cantor 0.5 with this small change and post it as a legacy update for LTS 14.04 ? - it would make a BIG BIG difference to so many of us who use it (I can't upgrade without spending days reorganizing).

Cantor makes open mathematics a professional tool for researchwork, so thanks a lot for this great piece of software,

Jack
Comment 8 matpen 2016-02-08 13:20:52 UTC
Hi Jack,

I dont know if the guys will be able to backport the fix, and how long it is going to take.
However, you can build a custom version for yourself very easily in the meantime.

Here some instructions on how to go about it (run these in the terminal):
#make a temporary directory
mkdir /tmp/cantor
cd /tmp/cantor

#download the source of your currently installed cantor package
sudo apt-get install debian-keyring
sudo apt-get source cantor

#the above will create a subdirectory called "cantor-version-number-something"
#in there you will find the directory "src" (i cant test right now, so you might have to look for it)
#find and edit the file "src/backends/sage/sagesession.cpp" according to the submitted patch
#which you can find here: https://quickgit.kde.org/?p=cantor.git&a=commitdiff&h=5d185d21431a989055ab4a1501584dbb3ea17842&hp=ad75e06d3b4317ab45e1b84419b9abb8e33ad6fa
#this patch is very simple: you only have to ad "+(|Math)" right after "Sage" on the right line
#the "right line" is 194 for the latest cantor, but it might be some lines up or down in your version

#now rebuild the package
sudo apt-get install dpkg-dev
sudo apt-get install build-dep cantor
cd "cantor-version-something"
dpkg-buildpackage -b -us -uc
cd ..

#you should now have some debian packages 
#install the sage backend with
sudo dpkg -i cantor-backend-sage*.deb

Once again, this is just the temporary workaround that I used until the change will show up in the official Ubuntu repositories.

Good luck!
Matteo
Comment 9 matpen 2016-02-08 13:45:56 UTC
Created attachment 97084 [details]
Fixes bug 348128 using non-capturing regex groups.
Comment 10 matpen 2016-02-08 13:46:13 UTC
Btw, I spotted a problem in the proposed patch.

The current fix uses "(|Math)" to identify a regular expression group that might or might not match "Math". Unfortunately, this is a capturing group, so the QRegExp object will capture "Math". Later on in the code, the captured text are used to identify the current version of Sage. The fix thus interferes with this procedure.

The solution I propose (see attachment) uses non-capturing groups to achieve the same result.
Extract of command line output with the current patch (using Sage 6.9):
[...]
found version:  ("SageMath Version 6.9", "Math", "6", "9")
using an old version of sage:  0 . 6 . Using the old init command
[...]
AttributeError                            Traceback (most recent call last)
<ipython-input-11-4afd552cec94> in <module>()
----> 1 __CANTOR_IPYTHON_SHELL__.autoindent=False
[...]

Using the patch I propose:
[...]
found version:  ("SageMath Version 6.9", "6", "9")
using the current set of commands
[...]

Please see attachment.
Comment 11 jackdyson31 2016-02-08 22:21:07 UTC
Hi Matteo!

Thankyou so much for taking the time to sort that out so nicely. I will start working on it as soon as get a moment. I'll post back what happens here for any observations and results. One small thing - will the new compiled version support both prior and post 6.5 sage additions ?

Jack
Comment 12 matpen 2016-02-09 06:13:52 UTC
Hi Jack!

Yes, although I only tested it with Sage 6.9, the patch should work fine with prior versions.
If it does not, feel free to post your observations here and someone will definitely look into the issue.

However, do note my second comment that I posted yesterday.
In my opinion the original patch is not correct, and with Sage gives error on init.
Although it "seems" to work anyway, it might have more subtle implications.

My advice is to wait for the decision of the core developers in this regard (I am just a regular user).
Comment 13 Filipe Saraiva 2016-02-09 14:39:12 UTC
(In reply to jackdyson31 from comment #7)
> Hi Fillipe and Fernando,
> 
> Thank you so much for sorting this out - I have just one ask :
> 
> I use Ubuntu LTS 14.04 running the excellent KDE desktop. I have (and am
> locked at) Cantor 0.5. Would be possible to rebuild Cantor 0.5 with this
> small change and post it as a legacy update for LTS 14.04 ? - it would make
> a BIG BIG difference to so many of us who use it (I can't upgrade without
> spending days reorganizing).
> 

Hello jackdyson31, unfortunately you will need to compile Cantor to use this fix. Currently the KDE Applications available in Ubuntu 14.04 official repository is 4.13 version, a very old release.

>
> Cantor makes open mathematics a professional tool for researchwork, so
> thanks a lot for this great piece of software,
> 

Thank you! We love to hear positive feedback!
Comment 14 Filipe Saraiva 2016-02-09 14:48:03 UTC
(In reply to matpen from comment #10)
> Btw, I spotted a problem in the proposed patch.
> 
> The current fix uses "(|Math)" to identify a regular expression group that
> might or might not match "Math". Unfortunately, this is a capturing group,
> so the QRegExp object will capture "Math". Later on in the code, the
> captured text are used to identify the current version of Sage. The fix thus
> interferes with this procedure.
> 
> The solution I propose (see attachment) uses non-capturing groups to achieve
> the same result.
> Extract of command line output with the current patch (using Sage 6.9):
> [...]
> found version:  ("SageMath Version 6.9", "Math", "6", "9")
> using an old version of sage:  0 . 6 . Using the old init command
> [...]
> AttributeError                            Traceback (most recent call last)
> <ipython-input-11-4afd552cec94> in <module>()
> ----> 1 __CANTOR_IPYTHON_SHELL__.autoindent=False
> [...]
> 
> Using the patch I propose:
> [...]
> found version:  ("SageMath Version 6.9", "6", "9")
> using the current set of commands
> [...]
> 
> Please see attachment.

Thank you matpen, your approach is better for solve this bug. If you have developer account, could you to commit and push it? If not I can to do it for you.
Comment 15 matpen 2016-02-09 15:45:08 UTC
> Thank you matpen, your approach is better for solve this bug. If you have
> developer account, could you to commit and push it? If not I can to do it
> for you.

Sorry Filipe, I do not have a developer account... It would be great if you could take over the tast of pushing the patch.

Thank you!
Comment 16 Filipe Saraiva 2016-02-09 16:51:31 UTC
Git commit 6586a64bc5ae9d385be68b8500aa6b273aab0c79 by Filipe Saraiva.
Committed on 09/02/2016 at 16:51.
Pushed by filipesaraiva into branch 'master'.

Improve the fix using non-capturing groups
Thanks matpen@dnet.it!
CCMAIL: matpen@dnet.it

M  +1    -1    src/backends/sage/sagesession.cpp

http://commits.kde.org/cantor/6586a64bc5ae9d385be68b8500aa6b273aab0c79
Comment 17 jackdyson31 2016-02-10 23:03:06 UTC
Dear Matteo and Filipe,

worked like a charm :-D, sage 7 fires up like it never went out out of fashion on Cantor 4.13

many thanks again!!!!

Jack

PS can I post the .deb somewhere for other fellows in my predicament?
Comment 18 jackdyson31 2016-02-10 23:25:58 UTC
PS @Matteo :
sudo apt-get install build-dep cantor --> sudo apt-get build-dep cantor
(just in case some other chap tries his hand at it)
Comment 19 matpen 2016-02-13 21:38:10 UTC
Jack,

If you want to share your .deb, the best way would be to set up your own ppa... but I cannot help you with this, since I never tried.

Thank you for spotting my mistype... as I said, I could not test on a real machine when I was writing. So good to have a fix for later reference. I am repeating the updated instructions below, including the updated patch for ease of reference:

Instructions to patch cantor to fix this bug, starting from the source of the official cantor package (run these commands in a terminal): 
#make a temporary directory 
mkdir /tmp/cantor 
cd /tmp/cantor 

#download the source of your currently installed cantor package 
sudo apt-get install debian-keyring 
sudo apt-get source cantor 

#the above will create a subdirectory called "cantor-version-number-something" 
#in there you will find the directory "src" (i cant test right now, so you might have to look for it) #find and edit the file "src/backends/sage/sagesession.cpp" according to the submitted patch #which you can find here: https://quickgit.kde.org/?p=cantor.git&a=commitdiff&h=6586a64bc5ae9d385be68b8500aa6b273aab0c79&hp=a94da3288f3cda78f9574aa2a7d753f4f70b5db0 
#this patch is very simple: you only have to add "(?:Math)?" right after "Sage" on the right line #the "right line" is 197 for the latest cantor, but it might be some lines up or down in your version 

#now rebuild the package 
sudo apt-get install dpkg-dev 
sudo apt-get build-dep cantor 
cd "cantor-version-something" 
dpkg-buildpackage -b -us -uc 
cd .. 

#you should now have some debian packages 
#install the sage backend with 
sudo dpkg -i cantor-backend-sage*.deb 

Note that these instructions are only useful until the fix for this package will show up in the Ubuntu repositories (or if you are running an old version of cantor which will not be updated).

Regards
Mat
Comment 20 jackdyson31 2016-02-13 22:08:31 UTC
Evening Mat,

Cheers for the really great and easy to follow instructions which work like a treat for Cantor 0.5 4.13 - I just hacked them and did the same update on Cantor 0.5, 4.14.3 from Kubuntu Backports (anyone interested in how that happens, get in touch with me and I'll fill you in)

No problems for the typo - just said it to help less experienced guys. One other small thing I did:

        //QRegExp versionExp("Sage\\s+Version\\s+(\\d+)\\.(\\d+)");
        QRegExp versionExp("Sage(?:Math)?\\s+Version\\s+(\\d+)\\.(\\d+)");

which is different to the one proposed for the latest version of Cantor (0.6).

This fix is a bit of a life saver!

Jack

PS Having run sage 7.0, 6.10, 6.9 etc in the rebuilt version, sadly the latex output is disabled (if you try show(x^2) for example it just dumps a string), sage 7.0 on Cantor 0.5 is a HUGE improvement and very powerful.
Comment 21 mathcals 2016-03-05 22:36:45 UTC
I had the same problem on ubuntu 14.04, and to save the trouble of rebuilding Cantor I created the following shell script and set it as Cantor's sage path:

echo "┌────────────────────────────────────────────────────────────────────┐"
echo "│ Sage Version 6.8, Release Date: 2015-07-26                         │"
sage "$@"
Comment 22 jackdyson31 2016-06-22 12:53:37 UTC
@mathcals@outlook.com

absolutely brilliant solution, should work out on other versions too - if you have kubuntu backports installed then doing a rebuild is a nightmare. Many thanks !
Comment 23 christopher 2017-05-08 15:11:49 UTC
I still have the same problem with Cantor 0.6 in Kubuntu 16.04 :-(
Comment 24 Christoph Feck 2017-05-08 20:51:16 UTC
Expected, because Kubuntu 16.04 only has KDE Applications 15.12. Please use a newer version, or use backport PPAs.
Comment 25 christopher 2017-05-08 21:34:46 UTC
(In reply to Christoph Feck from comment #24)
> Expected, because Kubuntu 16.04 only has KDE Applications 15.12. Please use
> a newer version, or use backport PPAs.

Oh okay, thank you for you help.
Comment 26 jackdyson31 2017-05-09 13:18:33 UTC
@christopher

this might be useful (and a lot better): 

https://github.com/sagemathinc/smc/tree/master/src/dev/docker

regards,

Jack