[graphics/krita/krita/4.3] /: Add support for SIP v5 bindings
Dmitry Kazakov
null at kde.org
Tue Aug 3 09:35:54 BST 2021
Git commit b263b56680f575a51bc9b6d9bb47070f3c1532f1 by Dmitry Kazakov, on behalf of L. E. Segovia.
Committed on 03/08/2021 at 08:35.
Pushed by dkazakov into branch 'krita/4.3'.
Add support for SIP v5 bindings
SIP v5 and above rely on a PEP-0518 based tooling system to build
bindings (usually distutils). v4, as our currently supported generator,
is only a dummy tool -- it relies on the user to compile and link the
bindings.
This commit adds support for SIP v5.
- I've added a "sip-generate" tool, that differs from the standard
sip-build in that it only generates the binding glue; this relies on a
private, undocumented method of the sipbuild.Builder class.
- The cmake/modules directory now has a pyproject.toml skeleton
manifest, which is processed by the new add_sip_python_module_v5 macro.
It works identically to the v4 macro, but targets the sip-generate tool.
Compilation happens in the exact same was as we do with v4.
Key remarks:
- All the data must be now injected in the skeleton manifest (as opposed
to build flags in v4).
- SIP v5 makes use of protected Qt methods; for this reason, it supplies
a "protected-as-public" override, which I emulate in the
add_sip_python_module_v5 macro.
- Like v4, v5 also needs to be told the fully qualified name of the SIP
package (e.g. `import PyQt5.sip` -- PyQt5.sip is the value). Otherwise,
the native library will not find the package and the initialization will
fail.
- The initialization function changes, from "PyInit_pykrita" to
"PyInit_krita" (the innermost module name). This has been macro'd for
backwards compatibility.
BUG: 415743
CCMAIL: kimageshop at kde.org
(cherry picked from commit 5bb4874ad04b771a0fec12827de748780b5b395b)
M +8 -3 cmake/modules/FindPyQt5.cmake
M +9 -3 cmake/modules/FindPyQt5.py
M +3 -3 cmake/modules/FindSIP.cmake
M +42 -12 cmake/modules/FindSIP.py
M +103 -6 cmake/modules/SIPMacros.cmake
A +15 -0 cmake/modules/pyproject.toml.in
A +24 -0 cmake/modules/sip-generate.py
M +5 -6 plugins/extensions/pykrita/plugin/PykritaModule.cpp
M +11 -3 plugins/extensions/pykrita/plugin/PykritaModule.h
M +4 -1 plugins/extensions/pykrita/plugin/config.h.cmake
M +5 -4 plugins/extensions/pykrita/plugin/utilities.cpp
M +33 -25 plugins/extensions/pykrita/sip/CMakeLists.txt
https://invent.kde.org/graphics/krita/commit/b263b56680f575a51bc9b6d9bb47070f3c1532f1
diff --git a/cmake/modules/FindPyQt5.cmake b/cmake/modules/FindPyQt5.cmake
index 62928602f0..bbbfa52279 100644
--- a/cmake/modules/FindPyQt5.cmake
+++ b/cmake/modules/FindPyQt5.cmake
@@ -1,8 +1,9 @@
# Find PyQt5
# ~~~~~~~~~~
-# Copyright (c) 2014, Simon Edwards <simon at simonzone.com>
-# Redistribution and use is allowed according to the terms of the BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+# SPDX-FileCopyrightText: 2014 Simon Edwards <simon at simonzone.com>
+# SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
+#
+# SPDX-License-Identifier: BSD-3-Clause
#
# PyQt5 website: http://www.riverbankcomputing.co.uk/pyqt/index.php
#
@@ -21,6 +22,8 @@
# PYQT5_SIP_DIR - The directory holding the PyQt5 .sip files.
#
# PYQT5_SIP_FLAGS - The SIP flags used to build PyQt.
+#
+# PYQT5_SIP_TAGS - The SIP tags necessary to bind to PyQt. (v5+)
IF(EXISTS PYQT5_VERSION)
# Already in cache, be silent
@@ -49,6 +52,8 @@ ELSE(EXISTS PYQT5_VERSION)
STRING(REGEX REPLACE ".*\npyqt_version_tag:([^\n]+).*$" "\\1" PYQT5_VERSION_TAG ${pyqt5_config})
STRING(REGEX REPLACE ".*\npyqt_sip_dir:([^\n]+).*$" "\\1" PYQT5_SIP_DIR ${pyqt5_config})
STRING(REGEX REPLACE ".*\npyqt_sip_flags:([^\n]+).*$" "\\1" PYQT5_SIP_FLAGS ${pyqt5_config})
+ STRING(REGEX REPLACE ".*\npyqt_sip_tags:([^\n]+).*$" "\\1" _tags ${pyqt5_config})
+ STRING(REPLACE "," ";" PYQT5_SIP_TAGS ${_tags})
IF(${pyqt5_config} MATCHES pyqt_sip_name)
STRING(REGEX REPLACE ".*\npyqt_sip_name:([^\n]+).*$" "\\1" PYQT5_SIP_NAME ${pyqt5_config})
ENDIF(${pyqt5_config} MATCHES pyqt_sip_name)
diff --git a/cmake/modules/FindPyQt5.py b/cmake/modules/FindPyQt5.py
index 85c662b9ae..e4293d5be7 100644
--- a/cmake/modules/FindPyQt5.py
+++ b/cmake/modules/FindPyQt5.py
@@ -1,7 +1,10 @@
-# Copyright (c) 2014, Simon Edwards <simon at simonzone.com>
-# Redistribution and use is allowed according to the terms of the BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+# SPDX-FileCopyrightText: 2014 Simon Edwards <simon at simonzone.com>
+# SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+import re
import sys
import os
from distutils.sysconfig import get_python_lib
@@ -47,3 +50,6 @@ if not os.path.exists(pyqt_sip_dir): # Fallback for older PyQt5/SIP
print("pyqt_sip_dir:%s" % pyqt_sip_dir)
print("pyqt_sip_flags:%s" % PyQt5.QtCore.PYQT_CONFIGURATION["sip_flags"])
+
+tags = re.findall(r"-t ([^\s]+)", PyQt5.QtCore.PYQT_CONFIGURATION["sip_flags"])
+print("pyqt_sip_tags:%s" % ",".join(tags))
diff --git a/cmake/modules/FindSIP.cmake b/cmake/modules/FindSIP.cmake
index c02136e6cb..e0a6f97d74 100644
--- a/cmake/modules/FindSIP.cmake
+++ b/cmake/modules/FindSIP.cmake
@@ -43,10 +43,10 @@ ELSE(SIP_VERSION)
STRING(REGEX REPLACE "^sip_version:([^\n]+).*$" "\\1" SIP_VERSION ${sip_config})
STRING(REGEX REPLACE ".*\nsip_version_str:([^\n]+).*$" "\\1" SIP_VERSION_STR ${sip_config})
STRING(REGEX REPLACE ".*\nsip_bin:([^\n]+).*$" "\\1" SIP_EXECUTABLE ${sip_config})
- IF(NOT SIP_DEFAULT_SIP_DIR)
- STRING(REGEX REPLACE ".*\ndefault_sip_dir:([^\n]+).*$" "\\1" SIP_DEFAULT_SIP_DIR ${sip_config})
- ENDIF(NOT SIP_DEFAULT_SIP_DIR)
IF(${SIP_VERSION_STR} VERSION_LESS 5)
+ IF(NOT SIP_DEFAULT_SIP_DIR)
+ STRING(REGEX REPLACE ".*\ndefault_sip_dir:([^\n]+).*$" "\\1" SIP_DEFAULT_SIP_DIR ${sip_config})
+ ENDIF(NOT SIP_DEFAULT_SIP_DIR)
STRING(REGEX REPLACE ".*\nsip_inc_dir:([^\n]+).*$" "\\1" SIP_INCLUDE_DIR ${sip_config})
FILE(TO_CMAKE_PATH ${SIP_INCLUDE_DIR} SIP_INCLUDE_DIR)
ELSE(${SIP_VERSION_STR} VERSION_LESS 5)
diff --git a/cmake/modules/FindSIP.py b/cmake/modules/FindSIP.py
index 9fb032f8e5..424620d6ee 100644
--- a/cmake/modules/FindSIP.py
+++ b/cmake/modules/FindSIP.py
@@ -1,26 +1,56 @@
# FindSIP.py
#
-# Copyright (c) 2007, Simon Edwards <simon at simonzone.com>
-# Redistribution and use is allowed according to the terms of the BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+# SPDX-FileCopyrightText: 2007 Simon Edwards <simon at simonzone.com>
+# SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+import os
+
+def osAwareExecutable(filename):
+ return filename if os.name != 'nt' else filename + ".exe"
+
+def osAwareSuffix():
+ return os.path.join("lib", "python3.8", "site-packages","sipconfig.py") if os.name != 'nt' else os.path.join("lib","krita-python-libs","sipconfig.py")
try:
- import sipbuild
-except ImportError: # Code for SIP v4
import sipconfig
sipcfg = sipconfig.Configuration()
- print("sip_version:%06.0x" % sipcfg.sip_version)
- print("sip_version_str:%s" % sipcfg.sip_version_str)
- print("sip_bin:%s" % sipcfg.sip_bin)
- print("default_sip_dir:%s" % sipcfg.default_sip_dir)
- print("sip_inc_dir:%s" % sipcfg.sip_inc_dir)
-else: # Code for SIP v5
+ sip_version = sipcfg.sip_version
+ sip_version_str = sipcfg.sip_version_str
+ sip_bin = sipcfg.sip_bin
+ default_sip_dir = sipcfg.default_sip_dir
+ sip_inc_dir = sipcfg.sip_inc_dir
+ if not os.path.isfile(osAwareExecutable(sip_bin)):
+ # Relocated deps, attempt to fix the paths...
+ sipconfig_path = os.path.abspath(sipconfig.__file__)
+ sipconfig_expected_suffix = osAwareSuffix()
+ if sipconfig_path.endswith(sipconfig_expected_suffix):
+ deps_prefix = sipconfig_path[:-len(sipconfig_expected_suffix)]
+ sip_bin_expected_suffix = os.path.join("bin","sip")
+ if sip_bin.endswith(sip_bin_expected_suffix):
+ orig_prefix = sip_bin[:-len(sip_bin_expected_suffix)]
+ if os.path.isfile(osAwareExecutable(sip_bin.replace(orig_prefix, deps_prefix, 1))):
+ sip_bin = sip_bin.replace(orig_prefix, deps_prefix, 1)
+ default_sip_dir = default_sip_dir.replace(orig_prefix, deps_prefix, 1)
+ sip_inc_dir = sip_inc_dir.replace(orig_prefix, deps_prefix, 1)
+ print("sip_version:%06.0x" % sip_version)
+ print("sip_version_str:%s" % sip_version_str)
+ print("sip_bin:%s" % sip_bin)
+ print("default_sip_dir:%s" % default_sip_dir)
+ print("sip_inc_dir:%s" % sip_inc_dir)
+except ImportError: # Code for SIP v5+
+ import sipbuild
+
print("sip_version:%06.0x" % sipbuild.version.SIP_VERSION)
print("sip_version_str:%s" % sipbuild.version.SIP_VERSION_STR)
import shutil
- print("sip_bin:%s" % shutil.which("sip5"))
+
+ # sip v5 and higher need to invoke sip-build
+ print("sip_bin:%s" % shutil.which("sip-build"))
from distutils.sysconfig import get_python_lib
python_modules_dir = get_python_lib(plat_specific=1)
diff --git a/cmake/modules/SIPMacros.cmake b/cmake/modules/SIPMacros.cmake
index bd60188878..f71879cad4 100644
--- a/cmake/modules/SIPMacros.cmake
+++ b/cmake/modules/SIPMacros.cmake
@@ -41,6 +41,8 @@ SET(SIP_CONCAT_PARTS 8)
SET(SIP_DISABLE_FEATURES)
SET(SIP_EXTRA_OPTIONS)
+if (${SIP_VERSION_STR} VERSION_LESS 5)
+
MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
SET(EXTRA_LINK_LIBRARIES ${ARGN})
@@ -99,12 +101,6 @@ MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
COMMAND ${SIP_EXECUTABLE} ${_sip_tags} ${_sip_x} ${SIP_EXTRA_OPTIONS} -j ${SIP_CONCAT_PARTS} -c ${CMAKE_CURRENT_SIP_OUTPUT_DIR} ${_sip_includes} ${_abs_module_sip}
DEPENDS ${_abs_module_sip} ${SIP_EXTRA_FILES_DEPEND}
)
- IF (SIP_MODULE_EXECUTABLE)
- ADD_CUSTOM_COMMAND(
- OUTPUT ${_sip_output_files} APPEND
- COMMAND ${SIP_MODULE_EXECUTABLE} --target-dir ${CMAKE_CURRENT_SIP_OUTPUT_DIR} --sip-h ${PYQT5_SIP_NAME}
- )
- ENDIF (SIP_MODULE_EXECUTABLE)
# not sure if type MODULE could be uses anywhere, limit to cygwin for now
IF (WIN32 OR CYGWIN OR APPLE)
ADD_LIBRARY(${_logical_name} MODULE ${_sip_output_files} )
@@ -126,3 +122,104 @@ MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
INSTALL(TARGETS ${_logical_name} DESTINATION "${PYTHON_SITE_PACKAGES_INSTALL_DIR}/${_parent_module_path}")
ENDMACRO(ADD_SIP_PYTHON_MODULE)
+
+else()
+ find_file(sip_generate "sip-generate.py" PATHS ${CMAKE_MODULE_PATH})
+ find_file(pyproject_toml "pyproject.toml.in" PATHS ${CMAKE_MODULE_PATH})
+
+ macro(add_sip_python_module_v5 MODULE_NAME MODULE_SIP)
+ get_filename_component(module_name_toml ${MODULE_SIP} NAME_WE)
+ set(module_srcs "${SIP_EXTRA_FILES_DEPEND}")
+
+ set(EXTRA_LINK_LIBRARIES ${ARGN})
+
+ if (SIP_MODULE)
+ set(sip_name ${SIP_MODULE})
+ else()
+ set(sip_name "sip")
+ endif()
+
+ set(module_tags)
+ foreach(_tag ${SIP_TAGS})
+ string(APPEND module_tags "\"${_tag}\",")
+ endforeach()
+ set(module_tags "[${module_tags}]")
+
+ set(sip_include_dirs)
+ foreach(_inc ${SIP_INCLUDES})
+ get_filename_component(_abs_inc ${_inc} ABSOLUTE)
+ string(APPEND sip_include_dirs "\"${_abs_inc}\",")
+ endforeach()
+ set(sip_include_dirs "[${sip_include_dirs}]")
+
+ string(REPLACE "." "/" _x ${MODULE_NAME})
+ get_filename_component(_parent_module_path ${_x} PATH)
+ get_filename_component(_child_module_name ${_x} NAME)
+
+ get_filename_component(_module_path ${MODULE_SIP} PATH)
+
+ set(CMAKE_CURRENT_SIP_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/_tmp")
+
+ get_filename_component(_abs_module_sip ${MODULE_SIP} ABSOLUTE)
+
+ # We give this target a long logical target name.
+ # (This is to avoid having the library name clash with any already
+ # install library names. If that happens then cmake dependency
+ # tracking get confused.)
+ string(REPLACE "." "_" _logical_name ${MODULE_NAME})
+ set(_logical_name "python_module_${_logical_name}")
+
+ set(_sip_output_files)
+ foreach(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS})
+ if(${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS})
+ set(_sip_output_files ${_sip_output_files} ${CMAKE_CURRENT_SIP_OUTPUT_DIR}/${_child_module_name}/sip${_child_module_name}part${CONCAT_NUM}.cpp )
+ endif( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS})
+ endforeach(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS})
+
+ configure_file(
+ ${pyproject_toml}
+ ${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml
+ )
+ add_custom_command(
+ COMMAND
+ ${CMAKE_COMMAND} -E echo "Generating SIP 5+ bindings for ${MODULE_NAME}..."
+ COMMAND
+ ${PYTHON_EXECUTABLE}
+ ${sip_generate}
+ --build-dir ${CMAKE_CURRENT_SIP_OUTPUT_DIR}
+ --target-dir ${PYTHON_SITE_PACKAGES_INSTALL_DIR}/${_parent_module_path}
+ --concatenate ${SIP_CONCAT_PARTS}
+ WORKING_DIRECTORY
+ ${CMAKE_CURRENT_BINARY_DIR}
+ DEPENDS
+ ${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml
+ OUTPUT
+ ${_sip_output_files}
+ )
+
+ # not sure if type MODULE could be usec anywhere, limit to cygwin for now
+ if (WIN32 OR CYGWIN OR APPLE)
+ add_library(${_logical_name} MODULE ${_sip_output_files})
+ else ()
+ add_library(${_logical_name} SHARED ${_sip_output_files})
+ endif ()
+ target_include_directories(${_logical_name} PRIVATE ${CMAKE_CURRENT_SIP_OUTPUT_DIR})
+ target_link_libraries(${_logical_name} ${PYTHON_LIBRARY})
+ target_link_libraries(${_logical_name} ${EXTRA_LINK_LIBRARIES})
+ set_target_properties(${_logical_name} PROPERTIES PREFIX "" OUTPUT_NAME ${_child_module_name})
+
+ if (MINGW)
+ target_compile_definitions(${_logical_name} PRIVATE _hypot=hypot)
+ else()
+ # SIP v5+ redefines access to protected variables.
+ target_compile_definitions(${_logical_name} PRIVATE SIP_PROTECTED_IS_PUBLIC)
+ target_compile_definitions(${_logical_name} PRIVATE protected=public)
+ endif ()
+
+ if (WIN32)
+ SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES SUFFIX ".pyd")
+ ENDIF ()
+
+ install(TARGETS ${_logical_name} DESTINATION "${PYTHON_SITE_PACKAGES_INSTALL_DIR}/${_parent_module_path}")
+ endmacro()
+endif()
diff --git a/cmake/modules/pyproject.toml.in b/cmake/modules/pyproject.toml.in
new file mode 100644
index 0000000000..090b2d4b0c
--- /dev/null
+++ b/cmake/modules/pyproject.toml.in
@@ -0,0 +1,15 @@
+[build-system]
+requires = ["sip >=5, <7", "PyQt5"]
+build-backend = "sipbuild.api"
+
+[tool.sip.metadata]
+name = "@module_name_toml@"
+
+[tool.sip.project]
+sip-module = "@sip_name@"
+sip-include-dirs = @sip_include_dirs@
+sip-files-dir = "@module_srcs@"
+abi-version = "12"
+
+[tool.sip.bindings. at module_name_toml@]
+tags = @module_tags@
diff --git a/cmake/modules/sip-generate.py b/cmake/modules/sip-generate.py
new file mode 100644
index 0000000000..d55116a230
--- /dev/null
+++ b/cmake/modules/sip-generate.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+# SPDX-FileCopyrightText: 2019 Riverbank Computing Limited
+# SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from sipbuild.abstract_project import AbstractProject
+from sipbuild.exceptions import handle_exception
+
+def main():
+ """ Generate the project bindings from the command line. """
+
+ try:
+ project = AbstractProject.bootstrap(
+ 'build', "Generate the project bindings.")
+ project.builder._generate_bindings()
+ project.progress("The project bindings are ready for build.")
+ except Exception as e:
+ handle_exception(e)
+
+ return 0
+
+if __name__ == "__main__":
+ main()
diff --git a/plugins/extensions/pykrita/plugin/PykritaModule.cpp b/plugins/extensions/pykrita/plugin/PykritaModule.cpp
index 517468a805..ada790be02 100644
--- a/plugins/extensions/pykrita/plugin/PykritaModule.cpp
+++ b/plugins/extensions/pykrita/plugin/PykritaModule.cpp
@@ -1,8 +1,9 @@
// This file is part of PyKrita, Krita' Python scripting plugin.
//
-// Copyright (C) 2006 Paul Giannaros <paul at giannaros.org>
-// Copyright (C) 2012, 2013 Shaheed Haque <srhaque at theiet.org>
-// Copyright (C) 2013 Alex Turbov <i.zaufi at gmail.com>
+// SPDX-FileCopyrightText: 2006 Paul Giannaros <paul at giannaros.org>
+// SPDX-FileCopyrightText: 2012, 2013 Shaheed Haque <srhaque at theiet.org>
+// SPDX-FileCopyrightText: 2013 Alex Turbov <i.zaufi at gmail.com>
+// SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@@ -25,8 +26,6 @@
#include "kis_debug.h"
-#define PYKRITA_INIT PyInit_pykrita
-
struct module_state {
PyObject *error;
};
@@ -84,7 +83,7 @@ static struct PyModuleDef moduledef = {
#define INITERROR return NULL
-PyMODINIT_FUNC PyInit_pykrita()
+PyMODINIT_FUNC PYKRITA_INIT()
#else
#define INITERROR return
diff --git a/plugins/extensions/pykrita/plugin/PykritaModule.h b/plugins/extensions/pykrita/plugin/PykritaModule.h
index 28a674eed1..c83844b3c3 100644
--- a/plugins/extensions/pykrita/plugin/PykritaModule.h
+++ b/plugins/extensions/pykrita/plugin/PykritaModule.h
@@ -1,8 +1,9 @@
/*
* This file is part of PyKrita, Krita' Python scripting plugin.
*
- * Copyright (C) 2013 Alex Turbov <i.zaufi at gmail.com>
- * Copyright (C) 2014-2016 Boudewijn Rempt <boud at valdyas.org>
+ * SPDX-FileCopyrightText: 2013 Alex Turbov <i.zaufi at gmail.com>
+ * SPDX-FileCopyrightText: 2014-2016 Boudewijn Rempt <boud at valdyas.org>
+ * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -24,6 +25,7 @@
#define __PYKRITA_MODULE_H__
#include <Python.h>
+#include "config.h"
#if PY_MAJOR_VERSION >= 3
#ifndef IS_PY3K
@@ -31,11 +33,17 @@
#endif
#endif
+#if SIP_VERSION >= 0x0500000
+#define PYKRITA_INIT PyInit_krita
+#else
+#define PYKRITA_INIT PyInit_pykrita
+#endif
+
/**
* Initializer for the built-in Python module.
*/
#if defined(IS_PY3K)
-PyMODINIT_FUNC PyInit_pykrita();
+PyMODINIT_FUNC PYKRITA_INIT();
#else
void initpykrita();
#endif
diff --git a/plugins/extensions/pykrita/plugin/config.h.cmake b/plugins/extensions/pykrita/plugin/config.h.cmake
index 17cc83c7d8..6b991d3546 100644
--- a/plugins/extensions/pykrita/plugin/config.h.cmake
+++ b/plugins/extensions/pykrita/plugin/config.h.cmake
@@ -1,6 +1,7 @@
// This file is part of PyKrita, Krita' Python scripting plugin.
//
-// Copyright (C) 2006 Paul Giannaros <paul at giannaros.org>
+// SPDX-FileCopyrightText: 2006 Paul Giannaros <paul at giannaros.org>
+// SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@@ -19,5 +20,7 @@
#define PYKRITA_PYTHON_LIBRARY "${PYTHON_LIBRARY}"
+#define SIP_VERSION 0x at SIP_VERSION@
+
/// Name of the file where per-plugin configuration is stored
#define CONFIG_FILE "kritapykritarc"
diff --git a/plugins/extensions/pykrita/plugin/utilities.cpp b/plugins/extensions/pykrita/plugin/utilities.cpp
index feecfdd6e5..2a2cd1b14d 100644
--- a/plugins/extensions/pykrita/plugin/utilities.cpp
+++ b/plugins/extensions/pykrita/plugin/utilities.cpp
@@ -1,7 +1,8 @@
// This file is part of PyKrita, Krita' Python scripting plugin.
//
-// Copyright (C) 2006 Paul Giannaros <paul at giannaros.org>
-// Copyright (C) 2012, 2013 Shaheed Haque <srhaque at theiet.org>
+// SPDX-FileCopyrightText: 2006 Paul Giannaros <paul at giannaros.org>
+// SPDX-FileCopyrightText: 2012, 2013 Shaheed Haque <srhaque at theiet.org>
+// SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@@ -77,7 +78,7 @@ namespace PyKrita
}
#if defined(IS_PY3K)
- if (0 != PyImport_AppendInittab(Python::PYKRITA_ENGINE, PyInit_pykrita)) {
+ if (0 != PyImport_AppendInittab(Python::PYKRITA_ENGINE, PYKRITA_INIT)) {
#else
if (0 != PyImport_AppendInittab(Python::PYKRITA_ENGINE, initpykrita)) {
#endif
@@ -96,7 +97,7 @@ namespace PyKrita
#if defined(IS_PY3K)
// Initialize our built-in module.
- auto pykritaModule = PyInit_pykrita();
+ auto pykritaModule = PYKRITA_INIT();
if (!pykritaModule) {
initStatus = INIT_CANNOT_LOAD_PYKRITA_MODULE;
diff --git a/plugins/extensions/pykrita/sip/CMakeLists.txt b/plugins/extensions/pykrita/sip/CMakeLists.txt
index 23a13426f0..07611d5a09 100644
--- a/plugins/extensions/pykrita/sip/CMakeLists.txt
+++ b/plugins/extensions/pykrita/sip/CMakeLists.txt
@@ -3,33 +3,41 @@ include(SIPMacros)
message( ${SIP_VERSION} " - The version of SIP found expressed as a 6 digit hex number suitable for comparison as a string.")
message( ${SIP_VERSION_STR} " - The version of SIP found as a human readable string.")
message( ${SIP_EXECUTABLE} " - Path and filename of the SIP command line executable.")
-IF(${SIP_VERSION_STR} VERSION_LESS 5)
+if(${SIP_VERSION_STR} VERSION_LESS 5)
+ message( ${SIP_DEFAULT_SIP_DIR} " - default SIP dir" )
message( ${SIP_INCLUDE_DIR} " - Directory holding the SIP C++ header file.")
-ENDIF(${SIP_VERSION_STR} VERSION_LESS 5)
-message( ${SIP_DEFAULT_SIP_DIR} " - default SIP dir" )
-set(SIP_INCLUDES
- ${SIP_DEFAULT_SIP_DIR}
- ${PYQT5_SIP_DIR}
- ${PYQT_SIP_DIR_OVERRIDE}
- ./krita)
+ set(SIP_INCLUDES
+ ${SIP_DEFAULT_SIP_DIR}
+ ${PYQT5_SIP_DIR}
+ ${PYQT_SIP_DIR_OVERRIDE}
+ ./krita)
-set(SIP_CONCAT_PARTS 1)
-set(SIP_TAGS ALL WS_X11 ${PYQT5_VERSION_TAG})
-set(SIP_EXTRA_OPTIONS -g -o -x PyKDE_QVector)
-IF (PYQT5_SIP_NAME)
- set(SIP_EXTRA_OPTIONS ${SIP_EXTRA_OPTIONS} -n ${PYQT5_SIP_NAME})
-ENDIF (PYQT5_SIP_NAME)
+ set(SIP_CONCAT_PARTS 1)
+ set(SIP_TAGS ALL WS_X11 ${PYQT5_VERSION_TAG})
+ set(SIP_EXTRA_OPTIONS -g -o -x PyKDE_QVector)
+ IF (PYQT5_SIP_NAME)
+ set(SIP_EXTRA_OPTIONS ${SIP_EXTRA_OPTIONS} -n ${PYQT5_SIP_NAME})
+ ENDIF (PYQT5_SIP_NAME)
-set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${LIB_INSTALL_DIR}/krita-python-libs)
-file(GLOB PYKRITA_KRITA_sip_files ./krita/*.sip)
-set(SIP_EXTRA_FILES_DEPEND ${PYKRITA_KRITA_sip_files})
-add_sip_python_module(PyKrita.krita ./krita/kritamod.sip kritalibkis kritaui kritaimage kritalibbrush)
+ set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${LIB_INSTALL_DIR}/krita-python-libs)
+ file(GLOB PYKRITA_KRITA_sip_files ./krita/*.sip)
+ set(SIP_EXTRA_FILES_DEPEND ${PYKRITA_KRITA_sip_files})
+ add_sip_python_module(PyKrita.krita ./krita/kritamod.sip kritalibkis kritaui kritaimage kritalibbrush)
-if (ENABLE_PYTHON_2)
- # Add an init file to turn it into a valid py2 module.
- # Otherwise PyKrita cannot be loaded.
- install(FILES
- ./__init__.py
- DESTINATION ${PYTHON_SITE_PACKAGES_INSTALL_DIR}/PyKrita)
-endif (ENABLE_PYTHON_2)
+ if (ENABLE_PYTHON_2)
+ # Add an init file to turn it into a valid py2 module.
+ # Otherwise PyKrita cannot be loaded.
+ install(FILES
+ ./__init__.py
+ DESTINATION ${PYTHON_SITE_PACKAGES_INSTALL_DIR}/PyKrita)
+ endif (ENABLE_PYTHON_2)
+else()
+ set(SIP_CONCAT_PARTS 1)
+ set(SIP_MODULE ${PYQT5_SIP_NAME})
+ set(SIP_TAGS ${PYQT5_SIP_TAGS})
+ set(SIP_INCLUDES ${PYQT5_SIP_DIR})
+ set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${LIB_INSTALL_DIR}/krita-python-libs)
+ set(SIP_EXTRA_FILES_DEPEND "${CMAKE_CURRENT_SOURCE_DIR}/krita")
+ add_sip_python_module_v5(PyKrita.krita ./krita/kritamod.sip kritalibkis kritaui kritaimage kritalibbrush)
+endif()
More information about the kimageshop
mailing list