mirror of
https://github.com/openbabel/openbabel.git
synced 2025-02-25 18:55:23 -06:00
Split python bindings into multiple pieces. Should solve PR#1905826.
This commit is contained in:
@@ -20,8 +20,9 @@ dist-hook:
|
||||
|
||||
if MAINTAINER_MODE
|
||||
if BUILD_SWIG
|
||||
BUILT_SOURCES = perl/openbabel_perl.cpp python/openbabel_python.cpp \
|
||||
java/openbabel_java.cpp csharp/openbabel_csharp.cpp
|
||||
BUILT_SOURCES = perl/openbabel_perl.cpp \
|
||||
java/openbabel_java.cpp csharp/openbabel_csharp.cpp \
|
||||
python/obcore.cpp python/obconversion.cpp python/obtemplate.cpp
|
||||
|
||||
script_includes = $(top_srcdir)/include/openbabel
|
||||
script_headers = $(script_includes)/mol.h $(script_includes)/obconversion.h \
|
||||
@@ -34,19 +35,17 @@ perl/openbabel_perl.cpp: openbabel-perl.i $(script_headers)
|
||||
sed -e "s/^@EXPORT.*/& sub dl_load_flags { 0x01 }/" <perl/OpenBabel.pm >perl/OpenBabel.new;
|
||||
mv perl/OpenBabel.new perl/OpenBabel.pm;
|
||||
|
||||
python/openbabel_python.cpp: openbabel-python.i $(script_headers)
|
||||
python/obconversion.cpp: openbabel-python2.i $(script_headers)
|
||||
$(SWIG) -small -O -python -templatereduce -naturalvar \
|
||||
-c++ -o $@ -I$(top_srcdir)/include -I$(top_builddir)/include $<;
|
||||
|
||||
python/obtemplate.cpp: openbabel-python3.i $(script_headers)
|
||||
$(SWIG) -small -O -python -templatereduce -naturalvar \
|
||||
-c++ -o $@ -I$(top_srcdir)/include -I$(top_builddir)/include $<;
|
||||
|
||||
python/obcore.cpp: openbabel-python.i $(script_headers)
|
||||
$(SWIG) -small -O -python -templatereduce -naturalvar \
|
||||
-c++ -o $@ -I$(top_srcdir)/include -I$(top_builddir)/include $<;
|
||||
echo "import sys" >python/ob.py;
|
||||
echo "if sys.platform.find(\"linux\") != -1:" >>python/ob.py;
|
||||
echo " try:" >>python/ob.py;
|
||||
echo " import dl" >>python/ob.py;
|
||||
echo " except ImportError:" >>python/ob.py;
|
||||
echo " import DLFCN as dl" >>python/ob.py;
|
||||
echo " sys.setdlopenflags(sys.getdlopenflags() | dl.RTLD_GLOBAL)" >>python/ob.py;
|
||||
echo >>python/ob.py;
|
||||
cat python/openbabel.py >>python/ob.py;
|
||||
mv python/ob.py python/openbabel.py;
|
||||
|
||||
java/openbabel_java.cpp: openbabel-java.i $(script_headers)
|
||||
$(SWIG) -small -O -java -naturalvar -templatereduce -c++ -o $@ \
|
||||
|
||||
@@ -34,8 +34,12 @@ host_triplet = @host@
|
||||
subdir = scripts
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
|
||||
$(top_srcdir)/configure.in
|
||||
am__aclocal_m4_deps = $(top_srcdir)/autoconf/libtool.m4 \
|
||||
$(top_srcdir)/autoconf/ltoptions.m4 \
|
||||
$(top_srcdir)/autoconf/ltsugar.m4 \
|
||||
$(top_srcdir)/autoconf/ltversion.m4 \
|
||||
$(top_srcdir)/autoconf/lt~obsolete.m4 \
|
||||
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.in
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
@@ -89,6 +93,7 @@ LIBDL = @LIBDL@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAINT = @MAINT@
|
||||
@@ -98,6 +103,8 @@ NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
OTOOL = @OTOOL@
|
||||
OTOOL64 = @OTOOL64@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
@@ -173,6 +180,7 @@ sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
EXTRA_DIST = openbabel-perl.i perl \
|
||||
@@ -185,9 +193,11 @@ EXTRA_DIST = openbabel-perl.i perl \
|
||||
# build the scripting language interfaces if --enable-maintainer-mode was set
|
||||
# and SWIG is available -- please use the most recent version of SWIG
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@BUILT_SOURCES = perl/openbabel_perl.cpp \
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ python/openbabel_python.cpp \
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ java/openbabel_java.cpp \
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ csharp/openbabel_csharp.cpp \
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ python/obcore.cpp \
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ python/obconversion.cpp \
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ python/obtemplate.cpp \
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ $(am__append_1)
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@script_includes = $(top_srcdir)/include/openbabel
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@script_headers = $(script_includes)/mol.h $(script_includes)/obconversion.h \
|
||||
@@ -386,19 +396,17 @@ dist-hook:
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ sed -e "s/^@EXPORT.*/& sub dl_load_flags { 0x01 }/" <perl/OpenBabel.pm >perl/OpenBabel.new;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ mv perl/OpenBabel.new perl/OpenBabel.pm;
|
||||
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@python/openbabel_python.cpp: openbabel-python.i $(script_headers)
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@python/obconversion.cpp: openbabel-python2.i $(script_headers)
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ $(SWIG) -small -O -python -templatereduce -naturalvar \
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ -c++ -o $@ -I$(top_srcdir)/include -I$(top_builddir)/include $<;
|
||||
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@python/obtemplate.cpp: openbabel-python3.i $(script_headers)
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ $(SWIG) -small -O -python -templatereduce -naturalvar \
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ -c++ -o $@ -I$(top_srcdir)/include -I$(top_builddir)/include $<;
|
||||
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@python/obcore.cpp: openbabel-python.i $(script_headers)
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ $(SWIG) -small -O -python -templatereduce -naturalvar \
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ -c++ -o $@ -I$(top_srcdir)/include -I$(top_builddir)/include $<;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ echo "import sys" >python/ob.py;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ echo "if sys.platform.find(\"linux\") != -1:" >>python/ob.py;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ echo " try:" >>python/ob.py;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ echo " import dl" >>python/ob.py;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ echo " except ImportError:" >>python/ob.py;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ echo " import DLFCN as dl" >>python/ob.py;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ echo " sys.setdlopenflags(sys.getdlopenflags() | dl.RTLD_GLOBAL)" >>python/ob.py;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ echo >>python/ob.py;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ cat python/openbabel.py >>python/ob.py;
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ mv python/ob.py python/openbabel.py;
|
||||
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@java/openbabel_java.cpp: openbabel-java.i $(script_headers)
|
||||
@BUILD_SWIG_TRUE@@MAINTAINER_MODE_TRUE@ $(SWIG) -small -O -java -naturalvar -templatereduce -c++ -o $@ \
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
%module openbabel
|
||||
%module obcore
|
||||
|
||||
%{
|
||||
// used to set import/export for Cygwin DLLs
|
||||
@@ -41,28 +41,6 @@
|
||||
|
||||
%}
|
||||
|
||||
%include "std_list.i"
|
||||
%include "std_map.i"
|
||||
%include "std_vector.i"
|
||||
%include "std_string.i"
|
||||
|
||||
namespace std {
|
||||
%template (vectorInt) vector<int>;
|
||||
%template (vectorUnsignedInt) vector<unsigned int>;
|
||||
%template (vvInt) vector< vector<int> >;
|
||||
%template (vectorDouble) vector<double>;
|
||||
%template (vectorString) vector<std::string>;
|
||||
%template (vVector3) vector<OpenBabel::vector3>;
|
||||
|
||||
%template (vectorMol) vector<OpenBabel::OBMol>;
|
||||
%template (vectorBond) vector<OpenBabel::OBBond>;
|
||||
%template (vectorResidue) vector<OpenBabel::OBResidue>;
|
||||
%template (vectorRing) vector<OpenBabel::OBRing>;
|
||||
%template (vectorpRing) vector<OpenBabel::OBRing*>;
|
||||
%template (vectorData) vector<OpenBabel::OBGenericData*>;
|
||||
}
|
||||
|
||||
|
||||
%inline %{
|
||||
OpenBabel::OBPairData *toPairData(OpenBabel::OBGenericData *data) {
|
||||
return (OpenBabel::OBPairData *) data;
|
||||
@@ -95,11 +73,11 @@ OpenBabel::OBUnitCell *toUnitCell(OpenBabel::OBGenericData *data) {
|
||||
//# %import <openbabel/bitvec.h>
|
||||
%import <openbabel/typer.h>
|
||||
|
||||
%include <openbabel/plugin.h>
|
||||
%import <openbabel/plugin.h>
|
||||
|
||||
%include <openbabel/oberror.h>
|
||||
%include <openbabel/format.h>
|
||||
%include <openbabel/obconversion.h>
|
||||
%import <openbabel/oberror.h>
|
||||
%import <openbabel/format.h>
|
||||
%import <openbabel/obconversion.h>
|
||||
%include <openbabel/residue.h>
|
||||
%include <openbabel/internalcoord.h>
|
||||
%include <openbabel/atom.h>
|
||||
@@ -110,11 +88,11 @@ OpenBabel::OBUnitCell *toUnitCell(OpenBabel::OBGenericData *data) {
|
||||
%include <openbabel/alias.h>
|
||||
%include <openbabel/atomclass.h>
|
||||
|
||||
%include <openbabel/fingerprint.h>
|
||||
%include <openbabel/descriptor.h>
|
||||
%include <openbabel/forcefield.h>
|
||||
%import <openbabel/fingerprint.h>
|
||||
%import <openbabel/descriptor.h>
|
||||
%import <openbabel/forcefield.h>
|
||||
|
||||
%include <openbabel/op.h>
|
||||
%import <openbabel/op.h>
|
||||
|
||||
%include <openbabel/bitvec.h>
|
||||
|
||||
|
||||
92
scripts/openbabel-python2.i
Normal file
92
scripts/openbabel-python2.i
Normal file
@@ -0,0 +1,92 @@
|
||||
%module obconversion
|
||||
|
||||
%{
|
||||
// used to set import/export for Cygwin DLLs
|
||||
#ifdef WIN32
|
||||
#define USING_OBDLL
|
||||
#endif
|
||||
|
||||
#include <openbabel/base.h>
|
||||
|
||||
#include <openbabel/generic.h>
|
||||
#include <openbabel/griddata.h>
|
||||
#include <openbabel/math/vector3.h>
|
||||
#include <openbabel/bitvec.h>
|
||||
|
||||
#include <openbabel/mol.h>
|
||||
#include <openbabel/obconversion.h>
|
||||
#include <openbabel/oberror.h>
|
||||
#include <openbabel/plugin.h>
|
||||
#include <openbabel/fingerprint.h>
|
||||
#include <openbabel/descriptor.h>
|
||||
#include <openbabel/format.h>
|
||||
#include <openbabel/forcefield.h>
|
||||
#include <openbabel/op.h>
|
||||
|
||||
%}
|
||||
|
||||
// These methods are renamed to valid Python method names, as otherwise
|
||||
// they cannot be used from Python
|
||||
%rename(inc) *::operator++;
|
||||
%rename(good) *::operator bool;
|
||||
|
||||
%import <openbabel/babelconfig.h>
|
||||
|
||||
%import <openbabel/base.h>
|
||||
%import <openbabel/generic.h>
|
||||
%import <openbabel/griddata.h>
|
||||
|
||||
%import <openbabel/math/vector3.h>
|
||||
%import <openbabel/bitvec.h>
|
||||
|
||||
%import <openbabel/chains.h>
|
||||
%import <openbabel/typer.h>
|
||||
|
||||
%include <openbabel/plugin.h>
|
||||
%include <openbabel/oberror.h>
|
||||
%include <openbabel/format.h>
|
||||
%include <openbabel/obconversion.h>
|
||||
%import <openbabel/residue.h>
|
||||
%import <openbabel/internalcoord.h>
|
||||
%import <openbabel/atom.h>
|
||||
%import <openbabel/bond.h>
|
||||
%import <openbabel/mol.h>
|
||||
%import <openbabel/ring.h>
|
||||
%import <openbabel/parsmart.h>
|
||||
|
||||
%include <openbabel/fingerprint.h>
|
||||
%include <openbabel/descriptor.h>
|
||||
%include <openbabel/forcefield.h>
|
||||
|
||||
%include <openbabel/op.h>
|
||||
%include <openbabel/bitvec.h>
|
||||
|
||||
%ignore *::operator=;
|
||||
|
||||
%include "carrays.i"
|
||||
%array_class(double, doubleArray)
|
||||
%pythoncode %{
|
||||
def double_array(mylist):
|
||||
"""Create a C array of doubles from a list."""
|
||||
c = doubleArray(len(mylist))
|
||||
for i,v in enumerate(mylist):
|
||||
c[i] = v
|
||||
return c
|
||||
%}
|
||||
|
||||
# Functions to set the log file to std::cout and std::cerr
|
||||
|
||||
%ignore OBForceField::SetLogFile(std::ostream *pos);
|
||||
%extend OpenBabel::OBForceField {
|
||||
void SetLogToStdOut()
|
||||
{
|
||||
self->SetLogFile(&std::cout);
|
||||
}
|
||||
|
||||
void SetLogToStdErr()
|
||||
{
|
||||
self->SetLogFile(&std::cerr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
65
scripts/openbabel-python3.i
Normal file
65
scripts/openbabel-python3.i
Normal file
@@ -0,0 +1,65 @@
|
||||
%module obtemplate
|
||||
|
||||
%{
|
||||
// used to set import/export for Cygwin DLLs
|
||||
#ifdef WIN32
|
||||
#define USING_OBDLL
|
||||
#endif
|
||||
|
||||
#include <openbabel/base.h>
|
||||
#include <openbabel/mol.h>
|
||||
#include <openbabel/atom.h>
|
||||
#include <openbabel/bond.h>
|
||||
#include <openbabel/residue.h>
|
||||
#include <openbabel/ring.h>
|
||||
|
||||
%}
|
||||
|
||||
%include "std_list.i"
|
||||
%include "std_map.i"
|
||||
%include "std_vector.i"
|
||||
%include "std_string.i"
|
||||
|
||||
namespace std {
|
||||
%template (vectorInt) vector<int>;
|
||||
%template (vectorUnsignedInt) vector<unsigned int>;
|
||||
%template (vvInt) vector< vector<int> >;
|
||||
%template (vectorDouble) vector<double>;
|
||||
%template (vectorString) vector<std::string>;
|
||||
%template (vVector3) vector<OpenBabel::vector3>;
|
||||
|
||||
%template (vectorMol) vector<OpenBabel::OBMol>;
|
||||
%template (vectorBond) vector<OpenBabel::OBBond>;
|
||||
%template (vectorResidue) vector<OpenBabel::OBResidue>;
|
||||
%template (vectorRing) vector<OpenBabel::OBRing>;
|
||||
%template (vectorpRing) vector<OpenBabel::OBRing*>;
|
||||
%template (vectorData) vector<OpenBabel::OBGenericData*>;
|
||||
}
|
||||
|
||||
// These methods are renamed to valid Python method names, as otherwise
|
||||
// they cannot be used from Python
|
||||
%rename(inc) *::operator++;
|
||||
%rename(good) *::operator bool;
|
||||
|
||||
%import <openbabel/babelconfig.h>
|
||||
|
||||
%import <openbabel/base.h>
|
||||
%import <openbabel/residue.h>
|
||||
%import <openbabel/atom.h>
|
||||
%import <openbabel/bond.h>
|
||||
%import <openbabel/mol.h>
|
||||
%import <openbabel/ring.h>
|
||||
|
||||
%ignore *::operator=;
|
||||
|
||||
%include "carrays.i"
|
||||
%array_class(double, doubleArray)
|
||||
%pythoncode %{
|
||||
def double_array(mylist):
|
||||
"""Create a C array of doubles from a list."""
|
||||
c = doubleArray(len(mylist))
|
||||
for i,v in enumerate(mylist):
|
||||
c[i] = v
|
||||
return c
|
||||
%}
|
||||
|
||||
@@ -8,10 +8,10 @@ $CC = 'g++';
|
||||
$srcdir = '../../src';
|
||||
|
||||
# check if we're compiling in the source directory
|
||||
$ldfrom = "\$(OBJECT) -L$srcdir/.libs -lopenbabel -lz"
|
||||
if (-r "$srcdir/.libs/libopenbabel.so") and (-s _) and (-B _);
|
||||
$ldfrom = "\$(OBJECT) -L$srcdir/.libs -lopenbabel -lz"
|
||||
if (-r "$srcdir/.libs/libopenbabel.dylib") and (-s _) and (-B _);
|
||||
$ldfrom = "\$(OBJECT) -L$srcdir/.libs -lopenbabel -lz"
|
||||
if (-r "$srcdir/.libs/libopenbabel.so") and (-s _) and (-B _);
|
||||
$ldfrom = "\$(OBJECT) $srcdir/.libs/libopenbabel.a -lz"
|
||||
if (-r "$srcdir/.libs/libopenbabel.a") and (-s _) and (-B _);
|
||||
|
||||
|
||||
11
scripts/python/openbabel.py
Normal file
11
scripts/python/openbabel.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import sys
|
||||
if sys.platform.find("linux") != -1:
|
||||
try:
|
||||
import dl
|
||||
except ImportError:
|
||||
import DLFCN as dl
|
||||
sys.setdlopenflags(sys.getdlopenflags() | dl.RTLD_GLOBAL)
|
||||
|
||||
import obcore
|
||||
import obconversion
|
||||
import obtemplate
|
||||
@@ -60,8 +60,22 @@ def find_likely_directory():
|
||||
|
||||
OBinclude,OBlibrary = find_likely_directory()
|
||||
|
||||
obExtension = Extension('_openbabel',
|
||||
['openbabel_python.cpp'],
|
||||
obCore = Extension('_obcore',
|
||||
['obcore.cpp'],
|
||||
include_dirs=OBinclude,
|
||||
library_dirs=OBlibrary,
|
||||
libraries=['openbabel']
|
||||
)
|
||||
|
||||
obConversion = Extension('_obconversion',
|
||||
['obconversion.cpp'],
|
||||
include_dirs=OBinclude,
|
||||
library_dirs=OBlibrary,
|
||||
libraries=['openbabel']
|
||||
)
|
||||
|
||||
obTemplate = Extension('_obtemplate',
|
||||
['obtemplate.cpp'],
|
||||
include_dirs=OBinclude,
|
||||
library_dirs=OBlibrary,
|
||||
libraries=['openbabel']
|
||||
@@ -74,7 +88,7 @@ setup(name='openbabel',
|
||||
url='http://openbabel.sourceforge.net/',
|
||||
license='http://www.gnu.org/copyleft/gpl.html',
|
||||
py_modules=['openbabel','pybel'],
|
||||
ext_modules=[obExtension],
|
||||
ext_modules=[obCore, obConversion, obTemplate],
|
||||
description = 'openbabel: Python interface to the Open Babel chemistry library',
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
|
||||
Reference in New Issue
Block a user