Python wrapper: update CMakeLists, and rename the module to 'pyiec61850'

* update the CMakeLists
  - remove the deprecated commands ('PythonInterp', ...)
   (https://cmake.org/cmake/help/latest/module/FindPythonInterp.html)

  - change the CMake minimum version from 3.8 to 3.12 (released in July 2018)

* rename the libiec61850 Python module into 'pyiec61850'
  - to avoid name conflict with the name for the C static lib
  - the build artifacts are now 'pyiec61850.py' and '_pyiec61850.so'

Signed-off-by: Mikael Bourhis <mikael.bourhis@smile.fr>
pull/477/head
Mikael Bourhis 2 years ago
parent e57dcc7214
commit 178312aa13

@ -1,14 +1,13 @@
# The SWIG functions/macros used in this module, swig_add_module and swig_add_library cmake_minimum_required(VERSION 3.12)
# are not available in CMake versions earlier than 3.8
# cmake_minimum_required(VERSION 3.8) set(CMAKE_POLICY_DEFAULT_CMP0078 NEW)
find_package(SWIG REQUIRED) find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE}) include(${SWIG_USE_FILE})
find_package(PythonInterp ${BUILD_PYTHON_VERSION} REQUIRED) find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED)
include_directories(${PYTHON_INCLUDE_PATH}) include_directories(${Python_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_SWIG_FLAGS "") set(CMAKE_SWIG_FLAGS "")
@ -20,25 +19,21 @@ else()
set(LIBS iec61850-shared) set(LIBS iec61850-shared)
endif() endif()
if(${CMAKE_VERSION} VERSION_LESS 3.8) swig_add_library(pyiec61850
swig_add_module(iec61850 python iec61850.i) LANGUAGE python
else() SOURCES iec61850.i
swig_add_library(iec61850 )
LANGUAGE python
SOURCES iec61850.i
)
endif()
swig_link_libraries(iec61850 ${PYTHON_LIBRARIES} ${LIBS}) swig_link_libraries(pyiec61850 ${LIBS})
# Finding python modules install path # Finding python modules install path
execute_process( execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c COMMAND ${Python_EXECUTABLE} -c
"from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib())" "from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib())"
OUTPUT_VARIABLE PYTHON_SITE_DIR OUTPUT_VARIABLE PYTHON_SITE_DIR
) )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iec61850.py DESTINATION ${PYTHON_SITE_DIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pyiec61850.py DESTINATION ${PYTHON_SITE_DIR})
install(TARGETS _iec61850 LIBRARY DESTINATION ${PYTHON_SITE_DIR}) install(TARGETS pyiec61850 LIBRARY DESTINATION ${PYTHON_SITE_DIR})
add_test(test_pyiec61850 ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/test_pyiec61850.py) add_test(test_pyiec61850 ${Python_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/test_pyiec61850.py)

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
import os,sys import os,sys
import iec61850 import pyiec61850 as iec61850
if __name__=="__main__": if __name__=="__main__":
hostname = "localhost"; hostname = "localhost";
tcpPort = 102 tcpPort = 102

@ -27,7 +27,7 @@ The user needs to:
import time import time
import sys import sys
import iec61850 import pyiec61850 as iec61850
def open_connection(ip_address, mms_port): def open_connection(ip_address, mms_port):

@ -1,5 +1,5 @@
/* File : iec61850.i */ /* File : iec61850.i */
%module(directors="1") iec61850 %module(directors="1") pyiec61850
%ignore ControlObjectClient_setTestMode(ControlObjectClient self); %ignore ControlObjectClient_setTestMode(ControlObjectClient self);
%ignore CDA_OperBoolean(ModelNode* parent, bool isTImeActivated); %ignore CDA_OperBoolean(ModelNode* parent, bool isTImeActivated);
%ignore LogicalNode_hasBufferedReports(LogicalNode* node); %ignore LogicalNode_hasBufferedReports(LogicalNode* node);

@ -6,7 +6,7 @@ import traceback
import signal import signal
import sys import sys
sys.path.append('.') sys.path.append('.')
import iec61850 import pyiec61850 as iec61850
def signal_handler(signal, frame): def signal_handler(signal, frame):
global running global running
running =0 running =0

@ -2,14 +2,27 @@
Before building you should install swig and python. Before building you should install swig and python.
To build python bindings you have to turn on the BUILD\_PYTHON\_BINDINGS flag in CMake from cmake-gui or in command line: To build python bindings you have to turn on the BUILD\_PYTHON\_BINDINGS flag in CMake from cmake-gui or in command line:
```sh ```sh
$ cmake -DBUILD_PYTHON_BINDINGS=ON . $ mkdir build && cd build
$ cmake -DBUILD_PYTHON_BINDINGS=ON ..
```
Then compile the library and install it:
```sh
$ make
$ sudo make install
```
CMake and swig will automatically detect your python version and install the python library in python library directories.
For running the integrated tests:
```sh
$ make test
``` ```
Then compile the library and install it. CMake and swig will automatically detect your python version and install the python library in python library directories.
pyiec61850 library is to be imported calling pyiec61850 library is to be imported calling
```python ```python
import iec61850 import pyiec61850 as iec61850
``` ```
# Client tutorial # Client tutorial
The python bindings works similarly to the basic C library. However there are some differences: The python bindings works similarly to the basic C library. However there are some differences:

Loading…
Cancel
Save