1. Ronald Oussoren
  2. modulegraph
  3. Issues
Issue #12 resolved

__init__.py of a module is not found.

created an issue

For some reason, when modulegraph is looking for init (modulegraph.ModuleGraph.load_package) it may end up with absolutely wrong init.py file in another directory.

Comments (20)

  1. Kentzo reporter

    The problem only appears if: 1. One of modules imports init 2. Graph builder walks the dependency tree so that init is added to notes before a package

  2. Ronald Oussoren repo owner

    Can you reproduce this problem with a small test project (similar to the other test projects in modulegraph_tests)?

    I'd prefer to have a unittest for this because changing the code to ensure that this bug doesn't reappear in the future. Especially because the graph creation code is fairly smelly and needs to be refactored some time in the future.

    (In the long run I'd like to rewrite the graph creation code using importlib, with a compatibility shim for python versions <= 3.2)

  3. Kentzo reporter

    I'll try to make it reproducable. Unfortunately the project I'm working on is very big. The challenging part is to create structure so that init is added before any other package.

  4. Ronald Oussoren repo owner

    I won't apply the patch unless I understand what's going on, and preferably with a testcase that reproduces the problem.

    Looking at the mercurial history wasn't helpful, the lines you remove in the patch were in the initial import.

  5. Ronald Oussoren repo owner

    It was in the initial check-in in the old modulegraph svn repository as well.

    This makes it slightly harder to know why these lines were added in the first place.

  6. Kentzo reporter

    oh, okay. It's very important to me, since I want to make building of my app as easy as possible.

    Let me know if I can somehow speedup and help you with fix.

  7. Ronald Oussoren repo owner

    I can reproduce the issue with your example, but haven't had time yet to properly debug. It is pretty odd that a completely unrelated import affects the import of distutils later on in the script.

    When I apply your patch one of the tests fails, but that's a test that was written long after the code and just verifies that the import-error gets raised. Disabling the test wouldn't be a problem.

    More importantly, the patch appears to break the py2app test suite. I'll need some more time to investigate what's going on there, with some luck I'll manage to so so tonight.

  8. Ronald Oussoren repo owner

    Could you test 'modulegraph-issue12.patch' that I just attached?

    This fixes the issue with the TestModuleGraph.zip script you posted earlier.

    This appears to be a rather lame issue: When looking for the package __init__ the code actually looked for any __init__ module on the search path (the package path plus sys.path), instead of looking for "package.__init__". The patch should fix that.

  9. Ronald Oussoren repo owner

    I've applied my patch in changeset e1eaf960729e in the 0.10 branch (and merged into default in changeset b8d9bdbd7c59).

    If this actually fixes the problem you have with the "real" program I'll push out a new version of modulegraph (as well as py2app, that has a number of bugfixes in the stable branch that need to get released)

  10. Log in to comment