From 624b847dd4b8c78ac03d4f63c4f323e55ae14e24 Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Thu, 20 Sep 2018 21:59:17 -0600 Subject: [PATCH] Update to latest git Port to python 3 --- .gitignore | 1 + gdl-python3.patch | 182 ++++++++++++++++++++++++++++++++++++++++++++++ gdl.spec | 57 +++++++++++++-- sources | 2 +- 4 files changed, 235 insertions(+), 7 deletions(-) create mode 100644 gdl-python3.patch diff --git a/.gitignore b/.gitignore index cf56935..55972b5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ gdl-0.9rc4.tar.gz /gdl-0.9.7.tgz /gdl-0.9.8.tgz /gdl-0.9.8-git-f3b6e01.tar.gz +/gdl-0.9.8-git-d892ee5.tar.gz diff --git a/gdl-python3.patch b/gdl-python3.patch new file mode 100644 index 0000000..8327f6b --- /dev/null +++ b/gdl-python3.patch @@ -0,0 +1,182 @@ +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 + #include + #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= 3 ++ argv[i] = Py_DecodeLocale(const_cast((*argvS)[ i].c_str()), NULL); ++#else + argv[i] = const_cast((*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..e541ba5 100644 +--- a/src/pythongdl.cpp ++++ b/src/pythongdl.cpp +@@ -191,14 +191,22 @@ bool CopyArgFromPython( vector& parRef, + for( SizeT k=0; k= 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,6 +531,35 @@ 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() +@@ -552,7 +589,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); diff --git a/gdl.spec b/gdl.spec index 8f06e8e..18a8a03 100644 --- a/gdl.spec +++ b/gdl.spec @@ -1,9 +1,9 @@ -%global commit f3b6e012ff645c93268cfb9da7f61792630c34ee +%global commit d892ee54b710c645ec0bc75d4a0cb3118813daa6 %global shortcommit %(c=%{commit}; echo ${c:0:7}) Name: gdl Version: 0.9.8 -Release: 5%{?dist}.20180723git%{shortcommit} +Release: 6%{?dist}.20180919git%{shortcommit} Summary: GNU Data Language Group: Applications/Engineering @@ -17,6 +17,8 @@ Source4: xorg.conf # Build with system antlr library. Request for upstream change here: # https://sourceforge.net/tracker/index.php?func=detail&aid=2685215&group_id=97659&atid=618686 Patch1: gdl-antlr.patch +# https://github.com/gnudatalanguage/gdl/pull/468 +Patch2: gdl-python3.patch #RHEL5 doesn't have the needed antlr version/headers, has old plplot %if 0%{?rhel} == 5 @@ -37,7 +39,11 @@ BuildRequires: java BuildRequires: readline-devel, ncurses-devel BuildRequires: gsl-devel, plplot-devel, GraphicsMagick-c++-devel BuildRequires: netcdf-devel, hdf5-devel, libjpeg-devel +%if 0%{?fedora} >= 29 +BuildRequires: python%{python3_pkgversion}-devel, python%{python3_pkgversion}-numpy, python%{python3_pkgversion}-matplotlib +%else BuildRequires: python2-devel, python2-numpy, python2-matplotlib +%endif BuildRequires: fftw-devel, hdf-static %if 0%{?fedora} %if 0%{?fedora} >= 28 @@ -90,6 +96,23 @@ BuildArch: noarch Common files for GDL +%if 0%{?fedora} >= 29 +%package -n python%{python3_pkgversion}-gdl +%{?python_provide:%python_provide python%{python3_pkgversion}-gdl} +# Remove before F30 +Provides: %{name}-python = %{version}-%{release} +Provides: %{name}-python%{?_isa} = %{version}-%{release} +Obsoletes: %{name}-python < %{version}-%{release} +Summary: GDL python module +Group: Applications/Engineering +# Needed to pull in drivers +Requires: plplot +Requires: %{name}-common = %{version}-%{release} +Provides: %{name}-runtime = %{version}-%{release} + +%description -n python%{python3_pkgversion}-gdl +%{summary}. +%else %package -n python2-gdl %{?python_provide:%python_provide python2-gdl} # Remove before F30 @@ -105,12 +128,14 @@ Provides: %{name}-runtime = %{version}-%{release} %description -n python2-gdl %{summary}. +%endif %prep %setup -q -n %{name}-%{commit} rm -rf src/antlr %patch1 -p1 -b .antlr +%patch2 -p1 -b .python3 pushd src for f in *.g @@ -119,6 +144,13 @@ do done popd +%if 0%{?fedora} >= 29 +%global __python %{__python3} +%global python_sitearch %{python3_sitearch} +%else +%global __python %{__python2} +%global python_sitearch %{python2_sitearch} +%endif %global cmake_opts \\\ -DWXWIDGETS=ON \\\ -DGEOTIFF_INCLUDE_DIR=%{_includedir}/libgeotiff \\\ @@ -126,7 +158,7 @@ popd -DUDUNITS_INCLUDE_DIR=%{_includedir}/udunits2 \\\ -DGRIB=ON \\\ -DOPENMP=ON \\\ - -DPYTHON_EXECUTABLE=%{_bindir}/python2 \\\ + -DPYTHON_EXECUTABLE=%{__python} \\\ %{?cmake_qhull} \\\ %{nil} # TODO - build an mpi version @@ -154,8 +186,13 @@ popd pushd build-python make install DESTDIR=$RPM_BUILD_ROOT # Install the python module in the right location -install -d -m 0755 $RPM_BUILD_ROOT/%{python2_sitearch} -mv $RPM_BUILD_ROOT%{_prefix}/lib/site-python/GDL.so $RPM_BUILD_ROOT%{python2_sitearch}/GDL.so +install -d -m 0755 $RPM_BUILD_ROOT/%{python_sitearch} +%if 0%{?fedora} >= 29 +mv $RPM_BUILD_ROOT%{_prefix}/lib/python*/site-packages/GDL.so \ +%else +mv $RPM_BUILD_ROOT%{_prefix}/lib/site-python/GDL.so \ +%endif + $RPM_BUILD_ROOT%{python_sitearch}/GDL.so popd # Install the profile file to set GDL_PATH @@ -239,11 +276,19 @@ cat xorg.log %files common %{_datadir}/gnudatalanguage/ +%if 0%{?fedora} >= 29 +%files -n python%{python3_pkgversion}-gdl +%else %files -n python2-gdl -%{python2_sitearch}/GDL.so +%endif +%{python_sitearch}/GDL.so %changelog +* Thu Sep 20 2018 Orion Poplawski - 0.9.8-6.20180919gitd892ee5 +- Update to latest git +- Port to python 3 + * Tue Jul 31 2018 Florian Weimer - 0.9.8-5.20180723gitf3b6e01 - Rebuild with fixed binutils diff --git a/sources b/sources index 950ef58..b554740 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -SHA512 (gdl-0.9.8-git-f3b6e01.tar.gz) = da07cd62f36e8c392bb45952a77982a3d55c1b0740debfcb277576130983d882c0502056efab1700c7f495b920567f86a8740aae61341ea403e438c55f3d103c +SHA512 (gdl-0.9.8-git-d892ee5.tar.gz) = 174dcb8a63903aa35a120459981e985bf813d0cebb576fd771b49e6101e76391a94535744c09edd75917ad3d7b3729ba21875671cceb42c3e6f0afef853a5ff2