SINGA-108 Add Python wrapper to singa
Add hook after make python wrappers and run python check only if
--enable-python is declared.
If you want to compile SINGA with python wrappers, just run:
./configure --enable-python
make
After make, you will find a file called "_driver.so" in
tool/python/singa/, which can be imported by python.
If you encounter an error called "Python.h not found", then please
specify your python include path using --with-python. For example:
./configure --enable-python --with-python=/usr/local/python2.7
If you do not know the python include path, just run:
python-config --includes
You can also run "make install" after "make" to automatically copy
_driver.so into tool/python/singa.
For example test, please run this command: (mnist example)
bin/singa-run.sh -conf examples/mnist/job.cof -exec tool/python/singa.py
Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/be0f1797
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/be0f1797
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/be0f1797
Branch: refs/heads/master
Commit: be0f17971b722e4f6ad3ae505e29cef7155bc112
Parents: 94ff71c
Author: xiezl <[email protected]>
Authored: Thu Dec 10 11:32:15 2015 +0800
Committer: xiezl <[email protected]>
Committed: Thu Dec 10 21:21:35 2015 +0800
----------------------------------------------------------------------
Makefile.am | 7 +++++++
configure.ac | 20 ++++++++++----------
tool/python/singa.py | 43 ++++++++++++++++++++++---------------------
3 files changed, 39 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/be0f1797/Makefile.am
----------------------------------------------------------------------
diff --git a/Makefile.am b/Makefile.am
index cd9524c..835f66d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -252,6 +252,13 @@ clean-local:
rm -rf rat_check
rm -rf tool/python/pb2
+all-local:
+ @if [ -f ".libs/_driver.so" ]; then \
+ echo "Copy libs for python wrapper"; \
+ cp -f .libs/_driver.so tool/python/singa/; \
+ touch tool/python/singa/__init__.py; \
+ fi
+
rat:
@if test ! -z '$(shell command -v java 2>/dev/null)'; then \
if test ! -z '$(shell echo $$RAT_PATH)'; then \
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/be0f1797/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 1c4d3aa..902beab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -157,23 +157,23 @@ AC_SUBST(PYLIBS)
AC_ARG_WITH([python],
[AS_HELP_STRING([--with-python=PATH],[prefix where python is installed])],
- [python_prefix=$withval],[python_prefix="/usr/local"])
+ [python_prefix=$withval],[python_prefix="/usr/include/python`python -V
2>&1 | awk '{print substr($2,1,3)}'`"])
if test "$python_prefix" == "yes"; then
if test "$withval" == "yes"; then
- python_prefix="/usr/local"
+ python_prefix="/usr/include/python`python -V 2>&1 | awk '{print
substr($2,1,3)}'`"
fi
fi
-AC_MSG_CHECKING([Python.h in $python_prefix])
-if test -f "$python_prefix/Python.h"; then
- AC_MSG_RESULT([python found])
- AC_DEFINE_UNQUOTED([PYTHON_PATH], ["$python_prefix"], [Path to python
binary])
-else
- AC_MSG_RESULT([python not found!])
- AC_MSG_FAILURE([Python.h was not found in $py_prefix])
-fi
if test x"$enable_python" != x"no"; then
+ AC_MSG_CHECKING([Python.h in $python_prefix])
+ if test -f "$python_prefix/Python.h"; then
+ AC_MSG_RESULT([Python.h found])
+ AC_DEFINE_UNQUOTED([PYTHON_PATH], ["$python_prefix"], [Path to python
binary])
+ else
+ AC_MSG_RESULT([Python.h not found!])
+ AC_MSG_FAILURE([Python.h was not found in $python_prefix])
+ fi
#AC_DEFINE(PY,[1],[Defined if PY should be used])
PY_PROGS='_driver.la '
PYFLAGS="-I$python_prefix "
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/be0f1797/tool/python/singa.py
----------------------------------------------------------------------
diff --git a/tool/python/singa.py b/tool/python/singa.py
index 00af545..6d03331 100755
--- a/tool/python/singa.py
+++ b/tool/python/singa.py
@@ -1,26 +1,27 @@
-/************************************************************
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*
-*************************************************************/
-
#!/usr/bin/env python
+#/************************************************************
+#*
+#* Licensed to the Apache Software Foundation (ASF) under one
+#* or more contributor license agreements. See the NOTICE file
+#* distributed with this work for additional information
+#* regarding copyright ownership. The ASF licenses this file
+#* to you under the Apache License, Version 2.0 (the
+#* "License"); you may not use this file except in compliance
+#* with the License. You may obtain a copy of the License at
+#*
+#* http://www.apache.org/licenses/LICENSE-2.0
+#*
+#* Unless required by applicable law or agreed to in writing,
+#* software distributed under the License is distributed on an
+#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#* KIND, either express or implied. See the License for the
+#* specific language governing permissions and limitations
+#* under the License.
+#*
+#*************************************************************/
+
+
import os
import sys