Commit f185aabf authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

python: add wrapper for libspotgen

For #254.

* python/spot/gen.i, tests/python/gen.py: New files.
* python/Makefile.am, tests/Makefile.am: Adjust.
* NEWS: Mention the spot.gen python package.
parent 5e8f3ee6
...@@ -61,6 +61,11 @@ New in spot 2.3.3.dev (not yet released) ...@@ -61,6 +61,11 @@ New in spot 2.3.3.dev (not yet released)
spot::acc_cond::rabin_like_pairs() are implemented for Rabin-like spot::acc_cond::rabin_like_pairs() are implemented for Rabin-like
pairs. pairs.
Python:
- The 'spot.gen' package is a wrapper around the functions from
the libspotgen library.
Bugs fixed: Bugs fixed:
- the transformation to state-based acceptance (spot::sbacc()) was - the transformation to state-based acceptance (spot::sbacc()) was
......
...@@ -12,3 +12,4 @@ buddy.py* ...@@ -12,3 +12,4 @@ buddy.py*
ajax/*.py ajax/*.py
spot/impl.py spot/impl.py
spot/ltsmin.py spot/ltsmin.py
spot/gen.py
...@@ -34,18 +34,21 @@ AM_CPPFLAGS = -I$(PYTHONINC) -I$(top_builddir) -I$(top_srcdir) \ ...@@ -34,18 +34,21 @@ AM_CPPFLAGS = -I$(PYTHONINC) -I$(top_builddir) -I$(top_srcdir) \
# this. # this.
SWIGFLAGS = -c++ -python -py3 -O -nofastproxy -MD SWIGFLAGS = -c++ -python -py3 -O -nofastproxy -MD
EXTRA_DIST = buddy.i spot/impl.i spot/ltsmin.i EXTRA_DIST = buddy.i spot/impl.i spot/ltsmin.i spot/gen.i
nobase_python_PYTHON = \ nobase_python_PYTHON = \
spot/__init__.py \ spot/__init__.py \
spot/aux.py \ spot/aux.py \
spot/impl.py \ spot/impl.py \
spot/ltsmin.py \ spot/ltsmin.py \
spot/gen.py \
buddy.py buddy.py
nobase_pyexec_LTLIBRARIES = _buddy.la spot/_impl.la spot/_ltsmin.la nobase_pyexec_LTLIBRARIES = _buddy.la spot/_impl.la \
spot/_ltsmin.la spot/_gen.la
MAINTAINERCLEANFILES = \ MAINTAINERCLEANFILES = \
$(srcdir)/spot/impl_wrap.cxx $(srcdir)/spot/impl.py \ $(srcdir)/spot/impl_wrap.cxx $(srcdir)/spot/impl.py \
$(srcdir)/spot/ltsmin_wrap.cxx $(srcdir)/spot/ltsmin.py \ $(srcdir)/spot/ltsmin_wrap.cxx $(srcdir)/spot/ltsmin.py \
$(srcdir)/spot/gen_wrap.cxx $(srcdir)/spot/gen.py \
$(srcdir)/buddy_wrap.cxx $(srcdir)/buddy.py $(srcdir)/buddy_wrap.cxx $(srcdir)/buddy.py
## spot ## spot
...@@ -81,6 +84,23 @@ spot/ltsmin.py: spot/ltsmin.i ...@@ -81,6 +84,23 @@ spot/ltsmin.py: spot/ltsmin.i
$(MAKE) $(AM_MAKEFLAGS) spot/ltsmin_wrap.cxx $(MAKE) $(AM_MAKEFLAGS) spot/ltsmin_wrap.cxx
## spot-gen
spot__gen_la_SOURCES = spot/gen_wrap.cxx
spot__gen_la_LDFLAGS = -avoid-version -module $(SYMBOLIC_LDFLAGS)
spot__gen_la_LIBADD = $(top_builddir)/spot/libspot.la \
$(top_builddir)/spot/gen/libspotgen.la
@AMDEP_TRUE@@am__include@ @am__quote@./spot/$(DEPDIR)/gen_wrap.Pcxx@am__quote@
${srcdir}/spot/gen_wrap.cxx: spot/gen.i
$(SWIG) $(SWIGFLAGS) -I$(srcdir) -I$(top_srcdir) -MF spot/$(DEPDIR)/gen_wrap.TPcxx $(srcdir)/spot/gen.i
mv spot/$(DEPDIR)/gen_wrap.TPcxx spot/$(DEPDIR)/gen_wrap.Pcxx
spot/gen.py: spot/gen.i
$(MAKE) $(AM_MAKEFLAGS) spot/gen_wrap.cxx
## buddy ## buddy
_buddy_la_SOURCES = buddy_wrap.cxx _buddy_la_SOURCES = buddy_wrap.cxx
......
// -*- coding: utf-8 -*-
// Copyright (C) 2017 Laboratoire de Recherche et Développement de
// l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
%{
// Workaround for SWIG 2.0.2 using ptrdiff_t but not including cstddef.
// It matters with g++ 4.6.
#include <cstddef>
%}
%module(package="spot", director="1") gen
%include "std_string.i"
%include "exception.i"
%include "std_shared_ptr.i"
%shared_ptr(spot::twa_graph)
%{
#include <spot/gen/automata.hh>
using namespace spot;
%}
%import(module="spot.impl") <spot/misc/common.hh>
%import(module="spot.impl") <spot/tl/formula.hh>
%import(module="spot.impl") <spot/twa/fwd.hh>
%exception {
try {
$action
}
catch (const std::runtime_error& e)
{
SWIG_exception(SWIG_RuntimeError, e.what());
}
}
%include <spot/gen/automata.hh>
...@@ -335,6 +335,7 @@ TESTS_python = \ ...@@ -335,6 +335,7 @@ TESTS_python = \
python/declenv.py \ python/declenv.py \
python/decompose_scc.py \ python/decompose_scc.py \
python/dualize.py \ python/dualize.py \
python/gen.py \
python/implies.py \ python/implies.py \
python/interdep.py \ python/interdep.py \
python/ltl2tgba.test \ python/ltl2tgba.test \
......
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017 Laboratoire de Recherche et Développement de
# l'Epita (LRDE).
#
# This file is part of Spot, a model checking library.
#
# Spot is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Spot is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test that the spot.gen package works, in particular, we want
# to make sure that the objects created from spot.gen methods
# are usable with methods from the spot package.
import spot.gen as gen
from sys import exit
k2 = gen.ks_cobuchi(2)
assert k2.num_states() == 5
# to_str is defined in the spot package, so this makes sure
# the type returned by spot.gen.ks_cobuchi() is the correct one.
assert 'to_str' in dir(k2)
try:
gen.ks_cobuchi(0)
except RuntimeError as e:
assert 'positive argument' in str(e)
else:
exit(2)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment