Gentoo Archives: gentoo-commits

From: Sergei Trofimovich <slyfox@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-misc/golly/files/, app-misc/golly/
Date: Sat, 27 Jun 2020 21:02:12
Message-Id: 1593291726.b9f7c1bd0d361768a432b5c9ba4f3c9e751bc1da.slyfox@gentoo
1 commit: b9f7c1bd0d361768a432b5c9ba4f3c9e751bc1da
2 Author: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jun 27 21:01:53 2020 +0000
4 Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
5 CommitDate: Sat Jun 27 21:02:06 2020 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b9f7c1bd
7
8 app-misc/golly: port to python3
9
10 Package-Manager: Portage-2.3.103, Repoman-2.3.23
11 Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>
12
13 .../golly/files/golly-3.3-allow-py23-exec.patch | 12 +++
14 app-misc/golly/files/golly-3.3-allow-py3.patch | 90 ++++++++++++++++++++++
15 app-misc/golly/files/golly-3.3-glife-py23.patch | 32 ++++++++
16 .../golly/files/golly-3.3-nondynamic-python.patch | 51 ++++++++++++
17 app-misc/golly/golly-3.3-r2.ebuild | 29 +++++--
18 5 files changed, 209 insertions(+), 5 deletions(-)
19
20 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
21 new file mode 100644
22 index 00000000000..e46b608ed6c
23 --- /dev/null
24 +++ b/app-misc/golly/files/golly-3.3-allow-py23-exec.patch
25 @@ -0,0 +1,12 @@
26 +'execfile' is python-2-only. 'exec/open' works for both python2 and python3.
27 +--- a/gui-wx/wxpython.cpp
28 ++++ b/gui-wx/wxpython.cpp
29 +@@ -3356,7 +3388,7 @@ void RunPythonScript(const wxString& filepath)
30 + // for the global namespace so that this script cannot change the
31 + // globals of a caller script (which is possible now that RunScript
32 + // is re-entrant)
33 +- wxString command = wxT("execfile('") + fpath + wxT("',{})");
34 ++ wxString command = wxT("exec(open('") + fpath + wxT("').read(),{})");
35 + PyRun_SimpleString(command.mb_str(wxConvLocal));
36 + // don't use wxConvUTF8 in above line because caller has already converted
37 + // filepath to decomposed UTF8 if on a Mac
38
39 diff --git a/app-misc/golly/files/golly-3.3-allow-py3.patch b/app-misc/golly/files/golly-3.3-allow-py3.patch
40 new file mode 100644
41 index 00000000000..54a04783081
42 --- /dev/null
43 +++ b/app-misc/golly/files/golly-3.3-allow-py3.patch
44 @@ -0,0 +1,90 @@
45 +The patch allows python3 as a python implementation.
46 +Ports module loading to conditional python3 support.
47 +--- a/gui-wx/configure/configure.ac
48 ++++ b/gui-wx/configure/configure.ac
49 +@@ -19,7 +19,7 @@ AC_ARG_WITH([python-shlib], [AS_HELP_STRING([--with-python-shlib=ARG],
50 + , [with_python_shlib=check])
51 + AC_ARG_VAR([GOLLYDIR], [golly data directory [default=DATADIR/golly]])
52 + AC_ARG_VAR([PERL], [Perl 5 interpreter])
53 +-AC_ARG_VAR([PYTHON], [Python 2 interpreter])
54 ++AC_ARG_VAR([PYTHON], [Python interpreter])
55 +
56 + # Check for build tools:
57 + m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
58 +@@ -76,7 +76,7 @@ AS_IF([test "x$enable_perl" = xyes], [
59 + ])
60 +
61 + # Find Python
62 +-AC_PATH_PROGS(PYTHON, [python2 python])
63 ++AC_CHECK_PROGS(PYTHON, [python python3 python2])
64 + AS_IF([test "x$PYTHON" = x], [AC_MSG_ERROR([missing Python])])
65 + AC_SUBST([PYTHON_INCLUDE], [-I"'`$PYTHON -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_inc())"`'"])
66 + AS_IF([test "x$with_python_shlib" = xcheck],
67 +--- a/gui-wx/wxpython.cpp
68 ++++ b/gui-wx/wxpython.cpp
69 +@@ -90,6 +90,12 @@
70 + #include <Python.h>
71 + #endif
72 +
73 ++#if PY_MAJOR_VERSION >= 3
74 ++ // python-3 got rid of int/log distinction
75 ++ #define PyInt_AsLong PyLong_AsLong
76 ++ #define PyInt_FromLong PyLong_FromLong
77 ++#endif
78 ++
79 + #ifdef USE_PYTHON_DYNAMIC
80 +
81 + #ifndef __WXMAC__
82 +@@ -3268,6 +3274,22 @@ static PyMethodDef py_methods[] = {
83 + { NULL, NULL, 0, NULL }
84 + };
85 +
86 ++#if PY_MAJOR_VERSION >= 3
87 ++static PyModuleDef golly_module = {
88 ++ PyModuleDef_HEAD_INIT,
89 ++ "golly", /* name */
90 ++ NULL, /* doc */
91 ++ -1, /* size */
92 ++ py_methods, /* methoods */
93 ++};
94 ++
95 ++PyMODINIT_FUNC
96 ++PyInit_golly(void)
97 ++{
98 ++ return PyModule_Create(&golly_module);
99 ++}
100 ++#endif
101 ++
102 + // =============================================================================
103 +
104 + bool pyinited = false; // InitPython has been successfully called?
105 +@@ -3280,6 +3302,13 @@ bool InitPython()
106 + if (!LoadPythonLib()) return false;
107 + #endif
108 +
109 ++ #if PY_MAJOR_VERSION >= 3
110 ++ // Autoload 'golly' builtin module at interpreter start.
111 ++ if (PyImport_AppendInittab("golly", PyInit_golly) == -1) {
112 ++ Warning(_("Error: could not extend in-built modules table\n"));
113 ++ }
114 ++ #endif
115 ++
116 + // only initialize the Python interpreter once, mainly because multiple
117 + // Py_Initialize/Py_Finalize calls cause leaks of about 12K each time!
118 + Py_Initialize();
119 +@@ -3287,9 +3316,12 @@ bool InitPython()
120 + #ifdef USE_PYTHON_DYNAMIC
121 + GetPythonExceptions();
122 + #endif
123 +-
124 +- // allow Python to call the above py_* routines
125 +- Py_InitModule((char*)"golly", py_methods);
126 ++
127 ++ // Python-3 uses module constructor
128 ++ #if PY_MAJOR_VERSION < 3
129 ++ // allow Python to call the above py_* routines
130 ++ Py_InitModule((char*)"golly", py_methods);
131 ++ #endif
132 +
133 + // catch Python messages sent to stderr and pass them to py_stderr
134 + if (PyRun_SimpleString(
135
136 diff --git a/app-misc/golly/files/golly-3.3-glife-py23.patch b/app-misc/golly/files/golly-3.3-glife-py23.patch
137 new file mode 100644
138 index 00000000000..8b159971250
139 --- /dev/null
140 +++ b/app-misc/golly/files/golly-3.3-glife-py23.patch
141 @@ -0,0 +1,32 @@
142 +Use python-3 compatible syntax.
143 +--- a/Scripts/Python/glife/__init__.py
144 ++++ b/Scripts/Python/glife/__init__.py
145 +@@ -90,7 +90,7 @@ def rule(s = "B3/S23"):
146 + def description(s):
147 + """Supply a textual description to the whole pattern."""
148 + for line in s.split("\n"):
149 +- print "#D", line
150 ++ print("#D", line)
151 +
152 + # --------------------------------------------------------------------
153 +
154 +@@ -161,7 +161,7 @@ class pattern(list):
155 + It is also the base for computing generations subsequent to N-th."""
156 + if N < 0:
157 + raise ValueError("backward evolving requested")
158 +- if self.__phases.has_key(N):
159 ++ if N in self.__phases:
160 + return self.__phases[N]
161 + M = 0
162 + for k in self.__phases.keys():
163 +--- a/Scripts/Python/glife/text.py
164 ++++ b/Scripts/Python/glife/text.py
165 +@@ -173,7 +173,7 @@ def make_text (string, font='Snakial'):
166 + unknown = '-'
167 +
168 + for c in string:
169 +- if not f.has_key (c): c = unknown
170 ++ if not (c in f): c = unknown
171 + symbol = f[c]
172 + p += symbol (x, 0)
173 + x += symbol.width
174
175 diff --git a/app-misc/golly/files/golly-3.3-nondynamic-python.patch b/app-misc/golly/files/golly-3.3-nondynamic-python.patch
176 new file mode 100644
177 index 00000000000..bc1c81a6191
178 --- /dev/null
179 +++ b/app-misc/golly/files/golly-3.3-nondynamic-python.patch
180 @@ -0,0 +1,51 @@
181 +Don't use runtime python loading via dlopen().
182 +
183 +Just link to libpython directly. That makes python dependency
184 +more explicit and allows catching more compile-time bugs.
185 +--- a/gui-wx/configure/Makefile.am
186 ++++ b/gui-wx/configure/Makefile.am
187 +@@ -22,7 +22,7 @@ golly_CPPFLAGS = $(AM_CPPFLAGS) $(WX_CPPFLAGS) $(PYTHON_INCLUDE) \
188 + $(PERL_CPPFLAGS) $(PERL_INCLUDE) \
189 + $(liblua_a_CPPFLAGS) -I$(top_srcdir)/../../lua
190 + golly_CXXFLAGS = $(AM_CXXFLAGS) $(WX_CXXFLAGS_ONLY)
191 +-golly_LDADD = $(WX_LIBS) libgolly.a liblua.a
192 ++golly_LDADD = $(WX_LIBS) $(PYTHON_LIBS) libgolly.a liblua.a
193 +
194 + if WINDOWS
195 + golly_LDADD += gollyres.o
196 +--- a/gui-wx/configure/configure.ac
197 ++++ b/gui-wx/configure/configure.ac
198 +@@ -86,6 +86,16 @@ AS_IF([test "x$with_python_shlib" = xcheck],
199 + AS_IF([test "x$shlib" = x], AC_MSG_ERROR([could not determine Python shared library name]))
200 + AC_DEFINE_UNQUOTED([PYTHON_SHLIB], [$shlib])
201 +
202 ++# Find python interpreter
203 ++# 1. --embed is needed for python>=3.8
204 ++# 2. statuc check is needed because python-3.7-config outputs error to stdout, not stderr
205 ++if ${PYTHON}-config --libs --embed; then
206 ++ PYTHON_LIBS=`${PYTHON}-config --libs --embed`
207 ++elif ${PYTHON}-config --libs; then
208 ++ PYTHON_LIBS=`${PYTHON}-config --libs`
209 ++fi
210 ++AC_SUBST(PYTHON_LIBS)
211 ++
212 + # Find zlib (unless explicitly disabled)
213 + AS_IF([test "x$with_zlib" != xno],
214 + [ AC_CHECK_HEADER([zlib.h], , [AC_MSG_ERROR([missing zlib])])
215 +--- a/gui-wx/wxpython.cpp
216 ++++ b/gui-wx/wxpython.cpp
217 +@@ -59,8 +59,12 @@
218 + #undef SIZEOF_SIZE_T
219 + #undef SIZEOF_VOID_P
220 + #else
221 +- // load Python lib at runtime
222 +- #define USE_PYTHON_DYNAMIC
223 ++ // On gentoo just link against python to make
224 ++ // python dependency more explicit.
225 ++ # if 0
226 ++ // load Python lib at runtime
227 ++ #define USE_PYTHON_DYNAMIC
228 ++ #endif
229 +
230 + #ifdef __UNIX__
231 + // avoid warning on Linux
232
233 diff --git a/app-misc/golly/golly-3.3-r2.ebuild b/app-misc/golly/golly-3.3-r2.ebuild
234 index 9ae4bf4acd8..e3a3e4a7e59 100644
235 --- a/app-misc/golly/golly-3.3-r2.ebuild
236 +++ b/app-misc/golly/golly-3.3-r2.ebuild
237 @@ -4,9 +4,9 @@
238 EAPI=7
239
240 WX_GTK_VER=3.0
241 -PYTHON_COMPAT=( python2_7 )
242 +PYTHON_COMPAT=( python{2_7,3_{7,8,9}} )
243
244 -inherit desktop python-single-r1 wxwidgets xdg-utils
245 +inherit autotools desktop python-single-r1 wxwidgets xdg-utils
246
247 DESCRIPTION="simulator for Conway's Game of Life and other cellular automata"
248 HOMEPAGE="http://golly.sourceforge.net/"
249 @@ -20,16 +20,35 @@ REQUIRED_USE="${PYTHON_REQUIRED_USE}"
250
251 DEPEND="virtual/opengl
252 sys-libs/zlib
253 - x11-libs/wxGTK:${WX_GTK_VER}[X,opengl,tiff?]"
254 -RDEPEND="${DEPEND}
255 - ${PYTHON_DEPS}"
256 + x11-libs/wxGTK:${WX_GTK_VER}[X,opengl,tiff?]
257 + ${PYTHON_DEPS}
258 +"
259 +
260 +RDEPEND="${DEPEND}"
261
262 S=${WORKDIR}/${P}-src
263
264 +PATCHES=(
265 + "${FILESDIR}"/${P}-nondynamic-python.patch
266 + "${FILESDIR}"/${P}-allow-py23-exec.patch
267 + "${FILESDIR}"/${P}-glife-py23.patch
268 + "${FILESDIR}"/${P}-allow-py3.patch
269 +)
270 +
271 pkg_setup() {
272 + python-single-r1_pkg_setup
273 setup-wxwidgets
274 }
275
276 +src_prepare() {
277 + default
278 +
279 + # patches change configure.ac and Makefile.am
280 + pushd gui-wx/configure
281 + eautoreconf
282 + popd
283 +}
284 +
285 src_configure() {
286 ECONF_SOURCE=gui-wx/configure econf \
287 --with-wxshared