#1378 Package information is not propagated when importing

None
closed
nobody
5
2014-10-10
2014-08-04
Johan Hake
No

The -relativeimport option works when a using the import directive as documented:

%import (package="pkg1.pkg2") "mod3.i"

However, if a user use the single file import:

%import (module="pkg1.pkg2.mod3") "Foo.h";

relative import directive has no effect. See simple attached example to reproduce the error.

I traced the bug down to the function importDirective in python.cxx.

Here module name of the incoming node is "mod3" for the correct example and "pkg1.pkg2.mod3" for the not working example. For the correct example the option "package" is also provided.

Not sure how it should be fixed. Either just keep the present syntax and try to manually split "pkg1.pkg2.mod3" in the importDirective function into package = "pkg1.pkg2" and module = "mod3", or extend the present import directive syntax with:

%import (package="pkg1.pkg2", module="mod3") "Foo.h";

I would prefer the latter as it is more explicit. Atm the package information is just discarded as the parser create a new module node, which does not get the option propagated to it. I attach a online patch that propagate the option child to the newly create module node in the parse tree. I can barely read yacc and barely write swig parser code, so please check that what I am doing this correct.

2 Attachments

Discussion

  • Johan Hake

    Johan Hake - 2014-08-04

    The attached bug tarball was not complete. Attached is an updated example.

     
    Last edit: Johan Hake 2014-08-04
  • William Fulton

    William Fulton - 2014-08-11

    Johan, could you please put this bug and patch into github - https://github.com/swig/swig ? It will make it a lot easier to collaborate on it. Please also ping @ptomulik in the Github patch as he contributed -relativeimport option and is best placed to review the patch. Sorry about this extra work.

     
  • William Fulton

    William Fulton - 2014-08-11

    Could you also either modify one of the test cases under Examples/python/import_packages with your example demonstrating the bug, or add another like those in that directory. Thanks.

     
  • Johan Hake

    Johan Hake - 2014-08-12

    I have now created an issue #207 together with a pull request.

    https://github.com/swig/swig/pull/207

    with an added Example (test), and a fix exposing the bug. It is tested for py2 but not py3 as I do not have such an environment, but it "should just work".

    I implemented the fix in a separate branch, which could be merged with master. I was not sure of the git work flow in swig, but this is how we do it in a couple of other projects.

     
  • William Fulton

    William Fulton - 2014-10-10
    • status: open --> closed
    • Group: -->
     
  • William Fulton

    William Fulton - 2014-10-10

    Merged to master, see Github pull request.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks