Add example to test the Python module being renamed to __init__.py
This examples tests the SWIG generated module being placed into a directory and then renamed __init__.py to convert the module into a package. This ability stopped working in swig-3.0.9. However, only Python 2.7 or 3.3 and later work. If Python 3.2 support is needed, use moduleimport in %module to customise the import code. Issue #1282
This commit is contained in:
parent
b19d3e06b3
commit
51dadaeacd
8 changed files with 101 additions and 0 deletions
20
Examples/python/import_packages/module_is_init/pkg1/Makefile
Normal file
20
Examples/python/import_packages/module_is_init/pkg1/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
TOP = ../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
|
||||
mv foo.py __init__.py
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
rm -f __init__.py
|
||||
10
Examples/python/import_packages/module_is_init/pkg1/foo.hpp
Normal file
10
Examples/python/import_packages/module_is_init/pkg1/foo.hpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
int foofunction(int i) {
|
||||
return i *= 10;
|
||||
}
|
||||
|
||||
struct FooClass {
|
||||
int foomethod(int i) {
|
||||
return i += 5;
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
%module foo
|
||||
%{
|
||||
#include "./foo.hpp"
|
||||
%}
|
||||
%include "./foo.hpp"
|
||||
Loading…
Add table
Add a link
Reference in a new issue