Skip to content

Commit

Permalink
fix: consider PyQt-sip version not sip version
Browse files Browse the repository at this point in the history
for deprecated annotation
  • Loading branch information
t0b3 committed Dec 26, 2024
1 parent b6ef834 commit 2b7b620
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ if (WITH_CORE AND WITH_BINDINGS)
if(BUILD_WITH_QT6)
find_package(PyQt6 REQUIRED)
set(PYQT_FOUND ${PYQT6_FOUND})
set(PYQT_SIP_VERSION_STR ${PYQT6_SIP_VERSION_STR})
set(PYQT_SIP_FLAGS ${PYQT6_SIP_FLAGS})
set(PYQT_SIP_DIR ${PYQT6_SIP_DIR})
set(PYQT_SIP_IMPORT ${PYQT6_SIP_IMPORT})
Expand All @@ -1177,6 +1178,7 @@ if (WITH_CORE AND WITH_BINDINGS)
else()
find_package(PyQt5 REQUIRED)
set(PYQT_FOUND ${PYQT5_FOUND})
set(PYQT_SIP_VERSION_STR ${PYQT5_SIP_VERSION_STR})
set(PYQT_SIP_FLAGS ${PYQT5_SIP_FLAGS})
set(PYQT_SIP_DIR ${PYQT5_SIP_DIR})
set(PYQT_SIP_IMPORT ${PYQT5_SIP_IMPORT})
Expand Down
2 changes: 2 additions & 0 deletions cmake/FindPyQt5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ELSE(EXISTS PYQT5_VERSION_STR)
ENDIF(_pyqt5_metadata)

IF(PYQT5_VERSION_STR)
EXECUTE_PROCESS(COMMAND ${Python_EXECUTABLE} -c "import os; import PyQt5.sip; print(PyQt5.sip.SIP_VERSION_STR)" OUTPUT_VARIABLE PYQT5_SIP_VERSION_STR)
EXECUTE_PROCESS(COMMAND ${Python_EXECUTABLE} -c "import os; import PyQt5; print(os.path.dirname(PyQt5.__file__), end='')" OUTPUT_VARIABLE PYQT5_MOD_DIR)
SET(PYQT5_SIP_DIR "${PYQT5_MOD_DIR}/bindings")
FIND_PROGRAM(__pyuic5 "pyuic5")
Expand All @@ -50,6 +51,7 @@ ELSE(EXISTS PYQT5_VERSION_STR)
EXECUTE_PROCESS(COMMAND ${Python_EXECUTABLE} ${_find_pyqt5_py} OUTPUT_VARIABLE pyqt_config)
IF(pyqt_config)
STRING(REGEX REPLACE "^pyqt_version_str:([^\n]+).*$" "\\1" PYQT5_VERSION_STR ${pyqt_config})
STRING(REGEX REPLACE "^pyqt_sip_version_str:([^\n]+).*$" "\\1" PYQT5_SIP_VERSION_STR ${pyqt_config})
STRING(REGEX REPLACE ".*\npyqt_mod_dir:([^\n]+).*$" "\\1" PYQT5_MOD_DIR ${pyqt_config})
STRING(REGEX REPLACE ".*\npyqt_sip_dir:([^\n]+).*$" "\\1" PYQT5_SIP_DIR ${pyqt_config})
IF(EXISTS ${PYQT5_SIP_DIR}/Qt5)
Expand Down
1 change: 1 addition & 0 deletions cmake/FindPyQt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@
import PyQt5.sip

print("pyqt_sip_module:PyQt5.sip")
print("pyqt_sip_version_str:%s" % PyQt5.sip.SIP_VERSION_STR)
except:
print("pyqt_sip_module:sip")
2 changes: 2 additions & 0 deletions cmake/FindPyQt6.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ELSE(EXISTS PYQT6_VERSION_STR)
ENDIF(_pyqt6_metadata)

IF(PYQT6_VERSION_STR)
EXECUTE_PROCESS(COMMAND ${Python_EXECUTABLE} -c "import os; import PyQt6.sip; print(PyQt6.sip.SIP_VERSION_STR)" OUTPUT_VARIABLE PYQT6_SIP_VERSION_STR)
EXECUTE_PROCESS(COMMAND ${Python_EXECUTABLE} -c "import os; import PyQt6; print(os.path.dirname(PyQt6.__file__), end='')" OUTPUT_VARIABLE PYQT6_MOD_DIR)
SET(PYQT6_SIP_DIR "${PYQT6_MOD_DIR}/bindings")
FIND_PROGRAM(__pyuic6 "pyuic6")
Expand All @@ -50,6 +51,7 @@ ELSE(EXISTS PYQT6_VERSION_STR)
EXECUTE_PROCESS(COMMAND ${Python_EXECUTABLE} ${_find_pyqt6_py} OUTPUT_VARIABLE pyqt_config)
IF(pyqt_config)
STRING(REGEX REPLACE "^pyqt_version_str:([^\n]+).*$" "\\1" PYQT6_VERSION_STR ${pyqt_config})
STRING(REGEX REPLACE "^pyqt_sip_version_str:([^\n]+).*$" "\\1" PYQT6_SIP_VERSION_STR ${pyqt_config})
STRING(REGEX REPLACE ".*\npyqt_mod_dir:([^\n]+).*$" "\\1" PYQT6_MOD_DIR ${pyqt_config})
STRING(REGEX REPLACE ".*\npyqt_sip_dir:([^\n]+).*$" "\\1" PYQT6_SIP_DIR ${pyqt_config})
IF(EXISTS ${PYQT6_SIP_DIR}/Qt6)
Expand Down
1 change: 1 addition & 0 deletions cmake/FindPyQt6.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
import PyQt6.sip

print("pyqt_sip_module:PyQt6.sip")
print("pyqt_sip_version_str:%s" % PyQt6.sip.SIP_VERSION_STR)
except Exception as e:
print("pyqt_sip_module:sip")
2 changes: 1 addition & 1 deletion cmake/SIPMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ MACRO(GENERATE_SIP_PYTHON_MODULE_CODE MODULE_NAME MODULE_SIP SIP_FILES CPP_FILES
CONFIGURE_FILE(${_sip_file} ${_out_sip_file})

# Deprecated annotation supports message only since version 6.9.0
if(${SIP_VERSION_STR} VERSION_LESS 6.9.0)
if(${PYQT_SIP_VERSION_STR} VERSION_LESS 6.9.0)
file(READ ${_out_sip_file} _content)
string(REGEX REPLACE "([/,])Deprecated=\"[^\"]*\"([/,])" "\\1Deprecated\\2" _content "${_content}")
file(GENERATE OUTPUT ${_out_sip_file} CONTENT "${_content}")
Expand Down

0 comments on commit 2b7b620

Please sign in to comment.