Commit 3a863aa7 authored by Garrett Regier's avatar Garrett Regier
Browse files

ide: Remove scripting support

This is now handled by libpeas and has been
for quite some time now.

https://bugzilla.gnome.org/show_bug.cgi?id=773021
parent fb2b863b
......@@ -248,22 +248,18 @@ AM_CONDITIONAL(ENABLE_WEBKIT, [test "x$enable_webkit" = "xyes"])
dnl ***********************************************************************
dnl Check for Required Python
dnl ***********************************************************************
enable_python_scripting=no
AS_IF([test "x$have_pygobject" = "xyes"],[
AM_PATH_PYTHON([3.2.3])
AC_PATH_TOOL(PYTHON3_CONFIG, "python3-config")
AS_IF([test -z "${PYTHON3_CONFIG}"],[
AC_MSG_RESULT([Failed to locate python3-config.])
AS_IF([test -z "${PYTHON}"],[
enable_python_scripting=no
AC_MSG_RESULT([Failed to locate python3.])
],[
LIBIDE_CFLAGS="${LIBIDE_CFLAGS} `${PYTHON3_CONFIG} --includes`"
LIBIDE_LIBS="${LIBIDE_LIBS} `${PYTHON3_CONFIG} --libs`"
LIBIDE_LDFLAGS="${LIBIDE_LDFLAGS} `${PYTHON3_CONFIG} --ldflags`"
enable_python_scripting=yes
pyoverridesdir="\$(pyexecdir)/gi/overrides"
AC_SUBST(pyoverridesdir)
])
pyoverridesdir="\$(pyexecdir)/gi/overrides"
AC_SUBST(pyoverridesdir)
])
AM_CONDITIONAL(ENABLE_PYTHON_SCRIPTING, test x$enable_python_scripting != xno)
dnl ***********************************************************************
......@@ -319,12 +315,6 @@ m4_include([plugins/vala-pack/configure.ac])
m4_include([plugins/xml-pack/configure.ac])
dnl ***********************************************************************
dnl Define automake conditionals based on what we found
dnl ***********************************************************************
AM_CONDITIONAL(ENABLE_PYTHON_SCRIPTING, test x$enable_python_scripting != xno)
dnl ***********************************************************************
dnl Initialize Libtool
dnl ***********************************************************************
......
......@@ -351,7 +351,6 @@ ide_context_get_device_manager
ide_context_get_project
ide_context_get_recent_manager
ide_context_get_runtime_manager
ide_context_get_script_manager
ide_context_get_search_engine
ide_context_get_settings
ide_context_get_snippets_manager
......@@ -1464,12 +1463,6 @@ ide_project_template_expand_finish
IdeProjectTemplate
</SECTION>
<SECTION>
<FILE>ide-pygobject-script</FILE>
IDE_TYPE_PYGOBJECT_SCRIPT
IdePyGObjectScript
</SECTION>
<SECTION>
<FILE>ide-recent-projects</FILE>
IDE_TYPE_RECENT_PROJECTS
......@@ -1554,27 +1547,6 @@ ide_runtime_provider_unload
IdeRuntimeProvider
</SECTION>
<SECTION>
<FILE>ide-script</FILE>
<TITLE>IdeScript</TITLE>
IDE_TYPE_SCRIPT
IDE_SCRIPT_EXTENSION_POINT
IdeScriptClass
ide_script_load
ide_script_unload
ide_script_get_file
IdeScript
</SECTION>
<SECTION>
<FILE>ide-script-manager</FILE>
IDE_TYPE_SCRIPT_MANAGER
ide_script_manager_get_scripts_directory
ide_script_manager_load_async
ide_script_manager_load_finish
IdeScriptManager
</SECTION>
<SECTION>
<FILE>ide-search-context</FILE>
IDE_TYPE_SEARCH_CONTEXT
......@@ -2210,8 +2182,6 @@ IdeRefactoryInterface
IdeRuntime
IdeRuntimeManager
IdeRuntimeProvider
IdeScript
IdeScriptManager
IdeSearchContext
IdeSearchEngine
IdeSearchProvider
......
......@@ -109,8 +109,6 @@ libide_1_0_la_public_headers = \
runtimes/ide-runtime-manager.h \
runtimes/ide-runtime-provider.h \
runtimes/ide-runtime.h \
scripting/ide-script-manager.h \
scripting/ide-script.h \
search/ide-omni-search-display.h \
search/ide-omni-search-entry.h \
search/ide-omni-search-group.h \
......@@ -286,8 +284,6 @@ libide_1_0_la_public_sources = \
runtimes/ide-runtime-manager.c \
runtimes/ide-runtime-provider.c \
runtimes/ide-runtime.c \
scripting/ide-script-manager.c \
scripting/ide-script.c \
search/ide-omni-search-display.c \
search/ide-omni-search-entry.c \
search/ide-omni-search-group.c \
......@@ -603,23 +599,6 @@ libide_1_0_la_LIBADD += $(top_builddir)/contrib/libeditorconfig/libeditorconfig.
endif
if ENABLE_PYTHON_SCRIPTING
libide_1_0_la_includes += -I$(srcdir)/pygobject
libide_1_0_la_SOURCES += \
pygobject/ide-pygobject-script.c \
pygobject/ide-pygobject-script.h \
$(NULL)
libide_1_0_la_CFLAGS += \
$(PYGOBJECT_CFLAGS) \
-DENABLE_PYTHON_SCRIPTING \
$(NULL)
libide_1_0_la_LIBADD += $(PYGOBJECT_LIBS)
endif
glib_enum_headers = \
buffers/ide-buffer.h \
buildsystem/ide-build-result.h \
......
......@@ -45,7 +45,6 @@
#include "projects/ide-recent-projects.h"
#include "runner/ide-run-manager.h"
#include "runtimes/ide-runtime-manager.h"
#include "scripting/ide-script-manager.h"
#include "search/ide-search-engine.h"
#include "search/ide-search-provider.h"
#include "snippets/ide-source-snippets-manager.h"
......@@ -72,7 +71,6 @@ struct _IdeContext
GtkRecentManager *recent_manager;
IdeRunManager *run_manager;
IdeRuntimeManager *runtime_manager;
IdeScriptManager *script_manager;
IdeSearchEngine *search_engine;
IdeSourceSnippetsManager *snippets_manager;
IdeTransferManager *transfer_manager;
......@@ -110,7 +108,6 @@ enum {
PROP_PROJECT,
PROP_ROOT_BUILD_DIR,
PROP_RUNTIME_MANAGER,
PROP_SCRIPT_MANAGER,
PROP_SEARCH_ENGINE,
PROP_SNIPPETS_MANAGER,
PROP_VCS,
......@@ -423,21 +420,6 @@ ide_context_set_project_file (IdeContext *self,
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PROJECT_FILE]);
}
/**
* ide_context_get_script_manager:
*
* Retrieves the script manager for the context.
*
* Returns: (transfer none): An #IdeScriptManager.
*/
IdeScriptManager *
ide_context_get_script_manager (IdeContext *self)
{
g_return_val_if_fail (IDE_IS_CONTEXT (self), NULL);
return self->script_manager;
}
/**
* ide_context_get_search_engine:
*
......@@ -628,10 +610,6 @@ ide_context_get_property (GObject *object,
g_value_set_object (value, ide_context_get_runtime_manager (self));
break;
case PROP_SCRIPT_MANAGER:
g_value_set_object (value, ide_context_get_script_manager (self));
break;
case PROP_SEARCH_ENGINE:
g_value_set_object (value, ide_context_get_search_engine (self));
break;
......@@ -751,13 +729,6 @@ ide_context_class_init (IdeContextClass *klass)
IDE_TYPE_RUNTIME_MANAGER,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties [PROP_SCRIPT_MANAGER] =
g_param_spec_object ("script-manager",
"Script Manager",
"The script manager for the context.",
IDE_TYPE_SCRIPT_MANAGER,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties [PROP_SEARCH_ENGINE] =
g_param_spec_object ("search-engine",
"Search Engine",
......@@ -808,8 +779,6 @@ ide_context_class_init (IdeContextClass *klass)
static void
ide_context_init (IdeContext *self)
{
g_autofree gchar *scriptsdir = NULL;
IDE_ENTRY;
g_mutex_init (&self->unload_mutex);
......@@ -872,15 +841,6 @@ ide_context_init (IdeContext *self)
self->snippets_manager = g_object_new (IDE_TYPE_SOURCE_SNIPPETS_MANAGER, NULL);
scriptsdir = g_build_filename (g_get_user_config_dir (),
ide_get_program_name (),
"scripts",
NULL);
self->script_manager = g_object_new (IDE_TYPE_SCRIPT_MANAGER,
"context", self,
"scripts-directory", scriptsdir,
NULL);
IDE_EXIT;
}
......@@ -1123,46 +1083,6 @@ ide_context_init_unsaved_files (gpointer source_object,
g_object_ref (task));
}
static void
ide_context_init_scripts_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
IdeScriptManager *manager = (IdeScriptManager *)object;
g_autoptr(GTask) task = user_data;
GError *error = NULL;
g_assert (IDE_IS_SCRIPT_MANAGER (manager));
g_assert (G_IS_TASK (task));
if (!ide_script_manager_load_finish (manager, result, &error))
{
g_task_return_error (task, error);
return;
}
g_task_return_boolean (task, TRUE);
}
static void
ide_context_init_scripts (gpointer source_object,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
IdeContext *self = source_object;
g_autoptr(GTask) task = NULL;
g_return_if_fail (IDE_IS_CONTEXT (self));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
ide_script_manager_load_async (self->script_manager,
cancellable,
ide_context_init_scripts_cb,
g_object_ref (task));
}
static void
ide_context_init_snippets_cb (GObject *object,
GAsyncResult *result,
......@@ -1582,7 +1502,6 @@ ide_context_init_async (GAsyncInitable *initable,
ide_context_init_project_name,
ide_context_init_back_forward_list,
ide_context_init_snippets,
ide_context_init_scripts,
ide_context_init_unsaved_files,
ide_context_init_add_recent,
ide_context_init_search_engine,
......
......@@ -42,7 +42,6 @@ IdeProject *ide_context_get_project (IdeContext
GtkRecentManager *ide_context_get_recent_manager (IdeContext *self);
IdeRunManager *ide_context_get_run_manager (IdeContext *self);
IdeRuntimeManager *ide_context_get_runtime_manager (IdeContext *self);
IdeScriptManager *ide_context_get_script_manager (IdeContext *self);
IdeSearchEngine *ide_context_get_search_engine (IdeContext *self);
IdeSettings *ide_context_get_settings (IdeContext *self,
const gchar *schema_id,
......
......@@ -31,10 +31,6 @@
# include "editorconfig/ide-editorconfig-file-settings.h"
#endif
#ifdef ENABLE_PYTHON_SCRIPTING
# include "pygobject/ide-pygobject-script.h"
#endif
static gboolean programNameRead;
static const gchar *programName = "libide";
......@@ -70,7 +66,6 @@ static void
ide_init_ctor (void)
{
g_io_extension_point_register (IDE_FILE_SETTINGS_EXTENSION_POINT);
g_io_extension_point_register (IDE_SCRIPT_EXTENSION_POINT);
g_io_extension_point_implement (IDE_FILE_SETTINGS_EXTENSION_POINT,
IDE_TYPE_MODELINES_FILE_SETTINGS,
......@@ -86,11 +81,4 @@ ide_init_ctor (void)
IDE_TYPE_GSETTINGS_FILE_SETTINGS,
IDE_FILE_SETTINGS_EXTENSION_POINT".gsettings",
-300);
#ifdef ENABLE_PYTHON_SCRIPTING
g_io_extension_point_implement (IDE_SCRIPT_EXTENSION_POINT,
IDE_TYPE_PYGOBJECT_SCRIPT,
IDE_SCRIPT_EXTENSION_POINT".py",
-100);
#endif
}
......@@ -101,8 +101,6 @@ G_BEGIN_DECLS
#include "runtimes/ide-runtime-manager.h"
#include "runtimes/ide-runtime-provider.h"
#include "runtimes/ide-runtime.h"
#include "scripting/ide-script-manager.h"
#include "scripting/ide-script.h"
#include "search/ide-omni-search-row.h"
#include "search/ide-pattern-spec.h"
#include "search/ide-search-context.h"
......
/* ide-pygobject-script.c
*
* Copyright (C) 2015 Garrett Regier <garrettregier@gmail.com>
*
* This file is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This file 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ide-context.h"
#include "ide-pygobject-script.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
/* _POSIX_C_SOURCE is defined in Python.h and in limits.h included by
* glib-object.h, so we unset it here to avoid a warning. Yep, that's bad.
*/
#undef _POSIX_C_SOURCE
#include <pygobject.h>
#pragma GCC diagnostic pop
#include <glib/gi18n.h>
struct _IdePyGObjectScript
{
IdeScript parent_instance;
};
static PyThreadState *py_thread_state = NULL;
static void async_initable_iface_init (GAsyncInitableIface *iface);
G_DEFINE_TYPE_EXTENDED (IdePyGObjectScript, ide_pygobject_script, IDE_TYPE_SCRIPT, 0,
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
async_initable_iface_init))
static gboolean
init_pygobject (void)
{
PyGILState_STATE state = 0;
long hexversion;
gboolean must_finalize_python = FALSE;
static gboolean initialized = FALSE;
static gboolean success = FALSE;
if (initialized)
return success;
initialized = TRUE;
/* Python initialization */
if (Py_IsInitialized ())
{
state = PyGILState_Ensure ();
}
else
{
Py_InitializeEx (FALSE);
must_finalize_python = TRUE;
}
hexversion = PyLong_AsLong (PySys_GetObject ((char *) "hexversion"));
#if PY_VERSION_HEX < 0x03000000
if (hexversion >= 0x03000000)
#else
if (hexversion < 0x03000000)
#endif
{
g_critical ("Attempting to mix incompatible Python versions");
return FALSE;
}
/* Initialize PyGObject */
pygobject_init (3, 0, 0);
if (PyErr_Occurred ())
{
g_warning ("PyGObject initialization failed");
PyErr_Print ();
return FALSE;
}
/* Initialize support for threads */
pyg_enable_threads ();
PyEval_InitThreads ();
/* Only redirect warnings when pygobject was not already initialized */
if (!must_finalize_python)
pyg_disable_warning_redirections ();
if (!must_finalize_python)
PyGILState_Release (state);
else
py_thread_state = PyEval_SaveThread ();
success = TRUE;
return TRUE;
}
static void
ide_pygobject_script_load (IdeScript *script)
{
IdePyGObjectScript *self = (IdePyGObjectScript *)script;
IdeContext *context;
g_autoptr(GError) error = NULL;
g_autofree gchar *contents = NULL;
g_autofree gchar *path = NULL;
g_autoptr(GFile) parent = NULL;
g_autofree gchar *parent_path = NULL;
GFile *file;
PyObject *globals = NULL;
PyObject *builtins_module;
PyObject *module_dir = NULL;
PyObject *retval;
PyObject *pycontext = NULL;
PyObject *code = NULL;
PyGILState_STATE state;
g_return_if_fail (IDE_IS_PYGOBJECT_SCRIPT (self));
file = ide_script_get_file (IDE_SCRIPT (script));
if (!file)
{
g_warning (_("Attempt to load a PyGObject script with no filename."));
return;
}
path = g_file_get_basename (file);
if (!g_file_load_contents (file, NULL, &contents, NULL, NULL, &error))
{
g_warning ("%s", error->message);
return;
}
if (!init_pygobject ())
return;
state = PyGILState_Ensure ();
globals = PyDict_New ();
if (globals == NULL)
goto out;
builtins_module = PyImport_ImportModule ("builtins");
if (builtins_module == NULL)
goto out;
if (PyDict_SetItemString (globals, "__builtins__", builtins_module) != 0)
goto out;
parent = g_file_get_parent (file);
parent_path = g_file_get_path (parent);
module_dir = PyUnicode_FromString (parent_path);
if (PyDict_SetItemString (globals, "module_dir", module_dir) != 0)
goto out;
retval = PyRun_String ("import signal\n"
"import sys\n"
"if module_dir not in sys.path:\n"
" sys.path.insert(0, module_dir)\n"
"\n"
"signal.signal(signal.SIGINT, signal.SIG_DFL)\n",
Py_file_input,
globals, globals);
if (PyDict_DelItemString (globals, "module_dir") != 0)
goto out;
context = ide_object_get_context (IDE_OBJECT (self));
pycontext = pygobject_new (G_OBJECT (context));
if (pycontext == NULL)
goto out;
if (PyDict_SetItemString (globals, "Context", pycontext) != 0)
goto out;
code = Py_CompileString (contents, path, Py_file_input);
if (code == NULL)
goto out;
retval = PyEval_EvalCode (code, globals, globals);
Py_XDECREF (retval);
out:
Py_XDECREF (code);
Py_XDECREF (pycontext);
Py_XDECREF (module_dir);
Py_XDECREF (globals);
if (PyErr_Occurred ())
PyErr_Print ();
PyGILState_Release (state);
}
static void
ide_pygobject_script_unload (IdeScript *self)
{
g_return_if_fail (IDE_IS_PYGOBJECT_SCRIPT (self));
}
static void
ide_pygobject_script_class_init (IdePyGObjectScriptClass *klass)
{
IdeScriptClass *script_class = IDE_SCRIPT_CLASS (klass);
script_class->load = ide_pygobject_script_load;
script_class->unload = ide_pygobject_script_unload;
}
static void
ide_pygobject_script_init (IdePyGObjectScript *self)
{
}
static void
ide_pygobject_script_init_async (GAsyncInitable *initable,
gint io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
IdePyGObjectScript *self = (IdePyGObjectScript *)initable;
g_autoptr(GTask) task = NULL;
g_autofree gchar *path = NULL;
GFile *file;
g_return_if_fail (IDE_IS_PYGOBJECT_SCRIPT (self));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
file = ide_script_get_file (IDE_SCRIPT (self));
if (!file)
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVALID_FILENAME,
_("The filename for the script was not provided."));
return;
}
path = g_file_get_path (file);
if (!path)
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVALID_FILENAME,
_("The script must be on a local filesystem."));
return;
}
if (!g_str_has_suffix (path, ".py"))
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
_("The script “%s” is not a PyGObject file."),
path);
return;
}
ide_script_load (IDE_SCRIPT (self));
g_task_return_boolean (task, TRUE);
}
static gboolean
ide_pygobject_script_init_finish (GAsyncInitable *initable,
GAsyncResult *result,
GError **error)
{
GTask *task = (GTask *)result;
g_return_val_if_fail (IDE_IS_PYGOBJECT_SCRIPT (initable), FALSE);
g_return_val_if_fail (G_IS_TASK (task), FALSE);
return g_task_propagate_boolean (task, error);
}
static void