commit:     b9f7c1bd0d361768a432b5c9ba4f3c9e751bc1da
Author:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
AuthorDate: Sat Jun 27 21:01:53 2020 +0000
Commit:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
CommitDate: Sat Jun 27 21:02:06 2020 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b9f7c1bd

app-misc/golly: port to python3

Package-Manager: Portage-2.3.103, Repoman-2.3.23
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>

 .../golly/files/golly-3.3-allow-py23-exec.patch    | 12 +++
 app-misc/golly/files/golly-3.3-allow-py3.patch     | 90 ++++++++++++++++++++++
 app-misc/golly/files/golly-3.3-glife-py23.patch    | 32 ++++++++
 .../golly/files/golly-3.3-nondynamic-python.patch  | 51 ++++++++++++
 app-misc/golly/golly-3.3-r2.ebuild                 | 29 +++++--
 5 files changed, 209 insertions(+), 5 deletions(-)

diff --git a/app-misc/golly/files/golly-3.3-allow-py23-exec.patch 
b/app-misc/golly/files/golly-3.3-allow-py23-exec.patch
new file mode 100644
index 00000000000..e46b608ed6c
--- /dev/null
+++ b/app-misc/golly/files/golly-3.3-allow-py23-exec.patch
@@ -0,0 +1,12 @@
+'execfile' is python-2-only. 'exec/open' works for both python2 and python3.
+--- a/gui-wx/wxpython.cpp
++++ b/gui-wx/wxpython.cpp
+@@ -3356,7 +3388,7 @@ void RunPythonScript(const wxString& filepath)
+     // for the global namespace so that this script cannot change the
+     // globals of a caller script (which is possible now that RunScript
+     // is re-entrant)
+-    wxString command = wxT("execfile('") + fpath + wxT("',{})");
++    wxString command = wxT("exec(open('") + fpath + wxT("').read(),{})");
+     PyRun_SimpleString(command.mb_str(wxConvLocal));
+     // don't use wxConvUTF8 in above line because caller has already converted
+     // filepath to decomposed UTF8 if on a Mac

diff --git a/app-misc/golly/files/golly-3.3-allow-py3.patch 
b/app-misc/golly/files/golly-3.3-allow-py3.patch
new file mode 100644
index 00000000000..54a04783081
--- /dev/null
+++ b/app-misc/golly/files/golly-3.3-allow-py3.patch
@@ -0,0 +1,90 @@
+The patch allows python3 as a python implementation.
+Ports module loading to conditional python3 support.
+--- a/gui-wx/configure/configure.ac
++++ b/gui-wx/configure/configure.ac
+@@ -19,7 +19,7 @@ AC_ARG_WITH([python-shlib], 
[AS_HELP_STRING([--with-python-shlib=ARG],
+       , [with_python_shlib=check])
+ AC_ARG_VAR([GOLLYDIR], [golly data directory [default=DATADIR/golly]])
+ AC_ARG_VAR([PERL], [Perl 5 interpreter])
+-AC_ARG_VAR([PYTHON], [Python 2 interpreter])
++AC_ARG_VAR([PYTHON], [Python interpreter])
+ 
+ # Check for build tools:
+ m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+@@ -76,7 +76,7 @@ AS_IF([test "x$enable_perl" = xyes], [
+ ])
+ 
+ # Find Python
+-AC_PATH_PROGS(PYTHON, [python2 python])
++AC_CHECK_PROGS(PYTHON, [python python3 python2])
+ AS_IF([test "x$PYTHON" = x], [AC_MSG_ERROR([missing Python])])
+ AC_SUBST([PYTHON_INCLUDE], [-I"'`$PYTHON -c "import distutils.sysconfig; 
print(distutils.sysconfig.get_python_inc())"`'"])
+ AS_IF([test "x$with_python_shlib" = xcheck],
+--- a/gui-wx/wxpython.cpp
++++ b/gui-wx/wxpython.cpp
+@@ -90,6 +90,12 @@
+     #include <Python.h>
+ #endif
+ 
++#if PY_MAJOR_VERSION >= 3
++    // python-3 got rid of int/log distinction
++    #define PyInt_AsLong PyLong_AsLong
++    #define PyInt_FromLong PyLong_FromLong
++#endif
++
+ #ifdef USE_PYTHON_DYNAMIC
+ 
+ #ifndef __WXMAC__
+@@ -3268,6 +3274,22 @@ static PyMethodDef py_methods[] = {
+     { NULL, NULL, 0, NULL }
+ };
+ 
++#if PY_MAJOR_VERSION >= 3
++static PyModuleDef golly_module = {
++    PyModuleDef_HEAD_INIT,
++    "golly", /* name */
++    NULL,    /* doc */
++    -1,      /* size */
++    py_methods, /* methoods */
++};
++
++PyMODINIT_FUNC
++PyInit_golly(void)
++{
++    return PyModule_Create(&golly_module);
++}
++#endif
++
+ // 
=============================================================================
+ 
+ bool pyinited = false;     // InitPython has been successfully called?
+@@ -3280,6 +3302,13 @@ bool InitPython()
+             if (!LoadPythonLib()) return false;
+         #endif
+         
++        #if PY_MAJOR_VERSION >= 3
++            // Autoload 'golly' builtin module at interpreter start.
++            if (PyImport_AppendInittab("golly", PyInit_golly) == -1) {
++                Warning(_("Error: could not extend in-built modules 
table\n"));
++            }
++        #endif
++
+         // only initialize the Python interpreter once, mainly because 
multiple
+         // Py_Initialize/Py_Finalize calls cause leaks of about 12K each time!
+         Py_Initialize();
+@@ -3287,9 +3316,12 @@ bool InitPython()
+         #ifdef USE_PYTHON_DYNAMIC
+             GetPythonExceptions();
+         #endif
+-        
+-        // allow Python to call the above py_* routines
+-        Py_InitModule((char*)"golly", py_methods);
++
++        // Python-3 uses module constructor
++        #if PY_MAJOR_VERSION < 3
++            // allow Python to call the above py_* routines
++            Py_InitModule((char*)"golly", py_methods);
++        #endif
+         
+         // catch Python messages sent to stderr and pass them to py_stderr
+         if (PyRun_SimpleString(

diff --git a/app-misc/golly/files/golly-3.3-glife-py23.patch 
b/app-misc/golly/files/golly-3.3-glife-py23.patch
new file mode 100644
index 00000000000..8b159971250
--- /dev/null
+++ b/app-misc/golly/files/golly-3.3-glife-py23.patch
@@ -0,0 +1,32 @@
+Use python-3 compatible syntax.
+--- a/Scripts/Python/glife/__init__.py
++++ b/Scripts/Python/glife/__init__.py
+@@ -90,7 +90,7 @@ def rule(s = "B3/S23"):
+ def description(s):
+     """Supply a textual description to the whole pattern."""
+     for line in s.split("\n"):
+-        print "#D", line
++        print("#D", line)
+ 
+ # --------------------------------------------------------------------
+ 
+@@ -161,7 +161,7 @@ class pattern(list):
+   It is also the base for computing generations subsequent to N-th."""
+         if N < 0:
+             raise ValueError("backward evolving requested")
+-        if self.__phases.has_key(N):
++        if N in self.__phases:
+             return self.__phases[N]
+         M = 0
+         for k in self.__phases.keys():
+--- a/Scripts/Python/glife/text.py
++++ b/Scripts/Python/glife/text.py
+@@ -173,7 +173,7 @@ def make_text (string, font='Snakial'):
+         unknown = '-'
+ 
+     for c in string:
+-        if not f.has_key (c): c = unknown
++        if not (c in f): c = unknown
+         symbol = f[c]
+         p += symbol (x, 0)
+         x += symbol.width

diff --git a/app-misc/golly/files/golly-3.3-nondynamic-python.patch 
b/app-misc/golly/files/golly-3.3-nondynamic-python.patch
new file mode 100644
index 00000000000..bc1c81a6191
--- /dev/null
+++ b/app-misc/golly/files/golly-3.3-nondynamic-python.patch
@@ -0,0 +1,51 @@
+Don't use runtime python loading via dlopen().
+
+Just link to libpython directly. That makes python dependency
+more explicit and allows catching more compile-time bugs.
+--- a/gui-wx/configure/Makefile.am
++++ b/gui-wx/configure/Makefile.am
+@@ -22,7 +22,7 @@ golly_CPPFLAGS = $(AM_CPPFLAGS) $(WX_CPPFLAGS) 
$(PYTHON_INCLUDE) \
+       $(PERL_CPPFLAGS) $(PERL_INCLUDE) \
+       $(liblua_a_CPPFLAGS) -I$(top_srcdir)/../../lua
+ golly_CXXFLAGS = $(AM_CXXFLAGS) $(WX_CXXFLAGS_ONLY)
+-golly_LDADD = $(WX_LIBS) libgolly.a liblua.a
++golly_LDADD = $(WX_LIBS) $(PYTHON_LIBS) libgolly.a liblua.a
+ 
+ if WINDOWS
+ golly_LDADD += gollyres.o
+--- a/gui-wx/configure/configure.ac
++++ b/gui-wx/configure/configure.ac
+@@ -86,6 +86,16 @@ AS_IF([test "x$with_python_shlib" = xcheck],
+ AS_IF([test "x$shlib" = x], AC_MSG_ERROR([could not determine Python shared 
library name]))
+ AC_DEFINE_UNQUOTED([PYTHON_SHLIB], [$shlib])
+ 
++# Find python interpreter
++# 1. --embed is needed for python>=3.8
++# 2. statuc check is needed because python-3.7-config outputs error to 
stdout, not stderr
++if ${PYTHON}-config --libs --embed; then
++    PYTHON_LIBS=`${PYTHON}-config --libs --embed`
++elif ${PYTHON}-config --libs; then
++    PYTHON_LIBS=`${PYTHON}-config --libs`
++fi
++AC_SUBST(PYTHON_LIBS)
++
+ # Find zlib (unless explicitly disabled)
+ AS_IF([test "x$with_zlib" != xno],
+       [       AC_CHECK_HEADER([zlib.h], , [AC_MSG_ERROR([missing zlib])])
+--- a/gui-wx/wxpython.cpp
++++ b/gui-wx/wxpython.cpp
+@@ -59,8 +59,12 @@
+     #undef SIZEOF_SIZE_T
+     #undef SIZEOF_VOID_P
+ #else
+-    // load Python lib at runtime
+-    #define USE_PYTHON_DYNAMIC
++    // On gentoo just link against python to make
++    // python dependency more explicit.
++    # if 0
++      // load Python lib at runtime
++      #define USE_PYTHON_DYNAMIC
++    #endif
+ 
+     #ifdef __UNIX__
+         // avoid warning on Linux

diff --git a/app-misc/golly/golly-3.3-r2.ebuild 
b/app-misc/golly/golly-3.3-r2.ebuild
index 9ae4bf4acd8..e3a3e4a7e59 100644
--- a/app-misc/golly/golly-3.3-r2.ebuild
+++ b/app-misc/golly/golly-3.3-r2.ebuild
@@ -4,9 +4,9 @@
 EAPI=7
 
 WX_GTK_VER=3.0
-PYTHON_COMPAT=( python2_7 )
+PYTHON_COMPAT=( python{2_7,3_{7,8,9}} )
 
-inherit desktop python-single-r1 wxwidgets xdg-utils
+inherit autotools desktop python-single-r1 wxwidgets xdg-utils
 
 DESCRIPTION="simulator for Conway's Game of Life and other cellular automata"
 HOMEPAGE="http://golly.sourceforge.net/";
@@ -20,16 +20,35 @@ REQUIRED_USE="${PYTHON_REQUIRED_USE}"
 
 DEPEND="virtual/opengl
        sys-libs/zlib
-       x11-libs/wxGTK:${WX_GTK_VER}[X,opengl,tiff?]"
-RDEPEND="${DEPEND}
-       ${PYTHON_DEPS}"
+       x11-libs/wxGTK:${WX_GTK_VER}[X,opengl,tiff?]
+       ${PYTHON_DEPS}
+"
+
+RDEPEND="${DEPEND}"
 
 S=${WORKDIR}/${P}-src
 
+PATCHES=(
+       "${FILESDIR}"/${P}-nondynamic-python.patch
+       "${FILESDIR}"/${P}-allow-py23-exec.patch
+       "${FILESDIR}"/${P}-glife-py23.patch
+       "${FILESDIR}"/${P}-allow-py3.patch
+)
+
 pkg_setup() {
+       python-single-r1_pkg_setup
        setup-wxwidgets
 }
 
+src_prepare() {
+       default
+
+       # patches change configure.ac and Makefile.am
+       pushd gui-wx/configure
+               eautoreconf
+       popd
+}
+
 src_configure() {
        ECONF_SOURCE=gui-wx/configure econf \
                --with-wxshared

Reply via email to