Skip to content

Commit

Permalink
Rewrite the python bindings using swig (#5)
Browse files Browse the repository at this point in the history
Rewrite the python bindings using swig
Silence most of the compiler warnings
Generate meta-functions instead of hard coded functions
Improve backwards compatibility with older versions of the bindings
Also mimic the ruby bindings syntax.

Co-authored-by: Noel Power <noel.power@suse.com>
  • Loading branch information
dmulder and noelpower committed Nov 13, 2017
1 parent a94b0fc commit 0ab5223
Show file tree
Hide file tree
Showing 41 changed files with 1,253 additions and 5,208 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,14 @@ Makefile.am.common
.dep
tmp.*
*.log
ar-lib
compile
config.h.in~
py-compile
src/.deps/
src/.libs/
src/YCPMap.h
*.la
*.lo
src/yast-core_wrap.cxx
src/ycp.py
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM yastdevel/cpp
RUN zypper --gpg-auto-import-keys --non-interactive in --no-recommends \
python-devel
python-devel swig autoconf-archive
COPY . /usr/src/app
14 changes: 9 additions & 5 deletions configure.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
@YAST2-CHECKS-COMMON@
@YAST2-CHECKS-PROGRAM@

AC_PROGRAM_PATH(PYTHON, python)
if test -z "$PYTHON" ; then
AC_MSG_ERROR(python is missing; please install python 2.6.)
fi
AC_SUBST(PYTHON)
AM_PATH_PYTHON([2.7])
AX_PYTHON_DEVEL
AX_PKG_SWIG([], [], AC_MSG_ERROR([SWIG is required to build.]))
AX_SWIG_PYTHON
AC_PROG_CXX

yast_plugin_dir=${libdir}/YaST2/plugin
AC_SUBST([py2langdir], [$yast_plugin_dir])
AC_SUBST([pkgpy2langdir], [\${yast_plugin_dir}])

##AC_CHECK_HEADER(python2.6/Python.h, , AC_MSG_ERROR(Headers for Python are missing. Please install the package python-devel.) )

Expand Down
5 changes: 5 additions & 0 deletions package/yast2-python-bindings.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Wed Nov 8 21:35:20 UTC 2017 - dmulder@suse.com

- Rewrite the python bindings using swig

-------------------------------------------------------------------
Wed Nov 13 15:56:18 UTC 2013 - jreidinger@suse.com

Expand Down
52 changes: 29 additions & 23 deletions package/yast2-python-bindings.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# spec file for package yast2-python-bindings
#
# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
Expand All @@ -17,28 +17,33 @@


Name: yast2-python-bindings
Version: 3.1.1
Version: 4.0.0
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source0: %{name}-%{version}.tar.bz2

Group: System/YaST
License: GPL-2.0
BuildRequires: curl-devel gcc-c++ yast2-core-devel python-devel yast2-ycp-ui-bindings-devel libtool
BuildRequires: yast2-devtools >= 3.1.10
BuildRequires: autoconf
BuildRequires: autoconf-archive
BuildRequires: automake
BuildRequires: gcc-c++
BuildRequires: libtool
BuildRequires: libyui-devel
BuildRequires: make
BuildRequires: python
BuildRequires: python-devel
BuildRequires: swig
BuildRequires: yast2-core-devel
BuildRequires: yast2-ycp-ui-bindings
BuildRequires: yast2-ycp-ui-bindings-devel

# YCPValue::valuetype_str()
Requires: yast2-core >= 2.16.37
BuildRequires: yast2-core-devel >= 2.16.37
BuildRequires: yast2-ycp-ui-bindings-devel >= 2.16.37
Requires: yast2-ycp-ui-bindings >= 2.16.37
Requires: python
%if 0%{?suse_version} < 1220
BuildRequires: libxcrypt-devel
%endif
Requires: python
Requires: yast2-core
Requires: yast2-ycp-ui-bindings

Summary: Python bindings for the YaST platform.
Summary: Python bindings for the YaST platform
License: GPL-2.0
Group: System/YaST

%description
The bindings allow YaST modules to be written using the Python language
Expand All @@ -53,16 +58,17 @@ and also Python scripts can use YaST agents, APIs and modules.
%install
%yast_install

rm $RPM_BUILD_ROOT/%{yast_plugindir}/libpy2lang_python.la
rm $RPM_BUILD_ROOT/%{python_sitearch}/libYCP.la

rm %{buildroot}/%{python_sitelib}/*.pyc
rm %{buildroot}/%{python_sitelib}/*.pyo
rm %{buildroot}/%{python_sitearch}/*.la
rm %{buildroot}/%{yast_plugindir}/libpy2lang_python.la

%files
%defattr (-, root, root)
%doc %{yast_docdir}
%{python_sitelib}/*.py
%{python_sitearch}/_ycp.*
%{yast_plugindir}/libpy2lang_python.so.*
%{yast_plugindir}/libpy2lang_python.so

# libYCP goes elsewhere
# %dir %{_libdir}/python
%{python_sitearch}/*
%doc %{yast_docdir}
%changelog
118 changes: 18 additions & 100 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,113 +1,31 @@
#
# Makefile.am for python-bindings/src
#
BUILT_SOURCES = ycp.py
ycp.py yast-core_wrap.cxx: yast-core.i ytypes.i ycp.i $(libpy2UI) YCPMap.h
$(SWIG) $(AX_SWIG_PYTHON_OPT) -c++ -I/usr/include/YaST2 -o $@ $<

AM_CXXFLAGS = -DY2LOG=\"Python\" -DMODULEDIR=\"$(moduledir)\" \
-DLOCALEDIR=\"${localedir}\"
# Remove non-standard syntax unrecognized by swig from YCPMap.h
YCPMap.h:
sed 's/__attribute__ ((deprecated)) //g' /usr/include/YaST2/ycp/YCPMap.h > YCPMap.h

MY_PYTHON_VENDORARCH = $(subst /usr,$(prefix),$(PYTHON_VENDORARCH))
#pythonpydir = $(MY_PYTHON_VENDORARCH)/YaST
pythonpydir = $(MY_PYTHON_VENDORARCH)/site-packages
pythonsodir = $(MY_PYTHON_VENDORARCH)/site-packages
python_PYTHON = ycp.py yast.py

pyexec_LTLIBRARIES = _ycp.la

pythonpy_DATA = YCPDeclarations.py
_ycp_la_SOURCES = yast-core_wrap.cxx yast.cpp yast-core.i ytypes.i ycp.i YPythonCode.cc

# plugin, libtool forces 'lib' prefix
plugin_LTLIBRARIES = libpy2lang_python.la
noinst_LTLIBRARIES = libYCPTypes.la liby2lang_python.la libYCPDeclarations.la
pythonso_LTLIBRARIES = libYCP.la
_ycp_la_LDFLAGS = -module ${PYTHON_LDFLAGS} -Wl,-rpath=$(py2langdir)

libYCPTypes_la_SOURCES = YCPTypes.cc YCPTypes.h \
YCPTypes/YCPTypesInternal.cc YCPTypes/YCPTypesInternal.h \
YCPTypes/Path.cc \
YCPTypes/Symbol.cc \
YCPTypes/Code.cc \
YCPTypes/Term.cc
_ycp_la_LIBADD = -L$(py2langdir) -lpy2UI

libYCPDeclarations_la_SOURCES = YCPDeclarations.cc YCPDeclarations.h
_ycp_la_CPPFLAGS = -std=c++11 -I/usr/include/YaST2 ${PYTHON_CPPFLAGS} -Wno-terminate

# binary part of the python module
libYCP_la_SOURCES = \
$(liby2lang_python_la_SOURCES) \
YCP.cc \
PythonLogger.cc PythonLogger.h
py2lang_LTLIBRARIES = libpy2lang_python.la

libpy2lang_python_la_SOURCES = Y2PythonClientComponent.cc Y2CCPythonClient.cc

libpy2lang_python_la_LDFLAGS = -lpython2.7 ${PYTHON_LDFLAGS} -Wl,-rpath=$(pyexecdir)

install-data-hook:
$(LN_S) -f libYCP.so $(DESTDIR)$(pythonsodir)/ycp.so
libpy2lang_python_la_CPPFLAGS = -std=c++11 -I/usr/include/YaST2 ${PYTHON_CPPFLAGS} -Wno-terminate

AM_CXXFLAGS = -DY2LOG=\"Python\"

# are there enough yast libraries?
# check with y2base, integrate them like y2pm does

libYCP_la_LDFLAGS = $(PYTHON_LDFLAGS) \
-L$(libdir) -L$(plugindir) \
-Xlinker --whole-archive \
-lpy2scr \
-lpy2wfm \
-lscr -lpy2UI \
-lycp -ly2 \
-Xlinker --no-whole-archive \
-ly2util \
-version-info 2:0

libYCP_la_LIBADD = libYCPTypes.la libpy2lang_python.la#libYCPDeclarations.la


libpy2lang_python_la_LDFLAGS = -version-info 2:0

liby2lang_python_la_LDFLAGS = -version-info 2:0


# the yast libraries are apparently necessary when we're loaded by python.
libpy2lang_python_la_LDFLAGS = $(PYTHON_LDFLAGS) \
-L$(libdir) -L$(plugindir) \
-lycp -ly2 -ly2util

libpy2lang_python_la_LIBADD = libYCPTypes.la libYCPDeclarations.la


liby2lang_python_la_LIBADD = $(PYTHON_LDFLAGS)


liby2lang_python_la_SOURCES = \
YPython.cc YPython.h

# Auto-generated stub for dynamic loading of python modules.
# And also register the interface to the YCP module
## which is linked in already and won't be in the standard python location.
#
# This results in a linker warning:
# *** Warning: Linking the shared library libpy2lang_python.la against the
# *** static library /usr/lib/python5/.../DynaLoader.a is not portable!
#
# According to mls@suse.de this warning can safely be disregarded:
# The SuSE DynaLoader is compiled with -fPIC for just this situation.
#
# -- sh@suse.de 2003-07-24
#pythonxsi.c:
# python -MExtUtils::Embed -e xsinit -- -o pythonxsi.c -std
# See "man pythonembed"


# the plugin adds the liby2 component interface

libpy2lang_python_la_SOURCES = \
$(liby2lang_python_la_SOURCES) \
Y2CCPython.cc Y2CCPython.h \
YPythonNamespace.cc YPythonNamespace.h \
Y2PythonComponent.cc Y2PythonComponent.h

# CLEANFILES = \
# pythonxsi.c

INCLUDES = -I$(srcdir)/include -I$(includedir) ${ZYPP_CFLAGS} -I/usr/include/python

# generated from YaPI.pm.in by configure
# nodist_module_DATA = YaPI.pm

#EXTRA_DIST = $(pythonpy_DATA) $(module_DATA)
EXTRA_DIST = $(pythonpy_DATA)

CLEANFILES = ycp.py yast-core_wrap.cxx YCPMap.h
31 changes: 0 additions & 31 deletions src/PythonLogger.cc

This file was deleted.

24 changes: 0 additions & 24 deletions src/PythonLogger.h

This file was deleted.

58 changes: 0 additions & 58 deletions src/Y2CCPython.cc

This file was deleted.

Loading

0 comments on commit 0ab5223

Please sign in to comment.