Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
6ce0133b
Commit
6ce0133b
authored
Oct 24, 2022
by
Christoph Cullmann
🍨
Browse files
compiles pythonutils but doesn't link yet
parent
952c2a55
Changes
9
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
6ce0133b
...
...
@@ -62,11 +62,6 @@ ecm_optional_add_subdirectory(apps)
# our documentation
ecm_optional_add_subdirectory
(
doc
)
# python bindings
if
(
BUILD_PYTHON_BINDINDS
)
ecm_optional_add_subdirectory
(
python
)
endif
()
ki18n_install
(
po
)
if
(
KF5DocTools_FOUND
)
kdoctools_install
(
po
)
...
...
addons/python/CMakeLists.txt
View file @
6ce0133b
#
# Kate Python bindings
#
remove_definitions
(
-DQT_STRICT_ITERATORS
)
set
(
PYTHON_BINDING_NAMESPACE
"PyKate"
)
# Just to fix warnings with --warn-uninitialized
if
(
NOT DEFINED SHIBOKEN_CUSTOM_PREFIX
)
#look for shiboken in a custom location
set
(
SHIBOKEN_CUSTOM_PREFIX
""
)
endif
()
if
(
NOT DEFINED PYSIDE_CUSTOM_PREFIX
)
#look for pyside in a custom location
set
(
PYSIDE_CUSTOM_PREFIX
""
)
endif
()
if
(
${
PROJECT_NAME
}
_QT6
)
set
(
PYSIDE_MAJOR_VERSION
"6"
)
set
(
PYTHON_BINDING_NAMESPACE
"
${
PYTHON_BINDING_NAMESPACE
}
Qt
${
PYSIDE_MAJOR_VERSION
}
"
)
set
(
QtWidgets_VERSION
${
Qt6Widgets_VERSION
}
)
else
()
set
(
PYSIDE_MAJOR_VERSION
"2"
)
set
(
QtWidgets_VERSION
${
Qt5Widgets_VERSION
}
)
endif
()
find_package
(
Python3 3.7 REQUIRED COMPONENTS Interpreter Development
)
find_package
(
Shiboken
${
PYSIDE_MAJOR_VERSION
}
REQUIRED
)
find_package
(
PySide
${
PYSIDE_MAJOR_VERSION
}
REQUIRED
)
if
(
NOT PYTHON_BINDINGS_INSTALL_PREFIX
)
set
(
PYTHON_BINDINGS_INSTALL_PREFIX
"
${
CMAKE_INSTALL_PREFIX
}
"
)
endif
()
set
(
Python3_VERSION_MAJORMINOR
"
${
Python3_VERSION_MAJOR
}
.
${
Python3_VERSION_MINOR
}
"
)
set
(
BINDINGS_DIR
"
${
INSTALL_LIBRARY_DIR
}
/python
${
Python3_VERSION_MAJORMINOR
}
/site-packages/
${
PYTHON_BINDING_NAMESPACE
}
"
)
set
(
PYTHON_BINDINGS_INSTALL_PREFIX
"
${
PYTHON_BINDINGS_INSTALL_PREFIX
}
/
${
BINDINGS_DIR
}
"
)
include
(
PySide
${
PYSIDE_MAJOR_VERSION
}
ModuleBuild
)
add_subdirectory
(
PyKate
)
#
# Kate Python plugin
#
kate_add_plugin
(
katepythonplugin
)
target_compile_definitions
(
katepythonplugin PRIVATE TRANSLATION_DOMAIN=
"katepythonplugin"
)
...
...
@@ -6,11 +48,14 @@ target_link_libraries(
PRIVATE
KF5::I18n
KF5::TextEditor
Shiboken2::libshiboken
${
Python3_LIBRARIES
}
)
target_sources
(
katepythonplugin
PRIVATE
katepythonplugin.cpp
pythonutils.cpp
plugin.qrc
)
python/PyKate/CMakeLists.txt
→
addons/
python/PyKate/CMakeLists.txt
View file @
6ce0133b
...
...
@@ -71,6 +71,6 @@ create_python_bindings(
configure_file
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/__init__.py.cmake
${
CMAKE_CURRENT_BINARY_DIR
}
/__init__.py @ONLY
)
# install
install
(
FILES
${
CMAKE_CURRENT_BINARY_DIR
}
/__init__.py $<TARGET_FILE:Kate>
install
(
FILES
${
CMAKE_CURRENT_BINARY_DIR
}
/__init__.py $<TARGET_FILE:
Py
Kate>
DESTINATION
${
PYTHON_BINDINGS_INSTALL_PREFIX
}
)
python/PyKate/__init__.py.cmake
→
addons/
python/PyKate/__init__.py.cmake
View file @
6ce0133b
File moved
python/PyKate/kate_python.h
→
addons/
python/PyKate/kate_python.h
View file @
6ce0133b
File moved
python/PyKate/typesystem_kate.xml
→
addons/
python/PyKate/typesystem_kate.xml
View file @
6ce0133b
File moved
addons/python/pythonutils.cpp
0 → 100644
View file @
6ce0133b
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include
"pythonutils.h"
#include
<QtCore/QByteArray>
#include
<QtCore/QCoreApplication>
#include
<QtCore/QDebug>
#include
<QtCore/QDir>
#include
<QtCore/QOperatingSystemVersion>
#include
<QtCore/QStringList>
#include
<QtCore/QTemporaryFile>
#include
<sbkconverter.h>
#include
<sbkmodule.h>
#include
<sbkpython.h>
/* from AppLib bindings */
extern
"C"
PyObject
*
PyInit_AppLib
();
static
const
char
moduleName
[]
=
"AppLib"
;
// This variable stores all Python types exported by this module.
extern
PyTypeObject
**
SbkAppLibTypes
;
// This variable stores all type converters exported by this module.
extern
SbkConverter
**
SbkAppLibTypeConverters
;
namespace
PythonUtils
{
static
State
state
=
PythonUninitialized
;
static
void
cleanup
()
{
if
(
state
>
PythonUninitialized
)
{
Py_Finalize
();
state
=
PythonUninitialized
;
}
}
static
const
char
virtualEnvVar
[]
=
"VIRTUAL_ENV"
;
// If there is an active python virtual environment, use that environment's
// packages location.
static
void
initVirtualEnvironment
()
{
// As of Python 3.8, Python is no longer able to run stand-alone in a
// virtualenv due to missing libraries. Add the path to the modules instead.
if
(
QOperatingSystemVersion
::
currentType
()
==
QOperatingSystemVersion
::
Windows
&&
(
PY_MAJOR_VERSION
>
3
||
(
PY_MAJOR_VERSION
==
3
&&
PY_MINOR_VERSION
>=
8
)))
{
const
QByteArray
virtualEnvPath
=
qgetenv
(
virtualEnvVar
);
qputenv
(
"PYTHONPATH"
,
virtualEnvPath
+
"
\\
Lib
\\
site-packages"
);
}
}
State
init
()
{
if
(
state
>
PythonUninitialized
)
return
state
;
if
(
qEnvironmentVariableIsSet
(
virtualEnvVar
))
initVirtualEnvironment
();
if
(
PyImport_AppendInittab
(
moduleName
,
PyInit_AppLib
)
==
-
1
)
{
qWarning
(
"Failed to add the module '%s' to the table of built-in modules."
,
moduleName
);
return
state
;
}
Py_Initialize
();
qAddPostRoutine
(
cleanup
);
state
=
PythonInitialized
;
const
bool
pythonInitialized
=
PyInit_AppLib
()
!=
nullptr
;
const
bool
pyErrorOccurred
=
PyErr_Occurred
()
!=
nullptr
;
if
(
pythonInitialized
&&
!
pyErrorOccurred
)
{
state
=
AppModuleLoaded
;
}
else
{
if
(
pyErrorOccurred
)
PyErr_Print
();
qWarning
(
"Failed to initialize the module."
);
}
return
state
;
}
bool
runScript
(
const
QStringList
&
script
)
{
if
(
init
()
==
PythonUninitialized
)
return
false
;
// Concatenating all the lines
QString
content
;
QTextStream
ss
(
&
content
);
for
(
const
QString
&
line
:
script
)
ss
<<
line
<<
"
\n
"
;
// Executing the whole script as one line
bool
result
=
true
;
const
QByteArray
line
=
content
.
toUtf8
();
if
(
PyRun_SimpleString
(
line
.
constData
())
==
-
1
)
{
if
(
PyErr_Occurred
())
PyErr_Print
();
result
=
false
;
}
return
result
;
}
}
// namespace PythonUtils
addons/python/pythonutils.h
0 → 100644
View file @
6ce0133b
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef PYTHONUTILS_H
#define PYTHONUTILS_H
#include
<QtCore/QStringList>
class
QObject
;
namespace
PythonUtils
{
enum
AppLibTypes
{
MainWindowType
=
0
// SBK_MAINWINDOW_IDX
};
enum
State
{
PythonUninitialized
,
PythonInitialized
,
AppModuleLoaded
};
State
init
();
bool
runScript
(
const
QStringList
&
script
);
}
// namespace PythonUtils
#endif // PYTHONUTILS_H
python/CMakeLists.txt
deleted
100644 → 0
View file @
952c2a55
remove_definitions
(
-DQT_STRICT_ITERATORS
)
set
(
PYTHON_BINDING_NAMESPACE
"PyKate"
)
# Just to fix warnings with --warn-uninitialized
if
(
NOT DEFINED SHIBOKEN_CUSTOM_PREFIX
)
#look for shiboken in a custom location
set
(
SHIBOKEN_CUSTOM_PREFIX
""
)
endif
()
if
(
NOT DEFINED PYSIDE_CUSTOM_PREFIX
)
#look for pyside in a custom location
set
(
PYSIDE_CUSTOM_PREFIX
""
)
endif
()
if
(
${
PROJECT_NAME
}
_QT6
)
set
(
PYSIDE_MAJOR_VERSION
"6"
)
set
(
PYTHON_BINDING_NAMESPACE
"
${
PYTHON_BINDING_NAMESPACE
}
Qt
${
PYSIDE_MAJOR_VERSION
}
"
)
set
(
QtWidgets_VERSION
${
Qt6Widgets_VERSION
}
)
else
()
set
(
PYSIDE_MAJOR_VERSION
"2"
)
set
(
QtWidgets_VERSION
${
Qt5Widgets_VERSION
}
)
endif
()
find_package
(
Python3 3.7 REQUIRED COMPONENTS Interpreter Development
)
find_package
(
Shiboken
${
PYSIDE_MAJOR_VERSION
}
REQUIRED
)
find_package
(
PySide
${
PYSIDE_MAJOR_VERSION
}
${
QtWidgets_VERSION
}
EXACT REQUIRED
)
if
(
NOT PYTHON_BINDINGS_INSTALL_PREFIX
)
set
(
PYTHON_BINDINGS_INSTALL_PREFIX
"
${
CMAKE_INSTALL_PREFIX
}
"
)
endif
()
set
(
Python3_VERSION_MAJORMINOR
"
${
Python3_VERSION_MAJOR
}
.
${
Python3_VERSION_MINOR
}
"
)
set
(
BINDINGS_DIR
"
${
INSTALL_LIBRARY_DIR
}
/python
${
Python3_VERSION_MAJORMINOR
}
/site-packages/
${
PYTHON_BINDING_NAMESPACE
}
"
)
set
(
PYTHON_BINDINGS_INSTALL_PREFIX
"
${
PYTHON_BINDINGS_INSTALL_PREFIX
}
/
${
BINDINGS_DIR
}
"
)
include
(
PySide
${
PYSIDE_MAJOR_VERSION
}
ModuleBuild
)
add_subdirectory
(
PyKate
)
# if(${PROJECT_NAME}_TESTS)
# add_subdirectory(tests)
# endif()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment