update swig on windows

This commit is contained in:
Bassem Girgis
2019-08-04 21:38:19 -05:00
parent 8414b7136b
commit 76ad52be58
5943 changed files with 91790 additions and 71892 deletions

View File

@@ -0,0 +1,49 @@
TOP = ../..
SWIGOPT =
LIBS =
import_packages_subdirs = \
same_modnames1 \
same_modnames2 \
from_init1 \
from_init2 \
from_init3 \
module_is_init \
relativeimport1 \
relativeimport2 \
relativeimport3 \
split_modules \
namespace_pkg \
check: build
if test "x$(SRCDIR)" != x; then \
for file in `cd $(SRCDIR) && find . -type f -name "*.py"`; do \
mkdir -p `dirname $$file`; \
cp "${SRCDIR}$$file" "$$file" || exit 1; \
done; \
fi
for s in $(import_packages_subdirs); do \
(cd $$s && $(MAKE) check) || exit 1; \
done
build:
for s in $(import_packages_subdirs); do \
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build) || exit 1; \
done
static:
for s in $(import_packages_subdirs); do \
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static) || exit 1; \
done
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
if test "x$(SRCDIR)" != x; then \
for file in `cd $(SRCDIR) && find . -type f -name "*.py"`; do \
rm -f "$$file" || exit 1; \
done; \
fi
for s in $(import_packages_subdirs); do \
(cd $$s && $(MAKE) clean) || exit 1; \
done

View File

@@ -0,0 +1,4 @@
These are actually regression tests for SF bug #1297 (GH issue #7).
The namespace_pkg is an example of python3's namespace packages.
See individual READMEs in subdirectories.

View File

@@ -0,0 +1,22 @@
TOP = ../../..
LIBS =
ifeq (,$(PY3))
PKG1DIR = "py2"
else
PKG1DIR = "py3"
endif
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
build:
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build
static:
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd py2 && $(MAKE) clean
cd py3 && $(MAKE) clean

View File

@@ -0,0 +1,63 @@
This example tests the %import directive and python import from __init__.py.
This case is not correctly handled by swig 2.
The issue was reported as Source Forge bug #1297 and later as GitHub issue #7.
Use 'python runme.py' to run a test.
Overview:
---------
The example defines 2 different extension modules--each wrapping a separate C++
class.
pyX/pkg2/foo.i - Pkg2_Foo class
pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg2_Foo
and the package pyX.pkg2 has:
pyX/pkg2/__init__.py - which imports something from "bar" module (we
import Pkg2_Bar class, but it is not the clue,
the clue is the 'from' keyword)
For example with python2.x the py2/pkg2/__init__.py imports Pkg2_Bar class
as follows
from bar import Pkg2_Bar # [1]
Such cases doesn't work when fully qualified python module names are used by
swig (swig 2.0.10, e.g.) to generate python import directives (SF bug #1297).
The generated file "py2/pkg2/bar.py" has following lines:
import py2.pkg2.foo # [2]
class Pkg2_Bar(py2.pkg2.foo.Pkg2_Foo): # [3]
but it's not possible to import anything from py2.pkg2 subpackage, e.g.
import py2.pkg2
fails with the following exception:
Traceback (most recent call last):
File "runme.py", line 3, in <module>
import py2.pkg2
File "py2/pkg2/__init__.py", line 7, in <module>
from .bar import Pkg2_Bar
File "py2/pkg2/bar.py", line 71, in <module>
class Pkg2_Bar(py2.pkg2.foo.Pkg2_Foo):
AttributeError: 'module' object has no attribute 'pkg2'
It seems like during the import [1], the sub-package pkg2 is not yet fully
initialized, so py2.pkg2 is not known. The above exception is raised at
line [3]. The problem disappears, for example, if we force swig to use relative
package names.
If everything works well, the package py2.pkg2 shall load properly.
Unix:
-----
- Run make
- Run the test as described above

View File

@@ -0,0 +1,13 @@
TOP = ../../../..
SWIGOPT =
LIBS =
build:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg2 && $(MAKE) clean

View File

@@ -0,0 +1,25 @@
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
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
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
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static
clean::
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean

View File

@@ -0,0 +1 @@
from bar import Pkg2_Bar

View File

@@ -0,0 +1,5 @@
#ifndef PY2_PKG2_BAR_HPP
#define PY2_PKG2_BAR_HPP
#include "../../py2/pkg2/foo.hpp"
struct Pkg2_Bar : Pkg2_Foo {};
#endif /* PY2_PKG2_BAR_HPP */

View File

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

View File

@@ -0,0 +1,4 @@
#ifndef PY2_PKG2_FOO_HPP
#define PY2_PKG2_FOO_HPP
struct Pkg2_Foo {};
#endif /* PY2_PKG2_FOO_HPP */

View File

@@ -0,0 +1,5 @@
%module(package="py2.pkg2") foo
%{
#include "../../py2/pkg2/foo.hpp"
%}
%include "../../py2/pkg2/foo.hpp"

View File

@@ -0,0 +1,13 @@
TOP = ../../../..
SWIGOPT =
LIBS =
build:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg2 && $(MAKE) clean

View File

@@ -0,0 +1,25 @@
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
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
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
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static
clean::
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean

View File

@@ -0,0 +1 @@
from .bar import Pkg2_Bar

View File

@@ -0,0 +1,5 @@
#ifndef PY3_PKG2_BAR_HPP
#define PY3_PKG2_BAR_HPP
#include "../../py3/pkg2/foo.hpp"
struct Pkg2_Bar : Pkg2_Foo {};
#endif /* PY3_PKG2_BAR_HPP */

View File

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

View File

@@ -0,0 +1,4 @@
#ifndef PY3_PKG2_FOO_HPP
#define PY3_PKG2_FOO_HPP
struct Pkg2_Foo {};
#endif /* PY3_PKG2_FOO_HPP */

View File

@@ -0,0 +1,5 @@
%module(package="py3.pkg2") foo
%{
#include "../../py3/pkg2/foo.hpp"
%}
%include "../../py3/pkg2/foo.hpp"

View File

@@ -0,0 +1,35 @@
import os.path
import subprocess
import sys
def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline)
# Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
if sys.version_info < (2, 5):
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
sys.exit(0)
if sys.version_info < (3, 0):
import py2.pkg2
print " Finished importing py2.pkg2"
commandline = sys.executable + " -m py2.pkg2.bar"
run_except_on_windows(commandline)
commandline = sys.executable + " -m py2.pkg2.foo"
run_except_on_windows(commandline)
else:
import py3.pkg2
print " Finished importing py3.pkg2"
# commandline = sys.executable + " -m py3.pkg2.bar"
# run_except_on_windows(commandline)
# commandline = sys.executable + " -m py3.pkg2.foo"
# run_except_on_windows(commandline)
# TODO: Commented out code above results in (from python-3.6 onwards):
# RuntimeWarning: 'py3.pkg2.bar' found in sys.modules after import of package 'py3.pkg2', but prior to execution of 'py3.pkg2.bar'; this may result in unpredictable behaviour

View File

@@ -0,0 +1,22 @@
TOP = ../../..
LIBS =
ifeq (,$(PY3))
PKG1DIR = "py2"
else
PKG1DIR = "py3"
endif
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
build:
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build
static:
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd py2 && $(MAKE) clean
cd py3 && $(MAKE) clean

View File

@@ -0,0 +1,81 @@
This example tests the %import directive and python import from __init__.py.
This case is not correctly handled by swig 2.
The issue was reported as Source Forge bug #1297 and later as GitHub issue #7.
Use 'python runme.py' to run a test.
Overview:
---------
The example defines 2 different extension modules--each wrapping a separate C++
class.
pyX/pkg2/pkg3/foo.i - Pkg3_Foo class
pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg3_Foo
and the package pyX.pkg2 has:
pyX/pkg2/__init__.py - which imports something from "bar" module
For example with python 2.x the py2/pkg2/__init__.py imports Pkg2_Bar class as
follows
from bar import Pkg2_Bar # [1]
Such cases doesn't work when fully qualified python module names are used by
swig to generate python import directives (SF bug #1297). The generated file
"py2/pkg2/bar.py" has following lines:
import py2.pkg2.pkg3.foo # [2]
class Pkg2_Bar(py2.pkg2.pkg3.foo.Pkg3_Foo): # [3]
and it's not possible to import anything from py2.pkg2 subpackage, e.g.
import py2.pkg2
fails with the following exception:
Traceback (most recent call last):
File "runme.py", line 3, in <module>
import py2.pkg2
File "py2/pkg2/__init__.py", line 4, in <module>
from bar import Pkg2_Bar
File "py2/pkg2/bar.py", line 71, in <module>
class Pkg2_Bar(py2.pkg2.pkg3.foo.Pkg3_Foo):
AttributeError: 'module' object has no attribute 'pkg2'
It seems like during the import [1], the subpackage pkg2 is not yet fully
initialized, so pyX.pkg2 is not known. The above exception is raised at line [3].
The problem disappears, for example, if we force swig to use relative package
names.
The difference between this ('from_init2') case and the case
'from_init1' is that here it's not sufficient to import relative module
by just ignoring the package part of the fully qualified module name. IOW
it is not correct to force swig to put:
import foo
class Pkg2_Bar(foo.Pkg3_Foo)
into pyX/pkg2/bar.py (note, that this would work for 'from_init1' case).
The import directive shall be rather:
import pkg3.foo
for python 2.x and:
from . import pkg3
import pkg3.foo
for python 3, and the class definition shall begin with:
class Pkg2_Bar(pkg3.foo.Pkg3_Foo)
If everything works well, the package pyX.pkg2 shall load properly.
Unix:
-----
- Run make
- Run the test as described above

View File

@@ -0,0 +1,13 @@
TOP = ../../../..
SWIGOPT =
LIBS =
build:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg2 && $(MAKE) clean

View File

@@ -0,0 +1,21 @@
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='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
cd pkg3 && $(MAKE) clean

View File

@@ -0,0 +1 @@
from bar import Pkg2_Bar

View File

@@ -0,0 +1,5 @@
#ifndef PY2_PKG2_BAR_HPP
#define PY2_PKG2_BAR_HPP
#include "../../py2/pkg2/pkg3/foo.hpp"
struct Pkg2_Bar : Pkg3_Foo {};
#endif /* PY2_PKG2_BAR_HPP */

View File

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

View File

@@ -0,0 +1,18 @@
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
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

View File

@@ -0,0 +1,4 @@
#ifndef PY2_PKG2_PKG3_FOO_HPP
#define PY2_PKG2_PKG3_FOO_HPP
struct Pkg3_Foo {};
#endif /* PY2_PKG2_PKG3_FOO_HPP */

View File

@@ -0,0 +1,5 @@
%module(package="py2.pkg2.pkg3") foo
%{
#include "../../../py2/pkg2/pkg3/foo.hpp"
%}
%include "../../../py2/pkg2/pkg3/foo.hpp"

View File

@@ -0,0 +1,13 @@
TOP = ../../../..
SWIGOPT =
LIBS =
build:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg2 && $(MAKE) clean

View File

@@ -0,0 +1,21 @@
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='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
cd pkg3 && $(MAKE) clean

View File

@@ -0,0 +1 @@
from .bar import Pkg2_Bar

View File

@@ -0,0 +1,5 @@
#ifndef PY3_PKG2_BAR_HPP
#define PY3_PKG2_BAR_HPP
#include "../../py3/pkg2/pkg3/foo.hpp"
struct Pkg2_Bar : Pkg3_Foo {};
#endif /* PY3_PKG2_BAR_HPP */

View File

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

View File

@@ -0,0 +1,18 @@
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
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

View File

@@ -0,0 +1,4 @@
#ifndef PY3_PKG2_PKG3_FOO_HPP
#define PY3_PKG2_PKG3_FOO_HPP
struct Pkg3_Foo {};
#endif /* PY3_PKG2_PKG3_FOO_HPP */

View File

@@ -0,0 +1,5 @@
%module(package="py3.pkg2.pkg3") foo
%{
#include "../../../py3/pkg2/pkg3/foo.hpp"
%}
%include "../../../py3/pkg2/pkg3/foo.hpp"

View File

@@ -0,0 +1,31 @@
import os.path
import subprocess
import sys
def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline)
# Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
if sys.version_info < (2, 5):
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
sys.exit(0)
if sys.version_info < (3, 0):
import py2.pkg2
print " Finished importing py2.pkg2"
commandline = sys.executable + " -m py2.pkg2.bar"
run_except_on_windows(commandline)
else:
import py3.pkg2
print " Finished importing py3.pkg2"
# commandline = sys.executable + " -m py3.pkg2.bar"
# run_except_on_windows(commandline)
# TODO: Commented out code above results in (from python-3.6 onwards):
# RuntimeWarning: 'py3.pkg2.bar' found in sys.modules after import of package 'py3.pkg2', but prior to execution of 'py3.pkg2.bar'; this may result in unpredictable behaviour

View File

@@ -0,0 +1,22 @@
TOP = ../../..
LIBS =
ifeq (,$(PY3))
PKG1DIR = "py2"
else
PKG1DIR = "py3"
endif
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
build:
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build
static:
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd py2 && $(MAKE) clean
cd py3 && $(MAKE) clean

View File

@@ -0,0 +1,67 @@
This example tests the %import directive and python import from __init__.py.
This case is not correctly handled by swig 2.
The issue was reported as Source Forge bug #1297 and later as GitHub issue #7.
Use 'python runme.py' to run a test.
Overview:
---------
The example defines 2 different extension modules--each wrapping a separate C++
class.
pyX/pkg2/pkg3/pkg4/foo.i - Pkg4_Foo class
pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg4_Foo
and the package pyX.pkg2 has:
pyX/pkg2/__init__.py - which imports something from "bar" module
For example with python 2.x the py2/pkg2/__init__.py imports Pkg2_Bar class as
follows
from bar import Pkg2_Bar # [1]
Such cases doesn't work when fully qualified python module names are used by
swig to generate python import directives (SF bug 1297). The generated file
"py2/pkg2/bar.py" has following lines:
import py2.pkg2.pkg3.pkg4.foo # [2]
class Pkg2_Bar(py2.pkg2.pkg3.pkg4.foo.P1_S1_S2_Foo): # [3]
and it's not possible to import anything from py2.pkg2 subpackage, e.g.
import py2.pkg2
fails with the following exception:
Traceback (most recent call last):
File "runme.py", line 3, in <module>
import py2.pkg2
File "py2/pkg2/__init__.py", line 4, in <module>
from bar import Pkg2_Bar
File "py2/pkg2/bar.py", line 71, in <module>
class Pkg2_Bar(py2.pkg2.pkg3.pkg4.foo.Pkg4_Foo):
AttributeError: 'module' object has no attribute 'pkg2'
It seems like during the import [1], the subpackage pkg2 is not yet fully
initialized, so py2.pkg2 can't be used. The above exception is raised at
line [3]. The problem disappears, for example, if we force swig to use relative
package names.
The difference between this ('from_init3') case and the case
'from_init2' is that here we import base class from module
pyX.pkg2.pkg3.pkg4.foo, which is nested deeper than it was in
'from_init2'. This is just to ensure, that two (and more) levels of
subpackages get imported correctly by generated python code, i.e, not only
'pkg3.foo' is handled properly (one-level subpackage) but the code works also
for 'pkg3.pkg4.foo', and so on.
If everything works well, the package pyX.pkg2 shall load properly.
Unix:
-----
- Run make
- Run the test as described above

View File

@@ -0,0 +1,13 @@
TOP = ../../../..
SWIGOPT =
LIBS =
build:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg2 && $(MAKE) clean

View File

@@ -0,0 +1,21 @@
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='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
cd pkg3 && $(MAKE) clean

View File

@@ -0,0 +1 @@
from bar import Pkg2_Bar

View File

@@ -0,0 +1,5 @@
#ifndef PY2_PKG2_HPP
#define PY2_PKG2_HPP
#include "../../py2/pkg2/pkg3/pkg4/foo.hpp"
struct Pkg2_Bar : Pkg4_Foo {};
#endif /* PY2_PKG2_HPP */

View File

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

View File

@@ -0,0 +1,13 @@
TOP = ../../../../../..
SWIGOPT =
LIBS =
build:
cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg4 && $(MAKE) clean

View File

@@ -0,0 +1,18 @@
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
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

View File

@@ -0,0 +1,4 @@
#ifndef PY2_PKG2_PKG3_PKG4
#define PY2_PKG2_PKG3_PKG4
struct Pkg4_Foo {};
#endif /* PY2_PKG2_PKG3_PKG4 */

View File

@@ -0,0 +1,5 @@
%module(package="py2.pkg2.pkg3.pkg4") foo
%{
#include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp"
%}
%include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp"

View File

@@ -0,0 +1,13 @@
TOP = ../../../..
SWIGOPT =
LIBS =
build:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg2 && $(MAKE) clean

View File

@@ -0,0 +1,21 @@
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='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
cd pkg3 && $(MAKE) clean

View File

@@ -0,0 +1 @@
from .bar import Pkg2_Bar

View File

@@ -0,0 +1,5 @@
#ifndef PY3_PKG2_HPP
#define PY3_PKG2_HPP
#include "../../py3/pkg2/pkg3/pkg4/foo.hpp"
struct Pkg2_Bar : Pkg4_Foo {};
#endif /* PY3_PKG2_HPP */

View File

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

View File

@@ -0,0 +1,13 @@
TOP = ../../../../../..
SWIGOPT =
LIBS =
build:
cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg4 && $(MAKE) clean

View File

@@ -0,0 +1,18 @@
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
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

View File

@@ -0,0 +1,4 @@
#ifndef PY3_PKG2_PKG3_PKG4
#define PY3_PKG2_PKG3_PKG4
struct Pkg4_Foo {};
#endif /* PY3_PKG2_PKG3_PKG4 */

View File

@@ -0,0 +1,5 @@
%module(package="py3.pkg2.pkg3.pkg4") foo
%{
#include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp"
%}
%include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp"

View File

@@ -0,0 +1,31 @@
import os.path
import subprocess
import sys
def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline)
# Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
if sys.version_info < (2, 5):
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
sys.exit(0)
if sys.version_info < (3, 0):
import py2.pkg2
print " Finished importing py2.pkg2"
commandline = sys.executable + " -m py2.pkg2.bar"
run_except_on_windows(commandline)
else:
import py3.pkg2
print " Finished importing py3.pkg2"
# commandline = sys.executable + " -m py3.pkg2.bar"
# run_except_on_windows(commandline)
# TODO: Commented out code above results in (from python-3.6 onwards):
# RuntimeWarning: 'py3.pkg2.bar' found in sys.modules after import of package 'py3.pkg2', but prior to execution of 'py3.pkg2.bar'; this may result in unpredictable behaviour

View File

@@ -0,0 +1,15 @@
TOP = ../../..
LIBS =
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
build:
cd pkg1 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg1 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg1 && $(MAKE) clean

View File

@@ -0,0 +1,18 @@
This example tests renaming the generated SWIG pure Python module to __init__.py
to turn the module into a Python package.
Use 'python runme.py' to run the test.
Overview:
---------
SWIG generates a pure Python module foo.py from the input interface file foo.i.
The foo.py file is generated within the pkg1 directory and is then renamed __init__.py.
This results in everything in the SWIG generated module being available in the Python
pkg1 package.
This approach of turning the SWIG generated module into a package worked in versions
of SWIG up to swig-3.0.8, but stopped working from swig-3.0.9 until it was
re-instated in swig-4.0.0. However, Python 2.7 or 3.3 and later are needed to
work out of the box. Python 3.2 does not work as this version of Python does
not set __package__ in __init__.py.

View 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

View File

@@ -0,0 +1,10 @@
int foofunction(int i) {
return i *= 10;
}
struct FooClass {
int foomethod(int i) {
return i += 5;
}
};

View File

@@ -0,0 +1,5 @@
%module foo
%{
#include "./foo.hpp"
%}
%include "./foo.hpp"

View File

@@ -0,0 +1,26 @@
import os.path
import sys
# Test import of a SWIG generated module renamed as the package's __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - module renamed as __init__.py"
if sys.version_info >= (3, 0, 0) and sys.version_info < (3, 3, 0):
print " Not importing as Python version is >= 3.0 and < 3.3"
# Package detection does not work in these versions.
# Can be fixed by using this in the interface file:
# %module(moduleimport="from . import $module") foo # without -builtin
# %module(moduleimport="from .$module import *") foo # with -builtin
sys.exit(0)
import pkg1
print " Finished importing pkg1"
if pkg1.foofunction(123) != 1230:
raise RuntimeError("foofunction failed")
fc = pkg1.FooClass()
if fc.foomethod(1) != 6:
raise RuntimeError("foomethod failed")
print " Finished testing pkg1"

View File

@@ -0,0 +1,17 @@
TOP = ../../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
TARGET = robin
INTERFACE = robin.i
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
rm -rf path1 path2 path3 path4.zip

View File

@@ -0,0 +1,25 @@
This is an example (and test) of using swig generated modules in the context
of python3's namespace packages:
https://www.python.org/dev/peps/pep-0420/
Consequently, this example requires python (3.3 or newer) to build and run.
This example creates a simple swig module named robin. The robin.py module
has a companion C module named _robin.so. The robin module is tested in four
ways:
1) As a non-package module (tested by nonpkg.py)
2) With robin.py and _robin.so in the brave package under the path1
subdirectory. (tested by normal.py)
3) With robin.py in path2/brave and _robin.so in path3/brave
(tested by split.py)
4) With robin.py contained in a zip file (path4.zip) as brave/robin.py and
_robin.so found on the filesystem under path3/brave (tested by zipsplit.py)
Note: Using namespace packages with subpackages (such as brave.sir.robin) where
robin.py is located in a zipfile requires python-3.5.1 or newer as
python's zipimporter only worked with packages of depth 1 until then.

View File

@@ -0,0 +1,22 @@
import os
import subprocess
import sys
def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline)
print(" Starting subtest " + os.path.basename(__file__))
# import robin as a module in the global namespace
import robin
print(" Finished importing robin")
if not(robin.run() == "AWAY!"):
raise RuntimeError("test failed")
commandline = sys.executable + " -m robin"
run_except_on_windows(commandline)

View File

@@ -0,0 +1,23 @@
import os
import subprocess
import sys
def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline)
print(" Starting subtest " + os.path.basename(__file__))
# Package brave found under one path
sys.path.insert(0, 'path1')
from brave import robin
print(" Finished from brave import robin")
if not(robin.run() == "AWAY!"):
raise RuntimeError("test failed")
commandline = sys.executable + " -m brave.robin"
run_except_on_windows(commandline, env = {"PYTHONPATH": "path1"})

View File

@@ -0,0 +1,51 @@
import sys
import os
import shutil
import subprocess
import zipfile
def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline)
def copyMods():
dirs = ['path1', 'path2', 'path3']
# Clean out any old package paths
for d in dirs:
if os.path.isdir(d):
shutil.rmtree(d)
for d in dirs:
os.mkdir(d)
os.mkdir(os.path.join(d, 'brave'))
shutil.copy('robin.py', os.path.join('path1', 'brave'))
subprocess.check_call('cp _robin.* ' + os.path.join('path1', 'brave'), shell=True)
shutil.copy('robin.py', os.path.join('path2', 'brave'))
subprocess.check_call('cp _robin.* ' + os.path.join('path3', 'brave'), shell=True)
mkzip()
def mkzip():
zf = zipfile.ZipFile("path4.zip", "w")
zf.writestr("brave/", b'')
zf.write('robin.py', 'brave/robin.py')
zf.close()
def main():
copyMods()
# Run each test with a separate interpreter
run_except_on_windows(sys.executable + " nonpkg.py")
run_except_on_windows(sys.executable + " normal.py")
run_except_on_windows(sys.executable + " split.py")
run_except_on_windows(sys.executable + " zipsplit.py")
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,7 @@
%module robin
%inline %{
const char *run(void) {
return "AWAY!";
}
%}

View File

@@ -0,0 +1,18 @@
# These examples rely on namespace packages. Don't
# run them for old python interpreters.
import os.path
import subprocess
import sys
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - namespace packages"
if sys.version_info < (3, 3, 0):
print " Not importing nstest as Python version is < 3.3"
sys.exit(0)
import nstest
print " Finished importing nstest"
nstest.main()

View File

@@ -0,0 +1,25 @@
import os
import subprocess
import sys
def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline)
print(" Starting subtest " + os.path.basename(__file__))
# Package brave split into two paths.
# path2/brave/robin.py and path3/brave/_robin.so
sys.path.insert(0, 'path2')
sys.path.insert(0, 'path3')
from brave import robin
print(" Finished from brave import robin")
if not(robin.run() == "AWAY!"):
raise RuntimeError("test failed")
commandline = sys.executable + " -m brave.robin"
run_except_on_windows(commandline , env = {"PYTHONPATH": "path2:path3"})

View File

@@ -0,0 +1,25 @@
import os
import subprocess
import sys
def run_except_on_windows(commandline, env=None):
if os.name != "nt" and sys.platform != "cygwin":
# Strange failures on windows/cygin/mingw
subprocess.check_call(commandline, env=env, shell=True)
print(" Finished running: " + commandline)
print(" Starting subtest " + os.path.basename(__file__))
# Package brave split into two paths.
# brave/robin.py (in path4.zip) and path3/brave/_robin.so
sys.path.insert(0, 'path4.zip')
sys.path.insert(0, 'path3')
from brave import robin
print(" Finished from brave import robin")
if not(robin.run() == "AWAY!"):
raise RuntimeError("test failed")
commandline = sys.executable + " -m brave.robin"
run_except_on_windows(commandline, env = {"PYTHONPATH": "path3:path4.zip"})

View File

@@ -0,0 +1,22 @@
TOP = ../../..
LIBS =
ifeq (,$(PY3))
PKG1DIR = "py2"
else
PKG1DIR = "py3"
endif
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
build:
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build
static:
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd py2 && $(MAKE) clean
cd py3 && $(MAKE) clean

View File

@@ -0,0 +1,22 @@
This example tests the %import directive and -relativeimport swig option.
Use 'python runme.py' to run a test.
Overview:
---------
The example defines 2 different extension modules--each wrapping a separate C++
class.
pyX/pkg2/pkg3/foo.i - Pkg3_Foo class
pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg3_Foo
The code is processed by swig with -relativeimport flag. The runtime test
imports pyX.pkg2.bar module.
If everything works well, the module pyX.pkg2.bar shall load properly.
Unix:
-----
- Run make
- Run the test as described above

View File

@@ -0,0 +1,13 @@
TOP = ../../../..
SWIGOPT =
LIBS =
build:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg2 && $(MAKE) clean

View File

@@ -0,0 +1,21 @@
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='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
cd pkg3 && $(MAKE) clean

View File

@@ -0,0 +1,5 @@
#ifndef PY2_PKG2_BAR_HPP
#define PY2_PKG2_BAR_HPP
#include "../../py2/pkg2/pkg3/foo.hpp"
struct Pkg2_Bar : Pkg3_Foo {};
#endif /* PY2_PKG2_BAR_HPP */

View File

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

View File

@@ -0,0 +1,18 @@
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
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

View File

@@ -0,0 +1,4 @@
#ifndef PY2_PKG2_PKG3_FOO_HPP
#define PY2_PKG2_PKG3_FOO_HPP
struct Pkg3_Foo {};
#endif /* PY2_PKG2_PKG3_FOO_HPP */

View File

@@ -0,0 +1,5 @@
%module(package="py2.pkg2.pkg3") foo
%{
#include "../../../py2/pkg2/pkg3/foo.hpp"
%}
%include "../../../py2/pkg2/pkg3/foo.hpp"

View File

@@ -0,0 +1,13 @@
TOP = ../../../..
SWIGOPT =
LIBS =
build:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg2 && $(MAKE) clean

Some files were not shown because too many files have changed in this diff Show More