Merge branch 'master' into C
This commit is contained in:
commit
f919896306
209 changed files with 3791 additions and 2243 deletions
|
|
@ -10,11 +10,15 @@ import_packages_subdirs = \
|
|||
from_init3 \
|
||||
relativeimport1 \
|
||||
relativeimport2 \
|
||||
relativeimport3
|
||||
relativeimport3 \
|
||||
split_modules \
|
||||
namespace_pkg
|
||||
|
||||
|
||||
check: build
|
||||
if test "x$(SRCDIR)" != x; then \
|
||||
for file in `cd $(SRCDIR) && find . -type f -name __init__.py`; do \
|
||||
for file in `cd $(SRCDIR) && find . -type f -name "*.py"`; do \
|
||||
mkdir -p `dirname $$file`; \
|
||||
cp "${SRCDIR}$$file" "$$file" || exit 1; \
|
||||
done; \
|
||||
fi; \
|
||||
|
|
@ -35,7 +39,7 @@ static:
|
|||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
if test "x$(SRCDIR)" != x; then \
|
||||
for file in `cd $(SRCDIR) && find . -type f -name __init__.py`; do \
|
||||
for file in `cd $(SRCDIR) && find . -type f -name "*.py"`; do \
|
||||
rm -f "$$file" || exit 1; \
|
||||
done; \
|
||||
fi; \
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
These are actually regression tests for SF bug #1297 (GH issue #7).
|
||||
See individual READMEs in subdirectories.
|
||||
The namespace_pkg is an example of python3's namespace packages.
|
||||
|
||||
See individual READMEs in subdirectories.
|
||||
17
Examples/python/import_packages/namespace_pkg/Makefile
Normal file
17
Examples/python/import_packages/namespace_pkg/Makefile
Normal 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
|
||||
25
Examples/python/import_packages/namespace_pkg/README
Normal file
25
Examples/python/import_packages/namespace_pkg/README
Normal 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.
|
||||
5
Examples/python/import_packages/namespace_pkg/nonpkg.py
Normal file
5
Examples/python/import_packages/namespace_pkg/nonpkg.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# import robin as a module in the global namespace
|
||||
|
||||
import robin
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
7
Examples/python/import_packages/namespace_pkg/normal.py
Normal file
7
Examples/python/import_packages/namespace_pkg/normal.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import sys
|
||||
# Package brave found under one path
|
||||
sys.path.insert(0, 'path1')
|
||||
|
||||
from brave import robin
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
45
Examples/python/import_packages/namespace_pkg/nstest.py
Normal file
45
Examples/python/import_packages/namespace_pkg/nstest.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import sys
|
||||
import os
|
||||
import shutil
|
||||
import zipfile
|
||||
|
||||
|
||||
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'))
|
||||
os.system('cp _robin.* ' + os.path.join('path1', 'brave'))
|
||||
|
||||
shutil.copy('robin.py', os.path.join('path2', 'brave'))
|
||||
os.system('cp _robin.* ' + os.path.join('path3', 'brave'))
|
||||
|
||||
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
|
||||
os.system(sys.executable + " nonpkg.py")
|
||||
os.system(sys.executable + " normal.py")
|
||||
os.system(sys.executable + " split.py")
|
||||
os.system(sys.executable + " zipsplit.py")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
7
Examples/python/import_packages/namespace_pkg/robin.i
Normal file
7
Examples/python/import_packages/namespace_pkg/robin.i
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
%module robin
|
||||
|
||||
%inline %{
|
||||
const char *run(void) {
|
||||
return "AWAY!";
|
||||
}
|
||||
%}
|
||||
17
Examples/python/import_packages/namespace_pkg/runme.py
Normal file
17
Examples/python/import_packages/namespace_pkg/runme.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# These examples rely on namespace packages. Don't
|
||||
# run them for old python interpreters.
|
||||
import sys
|
||||
import os.path
|
||||
|
||||
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()
|
||||
9
Examples/python/import_packages/namespace_pkg/split.py
Normal file
9
Examples/python/import_packages/namespace_pkg/split.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import sys
|
||||
# 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
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import sys
|
||||
# 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
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
26
Examples/python/import_packages/split_modules/Makefile
Normal file
26
Examples/python/import_packages/split_modules/Makefile
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
TOP = ../../..
|
||||
LIBS =
|
||||
|
||||
subdirs = vanilla vanilla_split
|
||||
|
||||
|
||||
check: build
|
||||
for s in $(subdirs); do \
|
||||
(cd $$s && $(MAKE) check); \
|
||||
done
|
||||
|
||||
build:
|
||||
for s in $(subdirs); do \
|
||||
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build); \
|
||||
done
|
||||
|
||||
static:
|
||||
for s in $(subdirs); do \
|
||||
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static); \
|
||||
done
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
for s in $(subdirs); do \
|
||||
(cd $$s && $(MAKE) clean); \
|
||||
done
|
||||
7
Examples/python/import_packages/split_modules/README
Normal file
7
Examples/python/import_packages/split_modules/README
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
These examples/tests are for when the SWIG generated wrapper module is split
|
||||
between two packages. Specifically the pure python part is part of a package
|
||||
and the C/C++ part is not in any package at all. Historically SWIG has
|
||||
supported this sort of thing.
|
||||
|
||||
vanilla # "plane Jane" module both halves in pkg1
|
||||
vanilla_split # python 1/2 in pkg1 C 1/2 in global namespace
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
TOP = ../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
cd pkg1 && $(MAKE) build
|
||||
|
||||
static:
|
||||
cd pkg1 && $(MAKE) static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
cd pkg1 && $(MAKE) -f $(TOP)/../Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1 @@
|
|||
# killroy was here
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
%module(package="pkg1") foo
|
||||
%{
|
||||
static unsigned count(void)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
%}
|
||||
|
||||
unsigned count(void);
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import os.path
|
||||
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - split modules"
|
||||
|
||||
import pkg1.foo
|
||||
|
||||
print " Finished importing pkg1.foo"
|
||||
|
||||
assert(pkg1.foo.count() == 3)
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
TOP = ../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT = -outdir pkg1
|
||||
LIBS =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
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
|
||||
cd pkg1 && $(MAKE) -f $(TOP)/../Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
%module(package="pkg1") foo
|
||||
%{
|
||||
static unsigned count(void)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
%}
|
||||
|
||||
unsigned count(void);
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
# killroy was here
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import os.path
|
||||
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - split modules"
|
||||
|
||||
import pkg1.foo
|
||||
|
||||
print " Finished importing pkg1.foo"
|
||||
|
||||
assert(pkg1.foo.count() == 3)
|
||||
Loading…
Add table
Add a link
Reference in a new issue