diff --git a/configure.ac b/configure.ac index ade14b0c4d6b16d5b55f100b4c19eb4192f4d6a7..0e82c06773daed1c38295fbe23989c10fbdce0b8 100644 --- a/configure.ac +++ b/configure.ac @@ -610,6 +610,10 @@ AS_IF([test ! -f $srcdir/deps/packcc/configure], [(cd $srcdir/deps/packcc; autoreconf -ifv)]) AX_SUBDIRS_CONFIGURE([deps/packcc]) +dnl expose where libtools objects and .so are put (for scripting interface) +LIBTOOL_OBJ_DIR="$objdir" +AC_SUBST(LIBTOOL_OBJ_DIR) + AX_PKG_SWIG([3],[], [AC_MSG_NOTICE([SWIG not found, will not build python interface.])]) AM_CONDITIONAL([WITH_SWIG], [test "x$SWIG" != "x"]) @@ -619,9 +623,13 @@ AS_IF([test "x$SWIG" != "x"],[ AX_PYTHON_DEVEL dnl AX_SWIG_MULTI_MODULE_SUPPORT AX_SWIG_PYTHON + AC_CONFIG_FILES([scripting/setup.py], [chmod +x scripting/setup.py]) + AC_CONFIG_FILES([scripting/__init__.py]) + AC_CONFIG_FILES([scripting/mpython], [chmod +x scripting/mpython]) ]) + AC_CONFIG_FILES([ Makefile include/Makefile @@ -641,10 +649,11 @@ AC_CONFIG_FILES([ deps/libcyaml/Makefile deps/c-timestamp/Makefile scripting/Makefile - scripting/setup.py MaestroConfig.cmake ]) + + dnl AC_SUBST does not preserve executable bit on scripts, so do dnl substitution and chmod in 2 phases m4_define([TESTSCRIPTS], diff --git a/scripting/.gitignore b/scripting/.gitignore index 398f7969790ccb7fdc917219fdd3d2359105b9d0..1c378cb8a0fb8d360a88b47d5f2f284c0981f559 100644 --- a/scripting/.gitignore +++ b/scripting/.gitignore @@ -1,3 +1,4 @@ +__init__.py maestro-py_wrap.c maestro.py setup.py diff --git a/scripting/Makefile.am b/scripting/Makefile.am index fe9551a4be57cf1aa1fe251ba994124b8e3242c9..a6157f0e028b14d1e7b5208e5d5dd50b5667cff8 100644 --- a/scripting/Makefile.am +++ b/scripting/Makefile.am @@ -31,7 +31,8 @@ # AUTOMAKE_OPTIONS = -Wno-error -AM_CPPFLAGS = -I$(PYTHONINC) -I$(top_srcdir)/include $(BUDDY_CPPFLAGS) \ +AM_CPPFLAGS = -I$(PYTHONINC) -I$(top_srcdir)/include \ + -I$(top_srcdir)/deps/mamba/common \ -DSWIG_TYPE_TABLE=mstro EXTRA_DIST = maestro-py.i @@ -45,8 +46,13 @@ pkgpython_PYTHON = maestro.py __init__.py setup.py pkgpyexec_LTLIBRARIES = _maestro.la _maestro_la_LDFLAGS = -avoid-version -module _maestro_la_SOURCES = maestro-py_wrap.c $(SWIG_SOURCES) -_maestro_la_LIBADD = $(top_srcdir)/libmaestro.la -_maestro_la_CPPFLAGS = $(AX_SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)/include -I/usr/include/python@PYTHON_VERSION@ -lpython@PYTHON_VERSION@ +_maestro_la_LIBADD = $(top_srcdir)/libmaestro.la -lpython@PYTHON_VERSION@ +_maestro_la_CPPFLAGS = $(AX_SWIG_PYTHON_CPPFLAGS) \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/deps/mamba/common \ + -I$(top_srcdir)/deps/mamba/memory \ + -DSWIG_TYPE_TABLE=mstro \ + -I/usr/include/python@PYTHON_VERSION@ WRAPPED = $(top_srcdir)/include/maestro.h\ $(top_srcdir)/include/maestro/attributes.h \ diff --git a/scripting/README.md b/scripting/README.md index 5568cbe9c91b490cdeb9c8ae24e4a45178d54983..ebc0014a57be171bc811dde90adaa93b6f796948 100644 --- a/scripting/README.md +++ b/scripting/README.md @@ -4,7 +4,7 @@ Scripting interface to the maestro library We are providing a low-level wrapper library for `libmaestro` at this time for python. -To build it, install swig from your system repositories, or from swig.org. +To build it, install swig from your system repositories, or from swig.org. A version >=4.0.1 is recommended. You also need a development environment for python3; if `configure` fails to detect it, try @@ -17,3 +17,46 @@ PYTHON=python3 ./configure ``` ./configure PYTHON_VERSION=3 ``` + +Automatic (default) Installation +-------------------------------- + +When you install maestro-core the python wrappers will be installed into + +``` +$prefix/lib/python<version>/site-packages +``` + +To use them you may need to to add this directory to your python's search path, e.g., by calling python via + +``` +PYTHONPATH="$prefix/lib/python<version>/site-packages:$PYTHONPATH" python3 +``` + + + + +Installation using setup.py +--------------------------- + +If you use the `setup.py` file provided you should be able to install +the wrappers into 'the ususal place', e.g., the user site-packages or +the `venv` package destination. + +THIS CURRENTLY DOES NOT WORK. + +Installation into user-site-packages directory +------------------------------------------------ + +See above -- use `setup.py` +THIS CURRENTLY DOES NOT WORK. + + +Testing without installation +---------------------------- + +The script in `scripting/mpython` wraps the python interpreter discovered at +configure time with enough PYTHONPATH so that the maestro package can be +imported successfully even while not yet installed. This is used during `make +check`, but may also be useful for experimenting. + diff --git a/scripting/__init__.py b/scripting/__init__.py deleted file mode 100644 index c286fbe0afceaab79f2549019ab5a7a6c0ad37bc..0000000000000000000000000000000000000000 --- a/scripting/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from . import _maestro -import maestro diff --git a/scripting/__init__.py.in b/scripting/__init__.py.in new file mode 100644 index 0000000000000000000000000000000000000000..c89273944471632382499e59b1798cc24a03872a --- /dev/null +++ b/scripting/__init__.py.in @@ -0,0 +1,3 @@ +# Maestro public API +# Currently importing everything that swig wrapped; we may want to be more specific later on +from .maestro import * diff --git a/scripting/check_maestro.py b/scripting/check_maestro.py new file mode 100644 index 0000000000000000000000000000000000000000..0f248f75946c632a32d34b7a7c8b18ae07ab770b --- /dev/null +++ b/scripting/check_maestro.py @@ -0,0 +1,28 @@ +# test with local pool manager only +import maestro as M + +def test_local_pm(): + M.mstro_init("test_workflow", "component1", 0) + cdo1 = M.mstro_cdo_declare("CDO1", None) + cdo2 = M.mstro_cdo_declare("CDO2", None) + + M.mstro_cdo_offer(cdo1) + M.mstro_cdo_offer(cdo2) + + cdo2_copy = M.mstro_cdo_declare("CDO2", None) + M.mstro_cdo_require(cdo2_copy) + M.mstro_cdo_demand(cdo2_copy) + + M.mstro_cdo_withdraw(cdo1) + M.mstro_cdo_withdraw(cdo2) + + M.mstro_cdo_dispose(cdo1) + M.mstro_cdo_dispose(cdo2) + M.mstro_cdo_dispose(cdo2_copy) + + M.mstro_finalize() + + +test_local_pm() +test_local_pm() + diff --git a/scripting/maestro-py.i b/scripting/maestro-py.i index f60b356a83240fb8e6e3f8e28b69adc65392fe75..20064c8fda7b307a1981e16945fb59e2835dda37 100644 --- a/scripting/maestro-py.i +++ b/scripting/maestro-py.i @@ -21,6 +21,9 @@ } } +/* swig needs help for opaque data types to generate a proper descriptor for the cell around them */ +//typedef void* mstro_cdo; + /* CDO return values: */ %typemap(in, numinputs=0) mstro_cdo *result (mstro_cdo temp) { $1 = &temp; @@ -30,7 +33,7 @@ /* Create shadow object (do not use SWIG_POINTER_NEW) */ PyObject * temp = SWIG_NewPointerObj(*$1, $descriptor(mstro_cdo), - SWIG_POINTER_NEW); + SWIG_POINTER_NOSHADOW); /* if multiple results: ensure result is a list */ if(VOID_Object==$result) { /* we're producing the first result */ diff --git a/scripting/mpython.in b/scripting/mpython.in new file mode 100644 index 0000000000000000000000000000000000000000..d5340bd0df64079c5cd00ecf6823be5e212fcaec --- /dev/null +++ b/scripting/mpython.in @@ -0,0 +1,6 @@ +#!/bin/sh +# Wrapper for running the user-provided python with maestro loaded +# while maestro is still uninstalled +PYTHONPATH="@abs_top_srcdir@/scripting:@abs_top_srcdir@/scripting/@LIBTOOL_OBJ_DIR@/:$PYTHONPATH" +export PYTHONPATH +exec @PYTHON@ $@ diff --git a/scripting/setup.py.in b/scripting/setup.py.in index 85801a2625e06fbcfc707c253d68f73b3ceab8df..43278f7aa6ea9d1902bb67bd4709e95ba4304652 100644 --- a/scripting/setup.py.in +++ b/scripting/setup.py.in @@ -9,7 +9,11 @@ from distutils.core import setup, Extension maestro_module = Extension('maestro', sources=['maestro-py_wrap.c'], - include_dirs = ['@top_srcdir@/include'], + include_dirs = ['@top_srcdir@/include', + '@top_srcdir@/deps/mamba/common', + '@top_srcdir@/deps/mamba/memory'], + library_dirs = ['@prefix@/lib'], + runtime_library_dirs = ['@prefix@/lib'], libraries = ['maestro'], )