Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bf0ff9e
ENH: add CMake build system support and update CI
Nov 26, 2024
f1df0ec
DOC: Add documentation for installing Qt6
hjmjohnson Jun 25, 2025
a9c14ab
PERF: Don't create temporary QRegularExpression
hjmjohnson Jun 25, 2025
3a2482d
BUG: Logic bug in contenating strings.
hjmjohnson Jun 25, 2025
2d950c7
COMP: Remove use of deprecated 'count()' function
hjmjohnson Jun 25, 2025
251544a
BUG: Fix PyUnicode/PyString usage for Qt6 compatibility
hjmjohnson Jun 25, 2025
f0c4ee6
REF: Replace Q_FOREACH with range-based for loops
hjmjohnson Jun 26, 2025
b80788b
ENH: If not set, choose Release BUILD_TYPE
hjmjohnson Jun 25, 2025
f280ece
ENH: Remove QT5 modules from Qt6 QTMODULES
hjmjohnson Jun 25, 2025
e487347
BUG: Remove deprecated Qt6 paradigms
hjmjohnson Jun 25, 2025
78687fb
ENH: Set old QT_VERSION_* variables.
hjmjohnson Jun 25, 2025
7e51b05
ENH: Add src to default include directories for PythonQt.h
hjmjohnson Jun 25, 2025
2fde0d7
ENH: Improve Qt include path resolution macOS
hjmjohnson Jun 26, 2025
317240f
ENH: Removing obsolete python2 support
hjmjohnson Jun 26, 2025
e388ac3
REF: Remove outdated `PY_VERSION_HEX` conditional branches
hjmjohnson Jun 26, 2025
aadc998
ENH: Define environment variables for Python and Qt versions in CMake
hjmjohnson Jun 26, 2025
5b1bf63
ENH: Update CMake to exclude qtscript_masterinclude.h and improve Qt5…
hjmjohnson Jun 26, 2025
8d5e204
ENH: Improve Qt include directory detection in generator CMake
hjmjohnson Jun 26, 2025
f23f420
ENH: Add file existence and readability checks for generator inputs
hjmjohnson Jun 26, 2025
ab78685
ENH: Add Qt6-specific build_all file and update generator resource ha…
hjmjohnson Jun 26, 2025
fad2ce8
ENH: Simplify Qt version handling in CMake and consolidate component …
hjmjohnson Jun 26, 2025
eaadef3
ENH: Add directory existence and readability checks for include paths…
hjmjohnson Jun 26, 2025
bc9a2c8
ENH: Add debug output for object tree dumping in generator
hjmjohnson Jun 26, 2025
11c251a
ENH: Add compile definitions to enforce safer casting rules in CMake
hjmjohnson Jun 26, 2025
bbd2ed8
ENH: Refactor CMakeLists to explicitly define public headers and sour…
hjmjohnson Jun 26, 2025
261ae9b
ENH: Enhance Qt6 include directory resolution
hjmjohnson Jun 26, 2025
986707e
ENH: Update generated path in CMake to include Qt version-specific su…
hjmjohnson Jun 26, 2025
a5b65ea
ENH: Refine Qt6 include path resolution for macOS framework support
hjmjohnson Jun 26, 2025
0f1618c
BUG: Fix generated path handling in CMake to remove incorrect version…
hjmjohnson Jun 26, 2025
8ab4791
BUG: Unsupported combination headers caused build error
hjmjohnson Jun 26, 2025
da40492
REF: Replace `qAsConst` with `std::as_const` for C++17 compatibility
hjmjohnson Jun 27, 2025
e886394
REF: Replace `QVariant::Type` with `QMetaType::Type` for Qt compatibi…
hjmjohnson Jun 27, 2025
005d4b6
REF: Update verbose/optimize flag handling for Python 3.11 compatibility
hjmjohnson Jun 27, 2025
48dd28f
ENH: Disable deprecated Qt features prior to version 6 in generator
hjmjohnson Jun 27, 2025
5c189da
ENH: Propogate macro from Python3.12
hjmjohnson Jun 28, 2025
abab7cf
WIP: Remove old generated files
hjmjohnson Jun 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: Removing obsolete python2 support
`#ifndef PY3K` conditionals and related logic

Removal of PY3k ifdef ifndef not done correctly.
  • Loading branch information
hjmjohnson committed Jun 27, 2025
commit 317240f617b111dfc0c1ab5e8eb019c1163a1c92
51 changes: 2 additions & 49 deletions src/PythonQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,13 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName)
_self->_p->_pySourcelessFileLoader = importlib.getVariable("SourcelessFileLoader");
}

#ifdef PY3K
PythonQtObjectPtr asyncio;
asyncio.setNewRef(PyImport_ImportModule("asyncio"));
if (asyncio)
{
_self->_p->_pyEnsureFuture = asyncio.getVariable("ensure_future");
_self->_p->_pyFutureClass = asyncio.getVariable("Future");
}
#endif

PythonQt::priv()->setupSharedLibrarySuffixes();

Expand Down Expand Up @@ -336,11 +334,8 @@ PythonQt::PythonQt(int flags, const QByteArray& pythonQtModuleName)
_p->_initFlags = flags;

if ((flags & PythonAlreadyInitialized) == 0) {
#ifdef PY3K
Py_SetProgramName(const_cast<wchar_t*>(L"PythonQt"));
#else
Py_SetProgramName(const_cast<char*>("PythonQt"));
#endif

if (flags & IgnoreSiteModule) {
// this prevents the automatic importing of Python site files
Py_NoSiteFlag = 1;
Expand Down Expand Up @@ -430,7 +425,6 @@ void PythonQtPrivate::setTaskDoneCallback(const PythonQtObjectPtr & callable)
PythonQtObjectPtr PythonQtPrivate::checkAndRunCoroutine(const PythonQtObjectPtr& object)
{
PythonQtObjectPtr result;
#ifdef PY3K
if (!PyCoro_CheckExact(object))
{
return result;
Expand All @@ -453,9 +447,6 @@ PythonQtObjectPtr PythonQtPrivate::checkAndRunCoroutine(const PythonQtObjectPtr&
Py_XDECREF(methodName);
}
Py_XDECREF(args);
#else
Q_UNUSED(object)
#endif
return result;
}

Expand Down Expand Up @@ -989,11 +980,7 @@ QVariant PythonQt::evalCode(PyObject* object, PyObject* pycode) {
}
PyObject* r = nullptr;
if (dict) {
#ifdef PY3K
r = PyEval_EvalCode(pycode, globals, dict);
#else
r = PyEval_EvalCode((PyCodeObject*)pycode, globals, dict);
#endif
}
if (r) {
result = PythonQtConv::PyObjToQVariant(r);
Expand Down Expand Up @@ -1253,14 +1240,7 @@ QStringList PythonQt::introspectObject(PyObject* object, ObjectType type)
keys = PyDict_Keys(object);
isDict = true;
} else {
#if defined(MEVISLAB) && !defined(PY3K)
int oldPy3kWarningFlag = Py_Py3kWarningFlag;
Py_Py3kWarningFlag = 0; // temporarily disable Python 3 warnings
keys = PyObject_Dir(object);
Py_Py3kWarningFlag = oldPy3kWarningFlag;
#else
keys = PyObject_Dir(object);
#endif
}
if (keys) {
int count = PyList_Size(keys);
Expand Down Expand Up @@ -1296,9 +1276,6 @@ QStringList PythonQt::introspectObject(PyObject* object, ObjectType type)
&& value->ob_type != &PyModule_Type
&& value->ob_type != &PyType_Type
&& value->ob_type != &PythonQtSlotFunction_Type
#ifndef PY3K
&& value->ob_type != &PyClass_Type
#endif
) {
results << keystr;
}
Expand Down Expand Up @@ -1647,13 +1624,8 @@ int custom_system_exit_exception_handler()
// return exitcode;

PyErr_Fetch(&exception, &value, &tb);
#ifndef PY3K
if (Py_FlushLine()) {
PyErr_Clear();
}
#else

// TODO: unclear what to do, since Py_FlushLine is gone...
#endif
fflush(stdout);
if (value == nullptr || value == Py_None)
goto done;
Expand Down Expand Up @@ -1831,7 +1803,6 @@ static PyMethodDef PythonQtMethods[] = {
{nullptr, nullptr, 0, nullptr}
};

#ifdef PY3K
static PyModuleDef PythonQtModuleDef = {
PyModuleDef_HEAD_INIT,
"",
Expand All @@ -1843,20 +1814,15 @@ static PyModuleDef PythonQtModuleDef = {
nullptr,
nullptr
};
#endif

void PythonQt::initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQtModuleName)
{
QByteArray name = "PythonQt";
if (!pythonQtModuleName.isEmpty()) {
name = pythonQtModuleName;
}
#ifdef PY3K
PythonQtModuleDef.m_name = name.constData();
_p->_pythonQtModule = PyModule_Create(&PythonQtModuleDef);
#else
_p->_pythonQtModule = Py_InitModule(name.constData(), PythonQtMethods);
#endif
_p->_pythonQtModuleName = name;

Py_INCREF((PyObject*)&PythonQtBoolResult_Type);
Expand Down Expand Up @@ -1892,13 +1858,11 @@ void PythonQt::initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQ
}
Py_XDECREF(old_module_names);

#ifdef PY3K
PyObject* modulesAttr = PyObject_GetAttrString(sys.object(), "modules");
PyObject* pyUnicodeObject = PyUnicode_FromString(name.constData());
PyDict_SetItem(modulesAttr, pyUnicodeObject, _p->_pythonQtModule.object());
Py_XDECREF(modulesAttr);
Py_XDECREF(pyUnicodeObject);
#endif
}

QString PythonQt::getReturnTypeOfWrappedMethod(PyObject* module, const QString& name)
Expand Down Expand Up @@ -2232,9 +2196,6 @@ bool PythonQtPrivate::isMethodDescriptor(PyObject* object) const
!PyObject_HasAttrString(object, "__set__") &&
!PyMethod_Check(object) &&
!PyFunction_Check(object)
#ifndef PY3K
&& !PyClass_Check(object)
#endif
) {
return true;
}
Expand Down Expand Up @@ -2596,20 +2557,12 @@ void PythonQtPrivate::shellClassDeleted( void* shellClass )

PyObject* PythonQtPrivate::wrapMemoryAsBuffer( const void* data, Py_ssize_t size )
{
#ifdef PY3K
return PyMemoryView_FromMemory((char*)data, size, PyBUF_READ);
#else
return PyBuffer_FromMemory((char*)data, size);
#endif
}

PyObject* PythonQtPrivate::wrapMemoryAsBuffer( void* data, Py_ssize_t size )
{
#ifdef PY3K
return PyMemoryView_FromMemory((char*)data, size, PyBUF_WRITE);
#else
return PyBuffer_FromReadWriteMemory((char*)data, size);
#endif
}

PythonQtClassInfo* PythonQtPrivate::getClassInfo( const QMetaObject* meta )
Expand Down
6 changes: 0 additions & 6 deletions src/PythonQt.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,9 @@ typedef QObject* PythonQtQObjectCreatorFunctionCB();
template<class T> QObject* PythonQtCreateObject() { return new T(); }

//! Helper define to convert from QString to Python C-API
#ifdef PY3K
#define QStringToPythonConstCharPointer(arg) ((arg).toUtf8().constData())
#define QStringToPythonCharPointer(arg) ((arg).toUtf8().data())
#define QStringToPythonEncoding(arg) ((arg).toUtf8())
#else
#define QStringToPythonConstCharPointer(arg) ((arg).toLatin1().constData())
#define QStringToPythonCharPointer(arg) ((arg).toLatin1().data())
#define QStringToPythonEncoding(arg) ((arg).toLatin1())
#endif

//! The main interface to the Python Qt binding, realized as a singleton
/*!
Expand Down
16 changes: 0 additions & 16 deletions src/PythonQtBoolResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ static PyNumberMethods PythonQtBoolResult_as_number = {
nullptr, /* nb_add */
nullptr, /* nb_subtract */
nullptr, /* nb_multiply */
#ifndef PY3K
nullptr, /* nb_divide */
#endif
nullptr, /* nb_remainder */
nullptr, /* nb_divmod */
nullptr, /* nb_power */
Expand All @@ -85,22 +82,12 @@ static PyNumberMethods PythonQtBoolResult_as_number = {
nullptr, /* nb_and */
nullptr, /* nb_xor */
nullptr, /* nb_or */
#ifndef PY3K
nullptr, /* nb_coerce */
#endif
nullptr, /* nb_int */
nullptr, /* nb_long / nb_reserved in Py3K */
nullptr, /* nb_float */
#ifndef PY3K
nullptr, /* nb_oct */
nullptr, /* nb_hex */
#endif
nullptr, /* nb_inplace_add */
nullptr, /* nb_inplace_subtract */
nullptr, /* nb_inplace_multiply */
#ifndef PY3K
nullptr, /* nb_inplace_divide */
#endif
nullptr, /* nb_inplace_remainder */
nullptr, /* nb_inplace_power */
nullptr, /* nb_inplace_lshift */
Expand All @@ -112,9 +99,7 @@ static PyNumberMethods PythonQtBoolResult_as_number = {
nullptr, /* nb_true_divide */
nullptr, /* nb_inplace_floor_divide */
nullptr, /* nb_inplace_true_divide */
#ifdef PY3K
nullptr, /* nb_index in Py3K */
#endif
};

PyTypeObject PythonQtBoolResult_Type = {
Expand Down Expand Up @@ -155,4 +140,3 @@ PyTypeObject PythonQtBoolResult_Type = {
0, /* tp_dictoffset */
(initproc)&PythonQtBoolResult_init, /* tp_init */
};

19 changes: 0 additions & 19 deletions src/PythonQtClassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,6 @@ static void initializeSlots(PythonQtClassWrapper* wrap)
wrap->_base.as_number.nb_multiply = (binaryfunc)PythonQtInstanceWrapper_mul;
}
if (typeSlots & PythonQt::Type_Divide) {
#ifndef PY3K
wrap->_base.as_number.nb_divide = (binaryfunc)PythonQtInstanceWrapper_div;
#endif
wrap->_base.as_number.nb_true_divide = (binaryfunc)PythonQtInstanceWrapper_div;
}
if (typeSlots & PythonQt::Type_And) {
Expand Down Expand Up @@ -294,9 +291,6 @@ static void initializeSlots(PythonQtClassWrapper* wrap)
wrap->_base.as_number.nb_inplace_multiply = (binaryfunc)PythonQtInstanceWrapper_imul;
}
if (typeSlots & PythonQt::Type_InplaceDivide) {
#ifndef PY3K
wrap->_base.as_number.nb_inplace_divide = (binaryfunc)PythonQtInstanceWrapper_idiv;
#endif
wrap->_base.as_number.nb_inplace_true_divide = (binaryfunc)PythonQtInstanceWrapper_idiv;
}
if (typeSlots & PythonQt::Type_InplaceAnd) {
Expand All @@ -321,11 +315,7 @@ static void initializeSlots(PythonQtClassWrapper* wrap)
wrap->_base.as_number.nb_invert = (unaryfunc)PythonQtInstanceWrapper_invert;
}
if (typeSlots & PythonQt::Type_NonZero) {
#ifdef PY3K
wrap->_base.as_number.nb_bool = (inquiry)PythonQtInstanceWrapper_nonzero;
#else
wrap->_base.as_number.nb_nonzero = (inquiry)PythonQtInstanceWrapper_nonzero;
#endif
}
}
}
Expand Down Expand Up @@ -564,11 +554,7 @@ static PyObject *PythonQtClassWrapper_getattro(PyObject *obj, PyObject *name)
}

// look for the internal methods (className(), help())
#ifdef PY3K
PyObject* internalMethod = PyObject_GenericGetAttr(obj, name);
#else
PyObject* internalMethod = Py_FindMethod( PythonQtClassWrapper_methods, obj, (char*)attributeName);
#endif
if (internalMethod) {
return internalMethod;
}
Expand Down Expand Up @@ -635,11 +621,7 @@ PyTypeObject PythonQtClassWrapper_Type = {
0, /* tp_weaklistoffset */
nullptr, /* tp_iter */
nullptr, /* tp_iternext */
#ifdef PY3K
PythonQtClassWrapper_methods, /* tp_methods */
#else
nullptr, /* tp_methods */
#endif
nullptr, /* tp_members */
nullptr, /* tp_getset */
nullptr, /* tp_base */
Expand All @@ -654,4 +636,3 @@ PyTypeObject PythonQtClassWrapper_Type = {
};

//-------------------------------------------------------

Loading