File: jupyter

package info (click to toggle)
polymake 4.12-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 35,992 kB
  • sloc: cpp: 168,768; perl: 43,375; javascript: 31,575; ansic: 3,007; java: 2,654; python: 633; sh: 268; xml: 117; makefile: 61
file content (102 lines) | stat: -rw-r--r-- 3,309 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#  Copyright (c) 1997-2024
#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
#  Technische Universität Berlin, Germany
#  https://polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------
#
# install and start polymake jupyter interface

# usage: polymake --script jupyter [--force] ...
# using --force allows reinstallation of the interface, skipping the existence check
# all other options are passed on to the 'jupyter notebook' command


sub install_jupymake {
   my $pconf_path = shift;
   # installation of jupyter
   # the $pconf_path is prepended to the $ENV{PATH} variable to make sure it is built
   # with the correct polymake installation
   print <<".";
This function installs the jupyter-polymake kernel
and the python libpolymake interface JuPyMake for the
current user (into ~/.local).
You need to have a running version of the jupyter
notebook for python3 installed.

Are you sure you want to continue with the installation? [y/N] 
.
   local $ENV{PATH}="$pconf_path:".$ENV{PATH};
   chomp ($_=<STDIN>);
   my $extraflags = $^O eq "darwin" ? " --prefix=" : "";
   if (/^[Yy](?:es)?$/) {
      my $dir = new Tempdir;
      my $cmd = <<".";
( cp -RLp $Polymake::Resources/jupyter-polymake $dir && \\
 cp -RLp $Polymake::Resources/JuPyMake $dir && \\
 $^X -pi -e 's/"display_name":"polymake"/"display_name":"polymake-$Version"/g' $dir/jupyter-polymake/setup.py && \\
 cd $dir/JuPyMake/ && python3 setup.py install --user $extraflags && \\
 cd $dir/jupyter-polymake/ && python3 setup.py install --user $extraflags ) 2>&1
.
      my $install_jupymake = `$cmd`;
      if ($?==0) {
         print << ".";
Installation complete.
Do you want to start a jupyter notebook now? [y/N]
.
         chomp ($_=<STDIN>);
         if (/^[Yy](?:es)?$/) {
            undef $dir;
            start_jupymake(@_);
         }
      } else {
         die "Installation failed, please check the output:\n$install_jupymake";
      }
   }
}

sub start_jupymake {
   # starts jupyter notebook
   # currently no polymake kernel is running on start up
   exec("jupyter","notebook",@_);
}


my $force_install = 0;
if (@ARGV > 0 && $ARGV[0] eq '--force') {
   $force_install = 1;
   shift @ARGV;
}
my $pconf_path = Cwd::abs_path($0) =~ s/\/polymake$//r;

if (!-x "$pconf_path/polymake-config") {
   die <<"."
This script must be run from an installed polymake
version which was built with the callable library.
.
}

# check if the user has a polymake kernel in jupyter installed,
# if not install it else run 'jupyter notebook'
my $out=`jupyter kernelspec list` ;
if (!$force_install && $out =~ /^\s+polymake/m){
   start_jupymake(@ARGV);
} else {
   install_jupymake($pconf_path,@ARGV);
}
    


# Local Variables:
# mode: perl
# c-basic-offset:3
# End: