Skip to content

Commit a98fefd

Browse files
committedMar 10, 2016
Merge pull request #2889 from m-kuhn/py3improvements
Simplify some python3 handling, refs #13686 (redmine)
2 parents 9b35a98 + 72764b2 commit a98fefd

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed
 

‎cmake/FindPythonLibrary.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ else(EXISTS "${PYTHON_INCLUDE_PATH}" AND EXISTS "${PYTHON_LIBRARY}" AND EXISTS "
4646

4747
IF (ENABLE_QT5)
4848
FIND_PACKAGE(PythonInterp 3)
49-
ADD_DEFINITIONS(-DPYTHON3)
5049
ELSE (ENABLE_QT5)
51-
FIND_PACKAGE(PythonInterp 2)
52-
ADD_DEFINITIONS(-DPYTHON2)
50+
FIND_PACKAGE(PythonInterp 2.7)
5351
ENDIF (ENABLE_QT5)
5452

5553
if(PYTHONINTERP_FOUND)

‎src/python/qgspythonutilsimpl.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ bool QgsPythonUtilsImpl::checkSystemImports()
127127
return false;
128128
}
129129
}
130-
#ifdef PYTHON2
130+
#if (PY_VERSION_HEX < 0x03000000)
131131
// import Qt bindings
132132
if ( !runString( "from PyQt4 import QtCore, QtGui",
133133
QObject::tr( "Couldn't load PyQt." ) + '\n' + QObject::tr( "Python support will be disabled." ) ) )
@@ -365,7 +365,7 @@ QString QgsPythonUtilsImpl::getTraceback()
365365
PyErr_Fetch( &type, &value, &traceback );
366366
PyErr_NormalizeException( &type, &value, &traceback );
367367

368-
#ifdef PYTHON2
368+
#if (PY_VERSION_HEX < 0x03000000)
369369
const char* iomod = "cStringIO";
370370
#else
371371
const char* iomod = "io";
@@ -403,7 +403,7 @@ QString QgsPythonUtilsImpl::getTraceback()
403403

404404
/* And it should be a string all ready to go - duplicate it. */
405405
if ( !
406-
#ifdef PYTHON2
406+
#if (PY_VERSION_HEX < 0x03000000)
407407
PyString_Check( obResult )
408408
#else
409409
PyUnicode_Check( obResult )
@@ -440,7 +440,7 @@ QString QgsPythonUtilsImpl::getTypeAsString( PyObject* obj )
440440
if ( !obj )
441441
return nullptr;
442442

443-
#ifdef PYTHON2
443+
#if (PY_VERSION_HEX < 0x03000000)
444444
if ( PyClass_Check( obj ) )
445445
{
446446
QgsDebugMsg( "got class" );
@@ -515,20 +515,11 @@ QString QgsPythonUtilsImpl::PyObjectToQString( PyObject* obj )
515515
// check whether the object is already a unicode string
516516
if ( PyUnicode_Check( obj ) )
517517
{
518-
#ifdef PYTHON2
519-
PyObject* utf8 = PyUnicode_AsUTF8String( obj );
520-
if ( utf8 )
521-
result = QString::fromUtf8( PyString_AS_STRING( utf8 ) );
522-
else
523-
result = "(qgis error)";
524-
Py_XDECREF( utf8 );
525-
#else
526518
result = PYOBJ2QSTRING( obj );
527-
#endif
528519
return result;
529520
}
530521

531-
#if PYTHON2
522+
#if (PY_VERSION_HEX < 0x03000000)
532523
// check whether the object is a classical (8-bit) string
533524
if ( PyString_Check( obj ) )
534525
{

0 commit comments

Comments
 (0)
Please sign in to comment.