Fixed SF bug #1297 (Python imports)

This changeset resolves several issues related to python imports.
For example, it's possible now to import modules having same module
names, but belonging to different packages.

From the user's viewpoint, this patch gives a little bit more control on
import directives generated by swig. The user may choose to use relative
or absolute imports (docs are provided in separate PR).

Some details:
  - we (still) generate import directives in form 'import a.b.c' which
    corresponds to absolute imports in python3 and (the only available)
    ambiguous one in python2.
  - added -relativeimport option to use explicit relative import syntax
    (python3),

Tests are under Examples/python, these are in fact regression tests but
with the current swig testing framework it seems to be impossible to put
appropriate tests under test-suite.

Closes #7
This commit is contained in:
Paweł Tomulik 2013-05-28 05:33:56 +02:00 committed by William S Fulton
commit 5562deec62
146 changed files with 1676 additions and 30 deletions

View file

@ -0,0 +1,15 @@
TOP = ../../../../..
SWIG = $(realpath $(TOP)/../preinst-swig)
SWIGOPT =
LIBS =
build:
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
static:
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static
clean:
$(MAKE) -f $(TOP)/Makefile TARGET='foo' python_clean

View file

@ -0,0 +1,5 @@
#ifndef PKG1_PKG2_FOO_HPP
#define PKG1_PKG2_FOO_HPP
#include "../../pkg1/foo.hpp"
struct Pkg2_Foo : public Pkg1_Foo{};
#endif /* PKG1_PKG2_FOO_HPP */

View file

@ -0,0 +1,6 @@
%module(package="pkg1.pkg2") foo
%{
#include "../../pkg1/pkg2/foo.hpp"
%}
%import "../../pkg1/foo.i"
%include "../../pkg1/pkg2/foo.hpp"