diff --git a/docs/index.rst b/docs/index.rst index 9435be6..dd5a12c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -215,6 +215,13 @@ plugin and Python interpreter. .. versionadded:: 1.1.0 +.. versionchanged:: 1.5.0 + Previously, :func:`pythonVersion` returned the compile-time version of + Python against which PyOtherSide was built. Starting with version 1.5.0, + the run-time version of Python is returned (e.g. PyOtherSide compiled + against Python 3.4.0 and running with Python 3.4.1 returned "3.4.0" + before, but returns "3.4.1" in PyOtherSide after and including 1.5.0). + QML ``PyGLArea`` Element ------------------------ @@ -1355,6 +1362,7 @@ Version 1.5.0 (UNRELEASED) * Spport for `OpenGL rendering in Python`_ using PyOpenGL >= 3.1.0 * New QML components: ``PyGLArea``, ``PyFBO`` +* :func:`pythonVersion` now returns the runtime Python version Version 1.4.0 (2015-02-19) -------------------------- diff --git a/src/qpython.cpp b/src/qpython.cpp index e73a19b..830df58 100644 --- a/src/qpython.cpp +++ b/src/qpython.cpp @@ -365,6 +365,25 @@ QPython::pluginVersion() QString QPython::pythonVersion() { + if (SINCE_API_VERSION(1, 5)) { + ENSURE_GIL_STATE; + + PyObjectRef version_info(PySys_GetObject("version_info")); + if (version_info && PyTuple_Check(version_info.borrow()) && + PyTuple_Size(version_info.borrow()) >= 3) { + + QStringList parts; + for (int i=0; i<3; i++) { + PyObjectRef part(PyTuple_GetItem(version_info.borrow(), i)); + parts << convertPyObjectToQVariant(part.borrow()).toString(); + } + return parts.join('.'); + } + + // Fallback to the compile-time version below + qWarning("Could not determine runtime Python version"); + } + return QString(PY_VERSION); }