jupyter_kernel_1.0.0_8c987c13/sources/ada/ada_kernel.adb

 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
--  SPDX-FileCopyrightText: 2020 Max Reznik <reznikmm@gmail.com>
--
--  SPDX-License-Identifier: MIT
----------------------------------------------------------------

with Ada.Directories;
with Ada.Environment_Variables;
with League.Application;
with League.String_Vectors;
with League.Strings;

with Ada_Kernels;
with Jupyter.Start_Kernel;

procedure Ada_Kernel is
   function Get_Top_Directory return League.Strings.Universal_String;

   -----------------------
   -- Get_Top_Directory --
   -----------------------

   function Get_Top_Directory return League.Strings.Universal_String is

      function Append (Root : String) return League.Strings.Universal_String;

      ------------
      -- Append --
      ------------

      function Append (Root : String) return League.Strings.Universal_String is
         Value  : constant String := Ada.Directories.Compose (Root, "jupyter");
         Result : League.Strings.Universal_String;
      begin
         Ada.Directories.Create_Path (Value);
         Result := League.Strings.From_UTF_8_String (Value);
         Result.Append ('/');

         return Result;
      end Append;

      Tmp  : constant String := Ada.Environment_Variables.Value ("TMPDIR", "");
      Temp : constant String := Ada.Environment_Variables.Value ("TEMP", "");
   begin
      if Tmp /= "" then
         return Append (Tmp);
      elsif Temp /= "" then
         return Append (Temp);
      else
         return Append ("/tmp");
      end if;
   end Get_Top_Directory;

   Kernel : Ada_Kernels.Kernel;
   Error  : League.Strings.Universal_String;
   Args   : constant League.String_Vectors.Universal_String_Vector :=
     League.Application.Arguments;
begin
   Kernel.Initialize (Get_Top_Directory, Error);

   if Error.Is_Empty then
      Jupyter.Start_Kernel (Kernel, Args (1));
   else
      raise Program_Error with Error.To_UTF_8_String;
   end if;
end Ada_Kernel;