...
 
Commits (2)
gnudatalanguage (0.9.9-8) unstable; urgency=medium
* Switch to Python 3
-- Ole Streicher <olebole@debian.org> Thu, 10 Jan 2019 16:44:15 +0100
gnudatalanguage (0.9.9-7) unstable; urgency=medium
* Disable more long-running tests
......
......@@ -27,8 +27,8 @@ Build-Depends: cmake,
libwxgtk3.0-dev,
plplot-driver-xwin,
pslib-dev,
python-dev,
python-numpy,
python3-dev,
python3-numpy,
xauth,
xvfb,
zlib1g-dev
......@@ -60,7 +60,7 @@ Architecture: any
Depends: ${misc:Depends},
${shlibs:Depends}
Recommends: plplot-driver-xwin,
python-numpy
python3-numpy
Description: Free IDL compatible incremental compiler
GNU Data Language (GDL) is a free IDL (Interactive Data Language)
compatible incremental compiler. It has full syntax compatibility
......@@ -78,14 +78,14 @@ Description: Free IDL compatible incremental compiler
.
This package contains the main commandline and interpreter frontend.
Package: python-gdl
Package: python3-gdl
Architecture: any
Multi-Arch: same
Section: python
Depends: ${misc:Depends},
${python:Depends},
${python3:Depends},
${shlibs:Depends}
Provides: ${python:Provides}
Provides: ${python3:Provides}
Recommends: plplot-driver-xwin
Description: Python interface for the GNU Data Language
GNU Data Language (GDL) is a free IDL (Interactive Data Language)
......
From: Orion Poplawski <orion@cora.nwra.com>
Date: Wed, 19 Sep 2018 22:13:37 -0600
Subject: Initial attempt at python 3 support
---
src/CMakeLists.txt | 6 +++++-
src/datatypes.cpp | 1 +
src/gdlpython.cpp | 31 ++++++++++++++++++++++++++++++-
src/gdlpython.hpp | 4 ++++
src/pythongdl.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 89 insertions(+), 3 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d78aa1e..4c0f36e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -310,7 +310,11 @@ target_link_libraries(gnudatalanguage ${LIBRARIES})
add_definitions(-DHAVE_CONFIG_H)
if(PYTHON_MODULE)
- find_package( PythonInterp REQUIRED )
+ if (ENABLE_PYTHON3)
+ find_package( PythonInterp 3.0 REQUIRED )
+ else (ENABLE_PYTHON3)
+ find_package( PythonInterp 2.0 REQUIRED )
+ endif (ENABLE_PYTHON3)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
"import site, sys; sys.stdout.write(site.PREFIXES[-1])"
OUTPUT_VARIABLE PYTHON_PREFIX)
diff --git a/src/datatypes.cpp b/src/datatypes.cpp
index 1a8d126..e8b08a1 100644
--- a/src/datatypes.cpp
+++ b/src/datatypes.cpp
@@ -18,6 +18,7 @@
#include "includefirst.hpp"
#if defined(USE_PYTHON) || defined(PYTHON_MODULE)
+#include <patchlevel.h>
#include <numpy/arrayobject.h>
#endif
diff --git a/src/gdlpython.cpp b/src/gdlpython.cpp
index 7835ec9..dd17598 100644
--- a/src/gdlpython.cpp
+++ b/src/gdlpython.cpp
@@ -32,18 +32,32 @@
using namespace std;
+#if PY_MAJOR_VERSION >= 3
+int PythonInit()
+{
+ if( Py_IsInitialized()) return NULL;
+#else
void PythonInit()
{
if( Py_IsInitialized()) return;
+#endif
Py_Initialize(); // signal handlers?
static int argc = 1;
+#if PY_MAJOR_VERSION >= 3
+ static wchar_t* arg0 = Py_DecodeLocale("./py/python.exe",NULL);
+ static wchar_t* argv[] = {arg0};
+#else
static char* arg0 = (char*)"./py/python.exe";
static char* argv[] = {arg0};
+#endif
PySys_SetArgv(argc, argv);
// http://docs.scipy.org/doc/numpy/reference/c-api.array.html#miscellaneous
import_array();
+#if PY_MAJOR_VERSION >= 3
+ return NULL;
+#endif
}
void PythonEnd()
@@ -71,6 +85,12 @@ BaseGDL* FromPython( PyObject* pyObj)
{
if( !PyArray_Check( pyObj))
{
+#if PY_MAJOR_VERSION >= 3
+ if( PyUnicode_Check( pyObj))
+ {
+ return new DStringGDL( PyUnicode_AsUTF8( pyObj));
+ }
+#else
if( PyString_Check( pyObj))
{
return new DStringGDL( PyString_AsString( pyObj));
@@ -79,6 +99,7 @@ BaseGDL* FromPython( PyObject* pyObj)
{
return new DLongGDL( PyInt_AsLong( pyObj));
}
+#endif
if( PyLong_Check( pyObj))
{
return new DLongGDL( PyLong_AsLong( pyObj));
@@ -174,11 +195,19 @@ namespace lib {
e->Throw( "ARGV keyword must be of type STRING.");
int argc = argvS->N_Elements();
+#if PY_MAJOR_VERSION >= 3
+ wchar_t** argv = new wchar_t*[ argc];
+#else
char** argv = new char*[ argc];
+#endif
- // pyhton copies the value -> threats it as const
+ // python copies the value -> treats it as const
for( int i=0; i<argc; ++i)
+#if PY_MAJOR_VERSION >= 3
+ argv[i] = Py_DecodeLocale(const_cast<char*>((*argvS)[ i].c_str()), NULL);
+#else
argv[i] = const_cast<char*>((*argvS)[ i].c_str());
+#endif
PySys_SetArgv(argc, argv);
delete[] argv;
diff --git a/src/gdlpython.hpp b/src/gdlpython.hpp
index 45ef436..cb53bd7 100644
--- a/src/gdlpython.hpp
+++ b/src/gdlpython.hpp
@@ -18,7 +18,11 @@
#ifndef GDLPYTHON_HPP_
#define GDLPYTHON_HPP_
+#if PY_MAJOR_VERSION >= 3
+int PythonInit();
+#else
void PythonInit();
+#endif
void PythonEnd();
BaseGDL* FromPython( PyObject* pyObj);
diff --git a/src/pythongdl.cpp b/src/pythongdl.cpp
index a3b5afd..684e942 100644
--- a/src/pythongdl.cpp
+++ b/src/pythongdl.cpp
@@ -191,14 +191,22 @@ bool CopyArgFromPython( vector<BaseGDL*>& parRef,
for( SizeT k=0; k<nKW; ++k)
{
PyDict_Next( kwDict, &dictPos, &key, &value);
+#if PY_MAJOR_VERSION >= 3
+ int keyIsString = PyUnicode_Check( key);
+#else
int keyIsString = PyString_Check( key);
+#endif
if( !keyIsString)
{
PyErr_SetString( gdlError,
"Keywords must be of type string");
return false;
}
+#if PY_MAJOR_VERSION >= 3
+ const char* keyChar = PyUnicode_AsUTF8( key);
+#else
const char* keyChar = PyString_AsString( key);
+#endif
string keyString = StrUpCase( keyChar);
int kwIx = e.GetPro()->FindKey( keyString);
if( kwIx == -1)
@@ -523,9 +531,42 @@ extern "C" {
{NULL, NULL, 0, NULL} // Sentinel
};
+#if PY_MAJOR_VERSION >= 3
+ struct module_state {
+ PyObject *error;
+ };
+
+ #define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
+
+ static int GDL_traverse(PyObject *m, visitproc visit, void *arg) {
+ Py_VISIT(GETSTATE(m)->error);
+ return 0;
+ }
+
+ static int GDL_clear(PyObject *m) {
+ Py_CLEAR(GETSTATE(m)->error);
+ return 0;
+ }
+
+ static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ "GDL",
+ NULL,
+ sizeof(struct module_state),
+ GDLMethods,
+ NULL,
+ GDL_traverse,
+ GDL_clear,
+ NULL
+ };
+#endif
// python GDL module init function
- PyMODINIT_FUNC initGDL()
+#if PY_MAJOR_VERSION >= 3
+ PyMODINIT_FUNC PyInit_GDL(void)
+#else
+ PyMODINIT_FUNC initGDL(void)
+#endif
{
// http://docs.scipy.org/doc/numpy/reference/c-api.array.html#miscellaneous
import_array();
@@ -552,7 +593,11 @@ extern "C" {
}
SysVar::SetGDLPath( gdlPath);
+#if PY_MAJOR_VERSION >= 3
+ PyObject* m = PyModule_Create(&moduledef);
+#else
PyObject* m = Py_InitModule("GDL", GDLMethods);
+#endif
gdlError = PyErr_NewException((char*)"GDL.error", NULL, NULL);
Py_INCREF(gdlError);
@@ -561,6 +606,9 @@ extern "C" {
// GDL event handling
oldInputHook = PyOS_InputHook;
PyOS_InputHook = GDLEventHandlerPy;
+#if PY_MAJOR_VERSION >= 3
+ return m;
+#endif
}
} // extern "C"
......@@ -5,3 +5,4 @@ Fix-various-spelling-errors-found-by-lintian.patch
Fix-wrong-include-in-dSFMT.patch
Disable-specialized-code-that-causes-problems-on-powerpc.patch
Remove-tests-that-take-too-long-on-some-archs.patch
Initial-attempt-at-python-3-support.patch
usr/lib/python2*/dist-packages/*
usr/lib/python3*/dist-packages/*
......@@ -13,7 +13,7 @@ ifneq (,$(filter $(DEB_HOST_ARCH), mips mipsel))
endif
%:
dh $@ -Scmake --with python2
dh $@ -Scmake --with python3
override_dh_auto_configure:
dh_auto_configure -- \
......@@ -22,6 +22,7 @@ override_dh_auto_configure:
-DFFTW=YES \
-DPYTHON=YES \
-DPYTHON_MODULE=YES \
-DENABLE_PYTHON3=YES \
-DWXWIDGETS=YES \
-DGRIB=YES \
-DQHULL=YES \
......@@ -39,13 +40,6 @@ endif
override_dh_compress:
dh_compress -X.pro
# The epoch in front of python-gdl's version number is needed since
# Debian Squeeze had a python-gdl binary package with version 2.25.3-7
# built from the gnome-python-extras source package.
override_dh_gencontrol:
dh_gencontrol -ppython-gdl -- -v1:$(DEB_VERSION)
dh_gencontrol --remaining
override_dh_auto_install:
dh_auto_install
dh_numpy
dh_numpy3
......@@ -3,4 +3,4 @@ Depends: gnudatalanguage, xauth, xvfb, plplot-driver-xwin
Restrictions: allow-stderr
Tests: test-GDL.py
Depends: python-gdl, python-pytest, python-numpy
Depends: python3-gdl, python3-pytest, python3-numpy
#!/usr/bin/py.test -vv
#!/usr/bin/py.test-3 -vv
import math
import numpy
import pytest
import os
import tempfile
import warnings
if 'ADTTMP' in os.environ:
......@@ -37,11 +38,11 @@ class GDLFile (object):
self.name = None
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.fname = os.tmpnam()
self.fname = tempfile.mkstemp()[1]
self.code = code
def __enter__(self):
fp = file(self.fname, 'w')
fp = open(self.fname, 'w')
fp.write(self.code)
fp.close()
return self.name or self.fname
......@@ -73,7 +74,7 @@ def test_function_user():
# u'Hello, world',
-1.2, 1e-39, 0.0, 0.05, 1.0, 1e128, float('inf'), float('-inf'),
-1, 0, 1, 1000, 2**31-1, -2**31,
-1L, 0L, 1L, 2L**31-1, -2L**31,
# -1L, 0L, 1L, 2L**31-1, -2L**31,
# 2**45-1,
# complex(1.,1.), complex(0,0),
# numpy.arange(0, 259, dtype=int),
......@@ -131,7 +132,7 @@ def test_pro_user():
# u'Hello, world',
-1.2, 1e-39, 0.0, 0.05, 1.0, 1e128, float('inf'), float('-inf'),
-1, 0, 1, 1000, 2**31-1, -2**31,
-1L, 0L, 1L, 2L**31-1, -2L**31,
# -1L, 0L, 1L, 2L**31-1, -2L**31,
# 2**45-1,
# complex(1.,1.),
])
......@@ -149,7 +150,7 @@ def test_pro_arg_pass(arg):
with GDLFile(code) as name:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fname = os.tmpnam()
fname = tempfile.mkstemp()[1]
GDL.pro(name, fname, arg)
ret = open(fname).read().strip()
os.unlink(fname)
......@@ -185,8 +186,8 @@ def test_script():
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fname = os.tmpnam()
scriptname = os.tmpnam()
fname = tempfile.mkstemp()[1]
scriptname = tempfile.mkstemp()[1]
arg = 'Hello, world!'
code = '''openw, 5, '{0}'
printf, 5, '{1}'
......