From ac7157dfc620471cee3376cfc3f8312dff48d32c Mon Sep 17 00:00:00 2001
From: Mike Romberg By default, SWIG would generate mod2.py proxy file with
import directive as in point 1. This can be changed with the
-relativeimport command line option. The -relativeimport instructs
-SWIG to organize imports as in point 2 (for Python 2.x) or as in point 4 (for
-Python 3, that is when the -py3 command line option is enabled). In short, if you have
+SWIG to organize imports as in point 2 (for Python < 2.7.0) or as in point 4
+for Python 2.7.0 and newer. This is a check done at the time the module is
+imported. In short, if you have
mod2.i and mod3.i as above, then without
-relativeimport SWIG will write
-import pkg2.mod3 ++import sys +if sys.version_info >= (2, 7, 0): + from . import pkg2 + import pkg1.pkg2.mod3 +else: + import pkg2.mod3
if -py3 is not used, or
- --from . import pkg2 -import pkg1.pkg2.mod3 --
when -py3 is used.
-You should avoid using relative imports and use absolute ones whenever possible. There are some cases, however, when relative imports may be necessary. The first example is, when some (legacy) Python code refers entities