Resurrected standalone python module

This commit is contained in:
Yevgen Muntyan 2011-04-16 12:31:54 -07:00
parent 417e24b1c5
commit b62fbb5ae8
19 changed files with 219 additions and 184 deletions

View File

@ -42,8 +42,6 @@ test:
$(MAKE) $(AM_MAKEFLAGS) installcheck
fullcheck:
$(MAKE) $(AM_MAKEFLAGS) test
DISTCHECK_CONFIGURE_FLAGS='MAKEFLAGS=-j3 --without-python --enable-silent-rules CFLAGS="-Werror -Wall -O2" CXXFLAGS="-Werror -Wall -O2"' \
$(MAKE) $(AM_MAKEFLAGS) distcheck
$(MAKE) $(AM_MAKEFLAGS) distcheck
@MOO_PO_SUBDIRS_RULE@

View File

@ -9,22 +9,29 @@ srcdir=`cd "$rel_srcdir" && pwd`
cd "$srcdir"
# autoreconf --verbose --install --force || exit $!
run_cmd() {
echo "$@"
"$@" || exit $!
}
# run_cmd libtoolize --copy --force
run_cmd libtoolize --copy --force
run_cmd $ACLOCAL --force -I m4 $ACLOCAL_FLAGS
run_cmd $AUTOCONF --force
run_cmd $AUTOHEADER --force
run_cmd $AUTOMAKE --add-missing --copy --force-missing
cd $workingdir
run_configure=true
configure_args="--enable-dev-mode --enable-silent-rules"
if [ "$1" ]; then
cd $workingdir && run_cmd $rel_srcdir/configure --enable-dev-mode "$@"
:
else
echo "Done. Run '$rel_srcdir/configure --enable-dev-mode' to configure"
echo "Done. Run '$rel_srcdir/configure --enable-dev-mode' to configure and then 'make' to build"
run_configure=false
fi
if $run_configure; then
run_cmd $rel_srcdir/configure $configure_args "$@"
fi

View File

@ -21,8 +21,10 @@ AC_GNU_SOURCE
AC_CONFIG_MACRO_DIR([m4])
AC_SUBST(ACLOCAL_FLAGS)
AM_INIT_AUTOMAKE([1.11 silent-rules foreign dist-bzip2 no-dist-gzip])
# LT_INIT([disable-shared])
AM_INIT_AUTOMAKE([1.11 foreign dist-bzip2 no-dist-gzip])
AM_SILENT_RULES([yes])
LT_INIT([disable-shared])
# AC_PROG_RANLIB
AC_SUBST(MOO_MAJOR_VERSION,_moo_major_version_)
AC_SUBST(MOO_MINOR_VERSION,_moo_minor_version_)
@ -54,12 +56,11 @@ AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_MKDIR_P
AM_PROG_CC_C_O
AC_PROG_RANLIB
AC_ARG_VAR([WINDRES], [windres])
AC_CHECK_TOOL(WINDRES, windres, :)
AC_ARG_VAR([PYTHON], [Python executable, used to run build scripts])
AC_ARG_VAR([PYTHON], [Python executable, required to run build scripts])
AC_CHECK_PROGS(PYTHON, python, [AC_MSG_ERROR([Python not found])])
MOO_AC_FLAGS
@ -89,6 +90,33 @@ AC_DEFINE_UNQUOTED(MOO_WEB_CONTACT,["$MOO_WEB_CONTACT"],MOO_WEB_CONTACT)
MOO_AC_CHECK_OS
MOO_AC_PYTHON
MOO_BUILD_APP=true
MOO_BUILD_MODULE=false
AC_ARG_ENABLE(moo-module,
AC_HELP_STRING([--enable-moo-module],[build standalone python module instead of medit, default NO (you must also use --enable-shared with this option)]),[
if test "$enable_moo_module" = "yes"; then
MOO_BUILD_APP=false
MOO_BUILD_MODULE=true
fi
])
if $MOO_BUILD_MODULE; then
if ! $MOO_ENABLE_PYTHON; then
AC_MSG_ERROR([Python bindings are not enabled, can't build python module])
elif test "$enable_shared" != "yes"; then
AC_MSG_ERROR([Python module can't be built without --enable-shared option])
fi
fi
if $MOO_BUILD_APP; then
AC_DEFINE(MOO_BUILD_APP, 1, [build medit application])
fi
if $MOO_BUILD_MODULE; then
AC_DEFINE(MOO_BUILD_MODULE, 1, [build standalone python module])
fi
AM_CONDITIONAL(MOO_BUILD_APP, [$MOO_BUILD_APP])
AM_CONDITIONAL(MOO_BUILD_MODULE, [$MOO_BUILD_MODULE])
AC_SUBST(MOO_TOP_SRCDIR,`cd $srcdir && pwd`)
if test x"$MOO_TOP_SRCDIR" = x"`pwd`"; then
AC_SUBST(MOO_CP_TO_SRCDIR,true)
@ -130,7 +158,11 @@ AC_ARG_ENABLE(install-hooks,
AC_HELP_STRING([--enable-install-hooks],[run gtk-update-icon-cache during 'make install']),[
MOO_ENABLE_INSTALL_HOOKS="$enable_install_hooks"
],[
MOO_ENABLE_INSTALL_HOOKS="yes"
if $MOO_BUILD_APP; then
MOO_ENABLE_INSTALL_HOOKS="yes"
else
MOO_ENABLE_INSTALL_HOOKS="no"
fi
])
AM_CONDITIONAL(MOO_ENABLE_INSTALL_HOOKS, test "x$MOO_ENABLE_INSTALL_HOOKS" = "xyes")

View File

@ -146,5 +146,7 @@ uninstall-local:
$(DESTDIR)$(MOO_HELP_DIR)/img/*.png
if MOO_OS_UNIX
if MOO_BUILD_APP
dist_man_MANS = built/medit.1
endif MOO_BUILD_APP
endif MOO_OS_UNIX

View File

@ -107,20 +107,27 @@ AC_DEFUN([MOO_AC_CHECK_PYTHON_NATIVE],[
AC_DEFUN([MOO_AM_PYTHON_DEVEL_CROSS_MINGW],[
if test x"$PYTHON_INCLUDES" = x; then
AC_MSG_ERROR([PYTHON_INCLUDES is not set])
fi
if test x"$PYTHON_LIBS" = x; then
AC_MSG_ERROR([PYTHON_LIBS is not set])
if test x"$PYTHON_INCLUDES" = x -o x"$PYTHON_LIBS" = x -o x"$PYTHON_VERSION" = x; then
AC_MSG_ERROR([The following variables must be set: PYTHON_INCLUDES, PYTHON_LIBS, PYTHON_VERSION])
fi
AC_ARG_VAR([PYTHON_INCLUDES], [python preprocessor flags])
AC_ARG_VAR([PYTHON_LIBS], [python linker flags])
AC_ARG_VAR([PYTHON_VERSION], [python version])
AC_SUBST(PYTHON_INCLUDES)
AC_SUBST(PYTHON_LIBS)
AC_MSG_CHECKING([for Python include path])
AC_MSG_RESULT([$PYTHON_INCLUDES])
AC_MSG_CHECKING([for Python linker flags])
AC_MSG_RESULT([$PYTHON_LIBS])
AC_SUBST([PYTHON_VERSION],[$PYTHON_VERSION])
AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
AC_SUBST([PYTHON_PLATFORM], [nt])
AC_SUBST([pythondir], [$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages])
AC_SUBST([pyexecdir], [$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages])
$1
])

View File

@ -37,6 +37,7 @@ include moolua/Makefile.incl
include moopython/Makefile.incl
include plugins/Makefile.incl
include medit-app/Makefile.incl
include medit-module/Makefile.incl
BUILT_SOURCES += $(built_moo_sources) $(built_plugin_sources)
CLEANFILES += $(built_moo_sources) $(built_plugin_sources)

View File

@ -1,5 +1,3 @@
bin_PROGRAMS += medit
EXTRA_DIST += medit-app/data
dist-hook: delete-junk-from-data
delete-junk-from-data:
@ -11,6 +9,13 @@ EXTRA_DIST += \
medit-app/run-tests-installed.sh \
medit-app/run-tests-uninstalled.sh
EXTRA_DIST += medit-app/medit.rc.in
EXTRA_DIST += medit-app/medit.desktop.in
if MOO_BUILD_APP
bin_PROGRAMS += medit
TESTS = medit-app/run-tests-uninstalled.sh
TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) top_srcdir=$(top_srcdir) bindir=$(bindir) PYTHON=$(PYTHON) print_functions=$(srcdir)/medit-app/print-functions.py
@ -47,20 +52,11 @@ nodist_medit_SOURCES = \
$(built_moo_sources) \
$(built_plugins_sources)
BUILT_SOURCES += \
$(built_moo_sources) \
$(built_plugins_sources)
CLEANFILES += \
$(built_moo_sources) \
$(built_plugins_sources)
medit_LDFLAGS =
if MOO_OS_WIN32
medit_LDFLAGS += -mwindows
endif
EXTRA_DIST += medit-app/medit.rc.in
if MOO_OS_WIN32
CLEANFILES += medit-app/medit.rc medit-app/medit.res
medit-app/medit.rc: medit-app/medit.rc.in $(top_builddir)/config.status
@ -71,7 +67,6 @@ medit-app/medit.res: medit-app/medit.rc
medit_LDADD += medit-app/medit.res
endif
EXTRA_DIST += medit-app/medit.desktop.in
if MOO_OS_UNIX
desktopdir = $(datadir)/applications
desktop_DATA = medit-app/medit.desktop
@ -81,7 +76,6 @@ medit-app/medit.desktop: medit-app/medit.desktop.in @MOO_INTLTOOL_INI_DEPS@
CLEANFILES += medit-app/medit.desktop
endif MOO_OS_UNIX
iconthemedir = $(datadir)/icons/hicolor/48x48/apps
icontheme_DATA = mooutils/pixmaps/medit.png
if MOO_ENABLE_INSTALL_HOOKS
@ -98,3 +92,5 @@ uninstall-hook: uninstall-data-hook-gtk-icon-cache
uninstall-data-hook-gtk-icon-cache:
@if echo "Updating icon cache" && $(update_icon_cache); then echo "Done."; else echo "Failed."; fi
endif
endif MOO_BUILD_APP

View File

@ -0,0 +1,36 @@
if MOO_BUILD_MODULE
pyexec_LTLIBRARIES = _moo.la
_moo_la_LDFLAGS = -avoid-version -module
_moo_la_CFLAGS = $(AM_CFLAGS)
_moo_la_CXXFLAGS = $(AM_CXXFLAGS)
if MOO_OS_WIN32
_moo_la_LDFLAGS += -no-undefined -shrext .pyd
endif
python_DATA = moopython/pygtk/moo.py
_moo_la_SOURCES = \
medit-module/medit-module.cpp \
$(moo_sources) \
$(plugins_sources)
_moo_la_LIBADD = $(MOO_LIBS) $(moo_libadd)
nodist__moo_la_SOURCES = \
$(built_moo_sources) \
$(built_plugins_sources)
EXTRA_DIST += medit-module/moo.rc.in
if MOO_OS_WIN32
CLEANFILES += medit-module/moo.rc medit-module/moo.res
medit-module/moo.rc: medit-module/moo.rc.in $(top_builddir)/config.status
$(AM_V_at)$(MKDIR_P) medit-module
$(AM_V_GEN)cd $(top_builddir) && ./config.status --silent --file=moo/medit-module/moo.rc
medit-module/moo.res: medit-module/moo.rc
$(AM_V_GEN)$(WINDRES) -i medit-module/moo.rc --input-format=rc -o medit-module/moo.res -O coff
_moo_la_LIBADD += medit-module/moo.res
endif
endif MOO_BUILD_MODULE

View File

@ -0,0 +1,7 @@
#include <moopython/pygtk/moo-pygtk.h>
extern "C"
void init_moo (void)
{
_moo_module_init ();
}

View File

@ -0,0 +1,30 @@
#include <windows.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION @MOO_MAJOR_VERSION@,@MOO_MINOR_VERSION@,@MOO_MICRO_VERSION@,0
PRODUCTVERSION @MOO_MAJOR_VERSION@,@MOO_MINOR_VERSION@,@MOO_MICRO_VERSION@,0
FILEFLAGSMASK 0
FILEFLAGS 0
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "@MOO_WEBSITE@"
VALUE "FileDescription", "moo"
VALUE "FileVersion", "@MOO_MAJOR_VERSION@.@MOO_MINOR_VERSION@.@MOO_MICRO_VERSION@.0"
VALUE "InternalName", "moo"
VALUE "LegalCopyright", "@MOO_COPYRIGHT@"
VALUE "OriginalFilename", "moo.pyd"
VALUE "ProductName", "moo"
VALUE "ProductVersion", "@MOO_DISPLAY_VERSION@"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END

View File

@ -28,6 +28,27 @@
#include "moopython/pygtk/moo-pygtk.h"
#include "moopython/moopython-pygtkmod.h"
#include "mooutils/mooutils-misc.h"
#include "moopython/pygtk/moo-mod.h"
static gboolean create_moo_module (void)
{
PyObject *moo_module;
PyObject *code;
code = Py_CompileString (MOO_PY, "moo.py", Py_file_input);
if (!code)
return FALSE;
moo_module = PyImport_ExecCodeModule ((char*) "moo", code);
if (!moo_module)
PyErr_Print ();
Py_DECREF (code);
return !PyErr_Occurred ();
}
gboolean
_moo_python_builtin_init (void)
@ -40,17 +61,23 @@ _moo_python_builtin_init (void)
return FALSE;
}
if (!_moo_pygtk_init ())
if (!_moo_module_init ())
{
g_warning ("could not initialize _moo module");
PyErr_Print ();
moo_python_api_deinit ();
return FALSE;
}
reset_log_func ();
if (!create_moo_module ())
{
g_warning ("could not initialize moo module");
PyErr_Print ();
moo_python_api_deinit ();
return FALSE;
}
#ifndef MOO_BUILD_MOO_MODULE
reset_log_func ();
#endif
}
if (!moo_plugin_loader_lookup (MOO_PYTHON_PLUGIN_LOADER_ID))

View File

@ -24,7 +24,7 @@ from moo import D_
try:
import vte
except ImportError:
moo.cancel_plugin_loading()
moo._cancel_plugin_loading()
TERMINAL_PLUGIN_ID = "Terminal"
COLOR_SCHEME_KEY = 'Plugins/Terminal/color_scheme'

View File

@ -19,7 +19,6 @@
#include "config.h"
#endif
#include "moopython/pygtk/moo-mod.h"
#include "moopython/pygtk/moo-pygtk.h"
#include "moopython/moopython-utils.h"
#include <pygobject.h> /* _PyGObjectAPI lives here */
@ -75,11 +74,9 @@ py_object_to_moo_py_object (GValue *value, PyObject *obj)
}
gboolean
_moo_pygtk_init (void)
_moo_module_init (void)
{
PyObject *_moo_module = NULL;
PyObject *moo_module = NULL;
PyObject *code;
init_pygtk_mod ();
@ -102,21 +99,6 @@ _moo_pygtk_init (void)
_moo_add_constants (_moo_module, "MOO_");
_moo_register_classes (PyModule_GetDict (_moo_module));
if (PyErr_Occurred ())
return FALSE;
code = Py_CompileString (MOO_PY, "moo.py", Py_file_input);
if (!code)
return FALSE;
moo_module = PyImport_ExecCodeModule ((char*) "moo", code);
if (!moo_module)
PyErr_Print ();
Py_DECREF (code);
return !PyErr_Occurred ();
}

View File

@ -21,7 +21,7 @@
G_BEGIN_DECLS
gboolean _moo_pygtk_init (void);
gboolean _moo_module_init (void);
extern const PyMethodDef _moo_functions[];

View File

@ -19,20 +19,21 @@ import gtk as _gtk
import gobject as _gobject
from _moo import *
# note, these aren't standard gettext functions
_ = gettext
D_ = dgettext
def N_(string):
return string
class _PluginWontLoad(Exception):
def __repr__(self):
return 'PluginWontLoad'
def cancel_plugin_loading():
def _cancel_plugin_loading():
raise _PluginWontLoad()
def N_(string):
return string
class ActionFactory(object):
class _ActionFactory(object):
def __init__(self, action_id, **kwargs):
object.__init__(self)
self.id = action_id
@ -70,4 +71,4 @@ def window_class_add_action(klass, action_id, group=None, **kwargs):
if kwargs.has_key("factory"):
_moo._window_class_add_action(klass, action_id, group, kwargs["factory"])
else:
_moo._window_class_add_action(klass, action_id, group, ActionFactory(action_id, **kwargs))
_moo._window_class_add_action(klass, action_id, group, _ActionFactory(action_id, **kwargs))

View File

@ -1,120 +0,0 @@
#
# mooedit-mod.py
#
# Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
#
# This file is part of medit. medit 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 2.1 of the License,
# or (at your option) any later version.
#
# You should have received a copy of the GNU Lesser General Public
# License along with medit. If not, see <http://www.gnu.org/licenses/>.
#
"""moo.edit module
Contains text editor and stuff.
To get an instance of Editor, the object which manages document instances,
use Editor.instance().
To create new or open existing document, use Editor.create_doc().
To save or close document use Edit.save() and Edit.close().
To find out status of document (unsaved, deleted from disk, etc.) use
Edit.get_status, it returns flags from EditStatus class.
Note that by default Editor shows alerts in various places, like when
user tries to close document with unsaved changes. To disable this,
use 'silent' property: editor.set_property("silent", True).
"""
import _moo_edit as _edit
from _moo_edit import *
#from _moo_edit import Plugin as _Plugin
#import gobject
def edit_class_add_action(cls, action_id, action_class):
_edit._edit_class_add_action(cls, action_id, action_class)
class _PluginWontLoad(Exception):
def __repr__(self):
return 'PluginWontLoad'
def cancel_plugin_loading():
raise _PluginWontLoad()
#class _UIInfo(object):
#def __init__(self, parent, action, name=None, index=-1):
#self.parent = parent
#self.action = action
#self.name = name or action
#self.index = index
#class _WindowActionInfo(object):
#def __init__(self, window_type, id, **kwargs):
#self.window_type = window_type
#self.id = id
#self.props = kwargs
#class _EditActionInfo(object):
#def __init__(self, id, action_type, edit_type = Edit):
#self.id = id
#self.action_type = action_type
#self.edit_type = edit_type
#class Plugin(_Plugin):
#def __init__(self):
#_Plugin.__init__(self)
#self._window_actions = []
#self._edit_actions = []
#self._ui_merge_id = 0
#self._ui = []
#def do_init(self):
#import moo
#for a in self._window_actions:
#moo.utils.window_class_add_action(a.window_type, a.id, **a.props)
#for a in self._edit_actions:
#edit_class_add_action(a.edit_type, a.id, a.action_type)
#if self._ui:
#editor = Editor.instance()
#xml = editor.get_ui_xml()
#self._ui_merge_id = xml.new_merge_id()
#for item in self._ui:
#xml.add_item(self._ui_merge_id, item.parent,
#item.name, item.action, item.index)
#return True
#def do_deinit(self):
#import moo
#if self._ui_merge_id:
#editor = Editor.instance()
#xml = editor.get_ui_xml()
#xml.remove_ui(self._ui_merge_id)
#self._ui_merge_id = 0
#for a in self._window_actions:
#moo.utils.window_class_remove_action(a.window_type, a.id)
#for a in self._edit_actions:
#edit_class_remove_action(a.edit_type, a.id)
#""" add_ui(self, parent, action, name=None, index=-1) -> None"""
#def add_ui(self, *args, **kwargs):
#self._ui.append(_UIInfo(*args, **kwargs))
#""" add_edit_action(self, id, action_type, edit_type = Edit) -> None"""
#def add_edit_action(self, *args, **kwargs):
#self._edit_actions.append(_EditActionInfo(*args, **kwargs))
#""" add_window_action(self, window_type, id, **kwargs) -> None"""
#def add_window_action(self, *args, **kwargs):
#self._window_actions.append(_WindowActionInfo(*args, **kwargs))
#gobject.type_register(Plugin)

View File

@ -1,5 +1,7 @@
export mgwbuildroot=$HOME/projects/gtk-win-build
export mgwpythonver=27
export mgwpythondotver=2.7
export mgwpythonver=`echo $mgwpythondotver | sed 's/[.]//'`
export mgwdir_s=$mgwdir
export mgwdir=`cd $mgwdir && pwd`

View File

@ -72,6 +72,7 @@ export PKG_CONFIG_PATH="$mgwtargetdir/lib/pkgconfig"
export PYTHON_INCLUDES="-I$mgwtargetdir/include/python"
export PYTHON_LIBS="-lpython$mgwpythonver"
export PYTHON_VERSION=$mgwpythondotver
configure_args="--build=i686-pc-linux-gnu --host=i586-pc-mingw32msvc --target=i586-pc-mingw32msvc \
AR=$AR RANLIB=$RANLIB STRIP=$STRIP AS=$AS DLLTOOL=$DLLTOOL OBJDUMP=$OBJDUMP NM=$NM WINDRES=$WINDRES RC=$RC \
@ -90,5 +91,10 @@ else
moo_configure_args='--enable-dev-mode'
fi
if [ "$1" = "--python" ]; then
shift
moo_configure_args="$moo_configure_args --enable-moo-module --enable-shared --disable-static"
fi
echo $srcdir/configure $configure_args $moo_configure_args $moo_nls_flags "$@"
exec $srcdir/configure $configure_args $moo_configure_args $moo_nls_flags "$@"

View File

@ -38,13 +38,32 @@ check_unix() {
set_title "medit-release unix build"
do_or_die mkdir $tmpdir/build-unix
do_or_die cd $tmpdir/build-unix
do_or_die $tmpdir/medit/configure --enable-dev-mode --enable-silent-rules
do_or_die $tmpdir/medit/configure --enable-dev-mode
do_or_die make
set_title "medit-release unix fullcheck"
do_or_die make fullcheck
do_or_die mv medit-*.tar.bz2 $tmpdir/files/
}
check_no_python() {
set_title "medit-release unix-no-python build"
do_or_die mkdir $tmpdir/build-unix-no-python
do_or_die cd $tmpdir/build-unix-no-python
do_or_die $tmpdir/medit/configure --enable-dev-mode --without-python
do_or_die make
set_title "medit-release unix-no-python fullcheck"
do_or_die make fullcheck
do_or_die mv medit-*.tar.bz2 $tmpdir/files/
}
check_python() {
set_title "medit-release unix-python build"
do_or_die mkdir $tmpdir/build-unix-python
do_or_die cd $tmpdir/build-unix-python
do_or_die $tmpdir/medit/configure --enable-dev-mode --enable-moo-module --disable-static
do_or_die make
}
check_windows() {
set_title "medit-release windows build"
do_or_die mkdir $tmpdir/build-windows
@ -58,6 +77,8 @@ check_windows() {
prepare
check_unix
check_no_python
check_python
check_windows
echo "============================================================="