EntropyOrg / p5-Devel-IPerl

:microscope::books: Perl5 language kernel for Jupyter <http://jupyter.org/>
http://p3rl.org/Devel::IPerl
93 stars 15 forks source link

Colors disappear when cell is executed on OS X. #40

Closed demianriccardi closed 9 years ago

demianriccardi commented 9 years ago

I see the kernel registered now, but the colored syntax is lost when the cell is executed.

demianriccardi commented 9 years ago

using IPerl 0.005 via ipython notebook on os x.

zmughal commented 9 years ago

Yeah, I noticed that too in my Debian Iceweasel browser.

My steps to reproduce:

  1. Create a new IPerl notebook by going through the New ▼ menu
  2. Type the first line of code in the cell. This has syntax highlighting.
  3. Hit <Return> to enter a new line. The whole cell loses syntax highlighting.
  4. Create a new cell below. This cell and all subsequent cells have syntax highlighting.
  5. The first cell still lacks syntax highlighting.
  6. After reloading the notebook, all the cells have syntax-highlighting.

I believe the problem is one that other IPython kernels are facing as well: https://github.com/facebook/iTorch/issues/9, https://github.com/JuliaLang/IJulia.jl/issues/168. This didn't crop up before because IPerl was using custom JS to set the cells' language mode.

@Carreau, is this something that the IPython team knows about? I'm seeing this under IPython 3.1.0-cbccb68.

Carreau commented 9 years ago

hum, with 3.1.0 this is strange, with prior versions I would have guess it could have been an issue. I'll try to install and investigate.

Does IPerl ships a custom.js or does it use a kernel.json ?

zmughal commented 9 years ago

It now uses a kernel.json which it installs the first time that the iperl script is run: https://github.com/EntropyOrg/p5-Devel-IPerl/blob/5dcb94d1a92296a366389066b6a582fa1ae60d66/bin/iperl#L99-103.

An example kernel.json:

{
   "argv" : [
      "perl",
      "-MDevel::IPerl",
      "-e1",
      "kernel",
      "{connection_file}"
   ],
   "display_name" : "IPerl 0.005",
   "language" : "perl"
}
Carreau commented 9 years ago

Ah !

That's most likely the kernel_info_reply which should set the language to perl. we fallback on language . Can yo u in the JS console tell what the following gives :

IPython.notebook.get_selected_cell().code_mirror.getOption('mode')

keys(CodeMirror.modes)

zmughal commented 9 years ago

Right, I send back perl in the kernel_info_reply here.

Running the first line of JS gives different values for a new notebook versus a saved notebook:

New notebook

// Fresh notebook created by using `New`

// First cell
IPython.notebook.get_selected_cell().code_mirror.getOption('mode');
// "ipython"

// Insert a cell (2nd cell is selected)
IPython.notebook.get_selected_cell().code_mirror.getOption('mode');
// "perl"

// Save and refresh the browser

// First cell is selected
IPython.notebook.get_selected_cell().code_mirror.getOption('mode');
// "text/x-perl"

// Second cell is selected
IPython.notebook.get_selected_cell().code_mirror.getOption('mode');
// "perl"

// Press the save button and refresh the browser *again*
// First cell is selected
IPython.notebook.get_selected_cell().code_mirror.getOption('mode');
// "perl"

// Second cell is selected
IPython.notebook.get_selected_cell().code_mirror.getOption('mode');
// "perl"

Saved notebook

When opening a saved notebook, the following remains true for all cells:

IPython.notebook.get_selected_cell().code_mirror.getOption('mode')
// "perl"

Opening a new or saved notebook gives the following output for the second line of JS

keys(CodeMirror.modes)
// Array [ "null", "python", "ipython", "stex", "ipythongfm", "xml", "markdown", "gfm", "perl" ]
Carreau commented 9 years ago

Hum, that is definitively weird. Ping @takluyver and @minrk.

minrk commented 9 years ago

Definitely super weird, and presumably a bug in IPython's js. It's surprising, since I haven't seen this with my Julia notebooks. Is the suggestion above that this happens with no custom.js at all?

Carreau commented 9 years ago

Haven't found any trace of custom.js in the repo. I can't seem to be able to build IPerl though, but my perl knowlege is limitted. I guess I can mock the perl kernel with WrapperKernel.

On Tue, May 12, 2015 at 12:13 PM, Min RK notifications@github.com wrote:

Definitely super weird, and presumably a bug in IPython's js. It's surprising, since I haven't seen this with my Julia notebooks. Is the suggestion above that this happens with no custom.js at all?

— Reply to this email directly or view it on GitHub https://github.com/EntropyOrg/p5-Devel-IPerl/issues/40#issuecomment-101391315 .

Carreau commented 9 years ago

I'm stuck at installing...

~/d/notebook (master) $ cpanm Devel::IPerl --force
--> Working on Devel::IPerl
Fetching http://www.cpan.org/authors/id/Z/ZM/ZMUGHAL/Devel-IPerl-0.005.tar.gz ... OK
==> Found dependencies: File::ShareDir::Install
--> Working on File::ShareDir::Install
Fetching http://www.cpan.org/authors/id/G/GW/GWYN/File-ShareDir-Install-0.10.tar.gz ... OK
Configuring File-ShareDir-Install-0.10 ... OK
Building and testing File-ShareDir-Install-0.10 ... OK
Successfully installed File-ShareDir-Install-0.10
! Installing the dependencies failed: Module 'File::ShareDir::Install' is not installed
! Bailing out the installation for Devel-IPerl-0.005.
1 distribution installed
~/d/notebook (master) $ cpanm File::ShareDir
--> Working on File::ShareDir
Fetching http://www.cpan.org/authors/id/R/RE/REHSACK/File-ShareDir-1.102.tar.gz ... OK
==> Found dependencies: File::ShareDir::Install
--> Working on File::ShareDir::Install
Fetching http://www.cpan.org/authors/id/G/GW/GWYN/File-ShareDir-Install-0.10.tar.gz ... OK
Configuring File-ShareDir-Install-0.10 ... OK
Building and testing File-ShareDir-Install-0.10 ... OK
Successfully installed File-ShareDir-Install-0.10
! Installing the dependencies failed: Module 'File::ShareDir::Install' is not installed
! Bailing out the installation for File-ShareDir-1.102.
1 distribution installed

File::ShareDir::Install is installed correctly but appear not installed... any hints ?

zmughal commented 9 years ago
cpanm --verbose --force File::ShareDir::Install

might give more information. Odd that that File::ShareDir::Install won't install as that should be straightforward.

I'm installing IPython and building Julia on a fresh computer to ensure it isn't something wonky I might have done.

Carreau commented 9 years ago

Well seem to install successfully, but IPerl sis it's not installed. Should I add some dirs to my $PATH Maybe ?

... (rest below)
Successfully installed File-ShareDir-Install-0.10
Installing /Users/bussonniermatthias/perl5/lib/perl5/darwin-thread-multi-2level/.meta/File-ShareDir-Install-0.10/install.json
! Installing the dependencies failed: Module 'File::ShareDir::Install' is not installed
! Bailing out the installation for Devel-IPerl-0.005.
1 distribution installed
$ cpanm --verbose --force Devel::IPerl
cpanm (App::cpanminus) 1.7031 on perl 5.018002 built for darwin-thread-multi-2level
Work directory is /Users/bussonniermatthias/.cpanm/work/1431475249.5172
You have make /usr/bin/make
You have LWP 6.05
You have /usr/bin/tar: bsdtar 2.8.3 - libarchive 2.8.3
You have /usr/bin/unzip
Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (6.66)
Checking if you have ExtUtils::Install 1.46 ... Yes (1.59)
Searching Devel::IPerl on cpanmetadb ...
--> Working on Devel::IPerl
Fetching http://www.cpan.org/authors/id/Z/ZM/ZMUGHAL/Devel-IPerl-0.005.tar.gz ... OK
Unpacking Devel-IPerl-0.005.tar.gz
x Devel-IPerl-0.005/
...
x File-ShareDir-Install-0.10/META.yml
Entering File-ShareDir-Install-0.10
Checking configure dependencies from META.yml
Running Makefile.PL
Configuring File-ShareDir-Install-0.10 ... Checking if your kit is complete...
Looks good
Writing Makefile for File::ShareDir::Install
Writing MYMETA.yml and MYMETA.json
OK
Checking dependencies from MYMETA.json ...
Checking if you have ExtUtils::MakeMaker 6.11 ... Yes (6.66)
Checking if you have File::Spec 0 ... Yes (3.40)
Checking if you have IO::Dir 0 ... Yes (1.10)
Building and testing File-ShareDir-Install-0.10 ... cp lib/File/ShareDir/Install.pm blib/lib/File/ShareDir/Install.pm
Manifying blib/man3/File::ShareDir::Install.3pm
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00_compile.t ....... ok
t/01_pod.t ........... skipped: these tests are for authors only
t/02_pod_coverage.t .. skipped: these tests are for authors only
t/10_makefile.t ...... ok
t/11_dotfile.t ....... ok
t/12_delete.t ........ ok
All tests successful.
Files=6, Tests=33,  1 wallclock secs ( 0.03 usr  0.02 sys +  1.08 cusr  0.26 csys =  1.39 CPU)
Result: PASS
Appending installation info to /Users/bussonniermatthias/perl5/lib/perl5/darwin-thread-multi-2level/perllocal.pod
OK
...
zmughal commented 9 years ago

Hmm, not sure why that is happening. Hopefully it isn't something to do with an old version of cpanm. cpanm --self-upgrade can fix that.

What I'm using locally is

cpanm (App::cpanminus) version 1.7001 (/home/zaki/perl5/perlbrew/bin/cpanm)
perl version 5.018004 (/home/zaki/perl5/perlbrew/perls/perl-5.18.1/bin/perl)

@demianriccardi, have any idea what might be going on? I know you're also using IPerl under OS X.

zmughal commented 9 years ago

I tried out IJulia and I'm facing the same problem that I have in the above comment, but the behaviour is a little different when it comes to having the text cursor in a cell:

// Fresh IJulia notebook created by using `New`

// First cell has text cursor blinking in it
IPython.notebook.get_selected_cell().code_mirror.getOption('mode');
// "text/x-julia"

// Click outside the first cell to remove the text cursor,
// but the first cell is still selected.
IPython.notebook.get_selected_cell().code_mirror.getOption('mode');
// "ipython"

All other behaviour after saving is similar to what I'm seeing under IPerl. I have also cleared my browser cache.

zmughal commented 9 years ago

Aha! I think I've figured out why there is that small difference between IJulia and IPerl!

I was watching the IJulia kernel start and noticed that while the notebook says "Kernel starting", the CodeMirror mode is set to text/x-julia. As soon as the notebook says, "Kernel started", the CodeMirror mode gets set to ipython.

The reason I didn't see the same behaviour with IPerl is because IPerl's kernel starts up faster than IJulia's kernel on my machine.

zmughal commented 9 years ago

I also see the same behaviour (under both IPerl and IJulia) in Chromium, so the browser is not the issue.

Carreau commented 9 years ago

Ha !

It is a fight in between (Code)Cell._options.cm_config and (Code)Cell.cm_config. I'll need @takluyver help for that as _options is a config section.

It was hard to see in Julia as the highlighting is close to python for simple things !

demianriccardi commented 9 years ago

It looks like @Carreau was able to reproduce without running iperl.

With respect to an earlier comment, which may not be relevant anymore, on running the iperl notebook on OS X, did you try running 'iperl notebook' after the install? [ aside: It looks like File::ShareDir::Install has some failing tests under earlier versions of perl on OS X (5.14 and 5.16) ]. I'm still transitioning over to using 'ipython notebook' to load Jupyter and then the perl 0.005 kernel.

zmughal commented 9 years ago

So it looks like when the backported version lands, this should be fixed in IPython. The fix in Jupyter has been set for the 4.0 milestone.

zmughal commented 9 years ago

IPython 3.2 has been released and I just confirmed that this has been fixed! :fireworks:

Thanks for reporting @demianriccardi++ and thanks for the fix @Carreau++!