2013-02-21 16:34:08 +00:00
|
|
|
------------------------------------------------------------------------------
|
2019-09-07 22:36:08 +00:00
|
|
|
-- GNAT Studio --
|
2013-02-21 16:34:08 +00:00
|
|
|
-- --
|
2026-01-05 12:40:47 +00:00
|
|
|
-- Copyright (C) 2013-2026, AdaCore --
|
2013-02-21 16:34:08 +00:00
|
|
|
-- --
|
|
|
|
|
-- This is free software; you can redistribute it and/or modify it under --
|
|
|
|
|
-- terms of the GNU General Public License as published by the Free Soft- --
|
|
|
|
|
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
|
|
|
|
-- sion. This software is distributed in the hope that it will be useful, --
|
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
|
|
|
|
|
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
|
|
|
|
|
-- License for more details. You should have received a copy of the GNU --
|
|
|
|
|
-- General Public License distributed with this software; see file --
|
|
|
|
|
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
|
|
|
|
|
-- of the license. --
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
2022-01-24 12:05:54 +03:00
|
|
|
with VSS.Application;
|
|
|
|
|
with VSS.String_Vectors;
|
|
|
|
|
with VSS.Strings.Conversions;
|
|
|
|
|
|
2021-12-17 14:25:38 +01:00
|
|
|
with Config; use Config;
|
2020-10-28 15:42:16 +02:00
|
|
|
with GNATCOLL.Arg_Lists;
|
2013-02-21 16:34:08 +00:00
|
|
|
with GNATCOLL.Scripts;
|
2021-12-17 14:25:38 +01:00
|
|
|
with GNATCOLL.Scripts.Python; use GNATCOLL.Scripts.Python;
|
|
|
|
|
with GNATCOLL.Utils; use GNATCOLL.Utils;
|
2022-01-17 14:51:21 +00:00
|
|
|
with GNATCOLL.VFS; use GNATCOLL.VFS;
|
2013-02-21 16:34:08 +00:00
|
|
|
|
|
|
|
|
package body GPS.Python_Core is
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
|
-- Register_Python --
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
procedure Register_Python
|
2022-01-24 13:37:11 +03:00
|
|
|
(Kernel : access GPS.Core_Kernels.Core_Kernel_Record'Class) is
|
2013-02-21 16:34:08 +00:00
|
|
|
begin
|
2022-01-24 13:37:11 +03:00
|
|
|
declare
|
|
|
|
|
Python_Home : constant VSS.Strings.Virtual_String :=
|
2022-01-24 13:48:59 +03:00
|
|
|
VSS.Application.System_Environment.Value ("GNATSTUDIO_PYTHONHOME");
|
2022-01-24 13:37:11 +03:00
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
if Python_Home.Is_Empty then
|
|
|
|
|
declare
|
|
|
|
|
Packaged_Python_Location : constant Virtual_File :=
|
|
|
|
|
Create (+Executable_Location)
|
|
|
|
|
/ (+"share") / (+"gnatstudio") / (+"python");
|
|
|
|
|
begin
|
|
|
|
|
Register_Python_Scripting
|
|
|
|
|
(Kernel.Scripts,
|
|
|
|
|
Module => "GPS",
|
2023-11-28 16:44:10 +00:00
|
|
|
Program_Name => "gnatstudio",
|
2022-01-24 13:37:11 +03:00
|
|
|
Python_Home => Packaged_Python_Location.Display_Full_Name);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
else
|
2022-01-17 14:51:21 +00:00
|
|
|
Register_Python_Scripting
|
|
|
|
|
(Kernel.Scripts,
|
|
|
|
|
Module => "GPS",
|
2023-11-28 16:44:10 +00:00
|
|
|
Program_Name => "gnatstudio",
|
2022-01-24 13:37:11 +03:00
|
|
|
Python_Home =>
|
|
|
|
|
VSS.Strings.Conversions.To_UTF_8_String (Python_Home));
|
|
|
|
|
end if;
|
|
|
|
|
end;
|
2020-10-28 15:42:16 +02:00
|
|
|
|
|
|
|
|
declare
|
2022-01-24 12:05:54 +03:00
|
|
|
Paths : constant VSS.String_Vectors.Virtual_String_Vector :=
|
|
|
|
|
VSS.Application.System_Environment.Value_Paths
|
2022-01-24 13:48:59 +03:00
|
|
|
("GNATSTUDIO_PYDLLPATH", False);
|
2020-10-28 15:42:16 +02:00
|
|
|
Script : constant GNATCOLL.Scripts.Scripting_Language :=
|
|
|
|
|
Kernel.Scripts.Lookup_Scripting_Language (Python_Name);
|
|
|
|
|
Errors : Boolean;
|
|
|
|
|
begin
|
2021-12-17 14:25:38 +01:00
|
|
|
-- Dynamically load the gtk DLLs on windows for python3.8+
|
|
|
|
|
-- if the DLLs are not relatively located to PYTHONHOME.
|
2022-01-24 12:05:54 +03:00
|
|
|
if Config.Host = Windows then
|
2023-02-08 12:05:46 +01:00
|
|
|
Script.Execute_Command
|
|
|
|
|
(CL => GNATCOLL.Arg_Lists.Create
|
|
|
|
|
("import os; import io;"
|
|
|
|
|
& "save_stdout = sys.stdout; sys.stdout = io.StringIO()"),
|
|
|
|
|
Hide_Output => True,
|
|
|
|
|
Errors => Errors);
|
2022-01-24 12:05:54 +03:00
|
|
|
for Path of Paths loop
|
|
|
|
|
Script.Execute_Command
|
|
|
|
|
(CL => GNATCOLL.Arg_Lists.Create
|
2023-02-08 12:05:46 +01:00
|
|
|
("os.add_dll_directory('"
|
2022-01-24 12:05:54 +03:00
|
|
|
& VSS.Strings.Conversions.To_UTF_8_String (Path)
|
|
|
|
|
& "')"),
|
|
|
|
|
Hide_Output => True,
|
|
|
|
|
Errors => Errors);
|
|
|
|
|
end loop;
|
2023-02-08 12:05:46 +01:00
|
|
|
Script.Execute_Command
|
|
|
|
|
(CL => GNATCOLL.Arg_Lists.Create
|
|
|
|
|
("sys.stdout = save_stdout"),
|
|
|
|
|
Hide_Output => True,
|
|
|
|
|
Errors => Errors);
|
2021-12-16 21:37:14 +01:00
|
|
|
end if;
|
|
|
|
|
|
2021-12-17 14:25:38 +01:00
|
|
|
-- Register GPS module as GS to use both in transition period
|
2020-10-28 15:42:16 +02:00
|
|
|
Script.Execute_Command
|
|
|
|
|
(CL => GNATCOLL.Arg_Lists.Create
|
|
|
|
|
("sys.modules['GS'] = GPS"),
|
|
|
|
|
Hide_Output => True,
|
|
|
|
|
Errors => Errors);
|
|
|
|
|
pragma Assert (not Errors);
|
2021-03-30 06:13:13 -04:00
|
|
|
|
|
|
|
|
-- Force the interpreter to load all files as utf8
|
|
|
|
|
Script.Execute_Command
|
|
|
|
|
(CL => GNATCOLL.Arg_Lists.Create
|
|
|
|
|
("import _locale; _locale._getdefaultlocale" &
|
|
|
|
|
" = (lambda *args: ['en_US', 'utf8'])"),
|
|
|
|
|
Hide_Output => True,
|
|
|
|
|
Errors => Errors);
|
|
|
|
|
pragma Assert (not Errors);
|
2020-10-28 15:42:16 +02:00
|
|
|
end;
|
2013-02-21 16:34:08 +00:00
|
|
|
end Register_Python;
|
|
|
|
|
|
|
|
|
|
end GPS.Python_Core;
|