zeek / pysubnettree

A Python Module for CIDR Lookups
Other
51 stars 20 forks source link

Swig 4 issue #29

Closed kitterma closed 2 years ago

kitterma commented 2 years ago

In Debian we switched from swig 3 to swig 4 and it did not go well. The specific error we get after SubnetTree_wrap.cc is regenerated with swig 4 is:

import SubnetTree t = SubnetTree.SubnetTree() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3/dist-packages/SubnetTree.py", line 82, in init _SubnetTree.SubnetTree_swiginit(self, _SubnetTree.new_SubnetTree(binary_lookup_mode)) AttributeError: module '_SubnetTree' has no attribute 'SubnetTree_swiginit'

Any suggestions you might have on how to get this working with swig 4 would be greatly appreciated.

kitterma commented 2 years ago

Would be nice to get some feedback on this.

awelzel commented 2 years ago

Would be nice to get some feedback on this.

Is this still an issue?

I'm on Debian bullseye and and fetched the dsc file and modified debian/rules as follows to regenerate the files during the build with swig-4.0 which seems to fail upstream (?).

--- ../../rules.orig    2022-11-02 18:01:34.534631156 +0100
+++ debian/rules        2022-11-02 18:01:36.850632392 +0100
@@ -7,9 +7,9 @@
        dh $@ --with python3

 override_dh_auto_build:
-       mv $(CURDIR)/SubnetTree_wrap.cc $(CURDIR)/not.SubnetTree_wrap.cc
+       # mv $(CURDIR)/SubnetTree_wrap.cc $(CURDIR)/not.SubnetTree_wrap.cc
        dh_auto_build
-       mv $(CURDIR)/not.SubnetTree_wrap.cc $(CURDIR)/SubnetTree_wrap.cc
+       # mv $(CURDIR)/not.SubnetTree_wrap.cc $(CURDIR)/SubnetTree_wrap.cc

 override_dh_auto_install:
        dh_install -ppython3-subnettree
@@ -19,8 +19,8 @@

 override_dh_clean:
        dh_clean
-       -cp -f $(CURDIR)/not.SubnetTree_wrap.cc $(CURDIR)/SubnetTree_wrap.cc
-       rm -f $(CURDIR)/not.SubnetTree_wrap.cc
+       # -cp -f $(CURDIR)/not.SubnetTree_wrap.cc $(CURDIR)/SubnetTree_wrap.cc
+       # rm -f $(CURDIR)/not.SubnetTree_wrap.cc
        rm -rf $(CURDIR)/build

 override_dh_auto_test:

shell returned 1

And then built with as follows to ignore complaints about regeneration of those files (I'm sure you know better how to fix that cleanly):

pysubnettree-0.35$ dpkg-buildpackage -us -uc --diff-ignore='SubnetTree_wrap.cc|SubnetTree.py'

Installing the .deb package and smoke testing things seem to be okay:

$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import SubnetTree; t = SubnetTree.SubnetTree(); t["192.168.0.0/16"] = "Network 1"; t["192.168.0.1"]; print(SubnetTree)
'Network 1'
<module 'SubnetTree' from '/usr/lib/python3/dist-packages/SubnetTree.py'>

Am I missing something here?

kitterma commented 2 years ago

By not moving the existing SubnetTree_wrap.cc out of the way before the build, doesn't your change lead to the file not being rebuilt?

awelzel commented 2 years ago

By not moving the existing SubnetTree_wrap.cc out of the way before the build, doesn't your change lead to the file not being rebuilt?

Hmm, nope, I had checked. However, looking again that's actually a bug in the Makefile using SubnetTree_wrap.cpp as target, but then producing SubnetTree_wrap.cc.

That's a separate problem though. Can you check if you can reproduce the debian issue still?

kitterma commented 2 years ago

I can still reproduce it, but I think that was enough of a clue for me to make progress. I tried the changes you suggested above and still got a non-working package. Then I added a manual invocation of swig right before dh_auto_build with the change you make in the Makefile:

swig -c++ -python -Iinclude -o SubnetTree_wrap.cc SubnetTree.i

And that produced a working module. I think (it's early here and I'm pre-coffee). Assuming I'm not dreaming, that's probably enough for me to sort out the rest as a Debian packaging issue. I'll let you know, but it'll be awhile because my day is already pretty fully committed.

Thanks.

kitterma commented 2 years ago

I see the issue now. Downstream (Debian) issue. I'll close the issue. Thanks for the help.