Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# CMakeLists.txt for cmpi-bindings
#
cmake_minimum_required(VERSION 2.4)
cmake_minimum_required(VERSION 3.1)

PROJECT(cmpi-bindings)

Expand Down Expand Up @@ -143,8 +143,6 @@ ADD_CUSTOM_TARGET( svncheck
SET( AUTOBUILD_COMMAND
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/package/*.tar.bz2
COMMAND ${CMAKE_MAKE_PROGRAM} package_source
COMMAND ${CMAKE_COMMAND} -E copy ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.bz2 ${CMAKE_BINARY_DIR}/package
COMMAND ${CMAKE_COMMAND} -E remove ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.bz2
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/package/${PACKAGE}.changes" "${CMAKE_BINARY_DIR}/package/${PACKAGE}.changes"
)

Expand Down
2 changes: 1 addition & 1 deletion VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SET(VERSION_MAJOR "1")
SET(VERSION_MINOR "0")
SET(VERSION_PATCH "5")
SET(VERSION_PATCH "6")
7 changes: 7 additions & 0 deletions package/cmpi-bindings.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu May 8 15:19:04 UTC 2025 - Klaus Kämpf <kkaempf@suse.de>

- Update to 1.0.6
- Adapt to Python 3.13
- Fix srcpackage build

-------------------------------------------------------------------
Mon Dec 9 16:40:05 UTC 2024 - Klaus Kämpf <kkaempf@suse.de>

Expand Down
12 changes: 7 additions & 5 deletions package/cmpi-bindings.spec.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# spec file for package cmpi-bindings
#
# Copyright (c) 2023 SUSE LLC
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
Expand Down Expand Up @@ -197,18 +197,20 @@ Summary: Adapter to write and run CMPI-type CIM providers in Python 2
Group: Development/Languages/Python
# for the debug package. we dont use debug_package_requires here as it would enforce to install both packages.
Provides: %{name} = %{version}-%{release}
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
%if %{python3}
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "import site; print(site.getsitepackages()[1])")}
%{!?python_sitearch: %global python_sitearch %(%{__python} -c "import site; print(site.getsitepackages()[0])")}
%{!?py3_requires: %define py3_requires Requires: python3}
%{py3_requires}
%else
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
%{!?py_requires: %define py_requires Requires: python}
%{py_requires}
%endif

%description -n %{pywbemname}
-
Adapter to write and run CMPI-type CIM providers in Python

%files -n %{pywbemname}
%defattr(-,root,root,-)
Expand All @@ -233,7 +235,7 @@ Group: Development/Languages/Perl
Provides: %{name} = %{version}-%{release}

%description -n cmpi-bindings-perl
-
Adapter to write and run CMPI-type CIM providers in Perl

%files -n cmpi-bindings-perl
%defattr(-,root,root,-)
Expand Down
34 changes: 26 additions & 8 deletions src/target_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@

#include <Python.h>


#if PY_MAJOR_VERSION > 2 && PY_MINOR_VERSION < 13
static PyThreadState* cmpiMainPyThreadState = NULL;
#endif

/*
* get Python exception trace -> CMPIString
Expand Down Expand Up @@ -173,20 +174,35 @@ PyGlobalInitialize(const CMPIBroker* broker, CMPIStatus* st)
PyStatus status;
PyConfig config;
PyConfig_InitIsolatedConfig(&config);
status = PyConfig_SetBytesString(&config, &config.program_name, "cmpi_pywbem_bindings");
if (PyStatus_Exception(status)) {
_SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() failed in PyConfig_SetBytesString", getpid(), pthread_self()));
goto exception;
}
config.isolated = 1;
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status))
return -1;
if (PyStatus_Exception(status)) {
_SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() failed in Py_InitializeFromConfig", getpid(), pthread_self()));
goto exception;
}
PyConfig_Clear(&config);
#endif
#if PY_MAJOR_VERSION < 3
SWIGEXPORT void SWIG_init(void);
SWIG_init();
#endif
#elsif PY_MINOR_VERSION < 13
cmpiMainPyThreadState = PyGILState_GetThisThreadState();
PyEval_ReleaseThread(cmpiMainPyThreadState);

#else /* 3.13 or later */
#endif
_SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() succeeded", getpid(), pthread_self()));
return 0;
return 0;
#if PY_MAJOR_VERSION > 2 && PY_MINOR_VERSION > 12
exception:
PyConfig_Clear(&config);
Py_ExitStatusException(status);
return -1;
#endif
}


Expand Down Expand Up @@ -441,9 +457,11 @@ TargetCleanup(ProviderMIHandle * hdl)
TARGET_THREAD_BEGIN_BLOCK;
Py_DecRef(_TARGET_MODULE);
TARGET_THREAD_END_BLOCK;

#if PY_MAJOR_VERSION < 3 || PY_MINOR_VERSION < 13
PyEval_AcquireLock();
PyThreadState_Swap(cmpiMainPyThreadState);
PyThreadState_Swap(cmpiMainPyThreadState);
#else
#endif
if (_TARGET_INIT) // if Python is initialized and _MI_COUNT == 0, call Py_Finalize
{
_SBLIM_TRACE(1,("Calling Py_Finalize()"));
Expand Down
41 changes: 4 additions & 37 deletions swig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,11 @@
enable_testing()

IF (BUILD_PYTHON3)
IF (BUILD_PYTHON2)
MESSAGE(FATAL_ERROR " Can't build Python2 and Python3, use -DBUILD_PYTHON2=YES **or** -DBUILD_PYTHON3=YES")
ENDIF (BUILD_PYTHON2)
find_package (Python3 COMPONENTS Interpreter Development)
IF (NOT Python3_FOUND)
MESSAGE(ERROR "Can't find Python3")
ELSE (NOT Python3_FOUND)
MESSAGE(STATUS "Building with Python3")
SET(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
SET(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS})
SET(PYTHON_LIBRARIES ${Python3_LIBRARIES})
SET(PYTHON_LDFLAGS ${Python3_LDFLAGS})
SET(PYTHON_LIB_DIR ${Python3_LIBRARY_DIRS})
SET(PYTHON_SITE_DIR ${Python3_SITE_DIR})
# SET(PYTHON_MAJOR_VERSION ${Python3_VERSION_MAJOR})
# SET(PYTHON_MINOR_VERSION ${Python3_VERSION_MINOR})
ADD_SUBDIRECTORY(python)
ENDIF (NOT Python3_FOUND)
MESSAGE(STATUS "Building Python 3 ...")
ADD_SUBDIRECTORY(python)
ELSEIF (BUILD_PYTHON2)
IF (BUILD_PYTHON3)
MESSAGE(FATAL_ERROR "Can't build Python2 and Python3 at the same time, use -DBUILD_PYTHON2=YES **or** -DBUILD_PYTHON3=YES")
ENDIF (BUILD_PYTHON3)

find_package (Python2 COMPONENTS Interpreter Development)
IF (NOT Python2_FOUND)
MESSAGE(ERROR "Can't find Python2")
ELSE (NOT Python2_FOUND)
MESSAGE(STATUS "Building with Python2")
SET(PYTHON_EXECUTABLE ${Python2_EXECUTABLE})
SET(PYTHON_INCLUDE_PATH ${Python2_INCLUDE_DIRS})
SET(PYTHON_LIBRARIES ${Python2_LIBRARIES})
SET(PYTHON_LDFLAGS ${Python2_LDFLAGS})
SET(PYTHON_LIB_DIR ${Python2_LIBRARY_DIRS})
SET(PYTHON_SITE_DIR ${Python2_SITE_DIR})
SET(PYTHON_MAJOR_VERSION ${Python2_VERSION_MAJOR})
SET(PYTHON_MINOR_VERSION ${Python2_VERSION_MINOR})
ADD_SUBDIRECTORY(python)
ENDIF (NOT Python2_FOUND)
MESSAGE(STATUS "Building Python 2 ...")
ADD_SUBDIRECTORY(python)
ELSE (BUILD_PYTHON2)
MESSAGE(STATUS "*****")
MESSAGE(STATUS "\tSkipping Python build")
Expand Down
10 changes: 5 additions & 5 deletions swig/cmpi.i
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ SWIGINTERNINLINE SV *SWIG_From_double SWIG_PERL_DECL_ARGS_1(double value);
static Target_Type
Target_DateTime(CMPIDateTime *datetime)
{
Target_Type result;
Target_Type result = Target_Null;
#if defined (SWIGRUBY)
CMPIStatus st;
if (datetime) {
Expand Down Expand Up @@ -172,7 +172,7 @@ fail:
static Target_Type
value_value(const CMPIValue *value, const CMPIType type)
{
Target_Type result;
Target_Type result = Target_Null;
switch (type)
{
case CMPI_null:
Expand Down Expand Up @@ -296,7 +296,7 @@ data_clone(const CMPIData *dp)
static Target_Type
data_value(const CMPIData *dp)
{
Target_Type result;
Target_Type result = Target_Null;

if ((dp->state & CMPI_notFound) /* should CMPI_notFound raise or return NULL ? */
|| (dp->state & CMPI_nullValue)
Expand Down Expand Up @@ -353,7 +353,7 @@ target_charptr(Target_Type target)
#elif defined (SWIGPYTHON)
str = PyString_AsString(target);
#else
#warning target_charptr not defined
#warning target_charptr not defined (expected for Perl)
str = NULL;
fail:
#endif
Expand All @@ -369,7 +369,7 @@ fail:
static Target_Type
data_data(const CMPIData *dp)
{
Target_Type result;
Target_Type result = Target_Null;

if (dp->state & CMPI_notFound) {
SWIG_exception(SWIG_IndexError, "value not found");
Expand Down
83 changes: 66 additions & 17 deletions swig/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,72 @@
#
# CMakeLists.txt for cmpi-bindings/swig/ruby
# CMakeLists.txt for cmpi-bindings/swig/python
#

enable_testing()
add_subdirectory(tests)

SET (BUILD_SHARED_LIBS ON)

EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib())" OUTPUT_VARIABLE PYTHON_LIB_DIR)

IF (NOT PYTHON_SITE_DIR)
SET (PYTHON_SITE_DIR ${PYTHON_LIB_DIR})
ENDIF (NOT PYTHON_SITE_DIR)

MESSAGE(STATUS "Python executable: ${PYTHON_EXECUTABLE}")
MESSAGE(STATUS "Python inc dir: ${PYTHON_INCLUDE_PATH}")
MESSAGE(STATUS "Python lib dir: ${PYTHON_LIB_DIR}")
MESSAGE(STATUS "Python libraries: ${PYTHON_LIBRARIES}")
MESSAGE(STATUS "Python ldflags: ${PYTHON_LDFLAGS}")
MESSAGE(STATUS "Python site dir: ${PYTHON_SITE_DIR}")
IF (BUILD_PYTHON2)
IF (BUILD_PYTHON3)
MESSAGE(FATAL_ERROR "Can't build Python2 and Python3 at the same time, use -DBUILD_PYTHON2=YES **or** -DBUILD_PYTHON3=YES")
ENDIF (BUILD_PYTHON3)

FIND_PACKAGE (Python2 COMPONENTS Interpreter Development REQUIRED)
IF (NOT Python2_FOUND)
MESSAGE(ERROR "Can't find Python2")
ENDIF (NOT Python2_FOUND)

SET(PYTHON_EXECUTABLE ${Python2_EXECUTABLE})
SET(PYTHON_LIB_DIR ${Python2_LIBRARY_DIRS})
SET(PYTHON_INCLUDE_DIRS ${Python2_INCLUDE_DIRS})
SET(PYTHON_INCLUDE_PATH ${Python2_INCLUDE_PATH})
SET(PYTHON_STDLIB ${Python2_STDLIB})
SET(PYTHON_STDARCH ${Python2_STDARCH})
SET(PYTHON_SITELIB ${Python2_SITELIB})
SET(PYTHON_SITEARCH ${Python2_SITEARCH})

ELSEIF (BUILD_PYTHON3)

IF (BUILD_PYTHON2)
MESSAGE(FATAL_ERROR "Can't build Python2 and Python3 at the same time, use -DBUILD_PYTHON2=YES **or** -DBUILD_PYTHON3=YES")
ENDIF (BUILD_PYTHON2)

FIND_PACKAGE (Python3 COMPONENTS Interpreter Development REQUIRED)
IF (NOT Python3_FOUND)
MESSAGE(ERROR "Can't find Python3")
ENDIF (NOT Python3_FOUND)

SET(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
SET(PYTHON_LIB_DIR ${Python3_LIBRARY_DIRS})
SET(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
SET(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_PATH})
SET(PYTHON_STDLIB ${Python3_STDLIB})
SET(PYTHON_STDARCH ${Python3_STDARCH})
SET(PYTHON_SITELIB ${Python3_SITELIB})
SET(PYTHON_SITEARCH ${Python3_SITEARCH})
ELSE (BUILD_PYTHON3)
MESSAGE(ERROR "No Python found")
ENDIF (BUILD_PYTHON2)

# CMake 3.30 and Python 3.11 do not set _STDLIB, _STDARCH, _SITELIB, or _SITEARCH

# CMake + Python not always define proper STD or SITE directories :-/
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c "if True:
import sysconfig as sc
print(sc.get_path(name='stdlib'))"
OUTPUT_VARIABLE PYTHON_SITE
OUTPUT_STRIP_TRAILING_WHITESPACE)

MESSAGE(STATUS "Python executable: ${PYTHON_EXECUTABLE}")
MESSAGE(STATUS "Python inc dir: ${PYTHON_INCLUDE_PATH}")
MESSAGE(STATUS "Python lib dir: ${PYTHON_LIB_DIR}")
MESSAGE(STATUS "Python libraries: ${PYTHON_LIBRARIES}")
MESSAGE(STATUS "Python ldflags: ${PYTHON_LDFLAGS}")
MESSAGE(STATUS "Python site dir: ${PYTHON_SITE}")
MESSAGE(STATUS "Python site lib dir: ${PYTHON_SITELIB}")
MESSAGE(STATUS "Python site arch dir: ${PYTHON_SITEARCH}")

SET( SWIG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cmpi_wrap.c" )
SET( SWIG_INPUT "${CMAKE_CURRENT_SOURCE_DIR}/../cmpi.i" )
Expand All @@ -37,6 +85,7 @@ SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -g" )

INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/.. )
INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_PATH} )
INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_DIRS} )
INCLUDE_DIRECTORIES( ${CMPI_INCLUDE_DIR} )

ADD_DEFINITIONS(-DCMPI_PLATFORM_LINUX_GENERIC_GNU -DCMPI_VERSION=200)
Expand All @@ -58,15 +107,15 @@ TARGET_LINK_LIBRARIES( ${NAME} util )

INSTALL(TARGETS ${NAME} LIBRARY DESTINATION ${CMPI_LIBRARY_DIR})
# .py: swig generated
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmpi.py DESTINATION ${PYTHON_SITE_DIR} )
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmpi.py DESTINATION ${PYTHON_SITELIB} )


#
# cmpi_pywbem_bindings.py: provider implementation
#
INSTALL(FILES cmpi_pywbem_bindings.py DESTINATION ${PYTHON_SITE_DIR} )
INSTALL(FILES cmpi_pywbem_bindings.py DESTINATION ${PYTHON_SITELIB} )
#INSTALL(FILES Py_UnixProcessProvider.py DESTINATION /usr/lib/pycim )

INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"from py_compile import compile; compile('\$ENV{DESTDIR}${PYTHON_SITE_DIR}/cmpi.py', dfile='${PYTHON_SITE_DIR}/cmpi.py')\")")
INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"from py_compile import compile; compile('\$ENV{DESTDIR}${PYTHON_SITELIB}/cmpi.py', dfile='${PYTHON_SITELIB}/cmpi.py')\")")

INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"from py_compile import compile; compile('\$ENV{DESTDIR}${PYTHON_SITE_DIR}/cmpi_pywbem_bindings.py', dfile='${PYTHON_SITE_DIR}/cmpi_pywbem_bindings.py')\")")
INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"from py_compile import compile; compile('\$ENV{DESTDIR}${PYTHON_SITELIB}/cmpi_pywbem_bindings.py', dfile='${PYTHON_SITELIB}/cmpi_pywbem_bindings.py')\")")