Discussion:
[Swig-devel] swig + python3 + relative imports = fail
m***@comcast.net
2016-04-04 17:30:01 UTC
Permalink
I've been working on my patch to fix swig for implicit namespace
packages (https://github.com/swig/swig/pull/612). I now think I
understand the swig test suite a bit better and can reproduce the
failures of the travisci builds on my local machine.

In a nutshell, swig is generating this code inside the shadow class
of a module contained in a package:

...
del version_info
from _foo import *
try:
_swig_property = property
except NameError:
...

The 'from _foo import *' line is not compatible with python3 as it
uses a relative import (which are gone in py3). For python3 this
needs to be 'from ._foo import *' or 'from package._foo import *'.

Does anyone happen to know the approximate location in the swig code
where this 'from _foo import *' line is being generated? I'm going to
start my search in python.cxx. But any tips would be appreciated.

Thanks,

Mike

P.S. I rebased my git branch to see stuff in the swig tree. I fear
I've worked the git incantation in a non-ideal way. I'll cancel and
re-submit a pull request after the travisci builds are clean.

------------------------------------------------------------------------------
Paweł Tomulik
2016-04-04 18:47:38 UTC
Permalink
Hi,
Post by m***@comcast.net
I've been working on my patch to fix swig for implicit namespace
packages (https://github.com/swig/swig/pull/612). I now think I
understand the swig test suite a bit better and can reproduce the
failures of the travisci builds on my local machine.
In a nutshell, swig is generating this code inside the shadow class
...
del version_info
from _foo import *
_swig_property = property
...
The 'from _foo import *' line is not compatible with python3 as it
uses a relative import (which are gone in py3). For python3 this
needs to be 'from ._foo import *' or 'from package._foo import *'.
Does anyone happen to know the approximate location in the swig code
where this 'from _foo import *' line is being generated? I'm going to
start my search in python.cxx. But any tips would be appreciated.
If this comes from the original SWIG code (master), then I'd suspect
this fragment below line 854:

https://github.com/swig/swig/blob/master/Source/Modules/python.cxx#L854
Post by m***@comcast.net
Thanks,
Mike
P.S. I rebased my git branch to see stuff in the swig tree. I fear
I've worked the git incantation in a non-ideal way. I'll cancel and
re-submit a pull request after the travisci builds are clean.
------------------------------------------------------------------------------
_______________________________________________
Swig-devel mailing list
https://lists.sourceforge.net/lists/listinfo/swig-devel
--
Pawel Tomulik

------------------------------------------------------------------------------
Loading...