Issue #15 resolved

How to veto an import?

david_cortesi
created an issue

I am investigating using MG in pyinstaller. One function it provides now is for a module "hook" file to veto an import. Specific case, module pydoc imports Tkinter, which should not happen unless the main program also imports Tkinter. So the pydoc hook looks for Tkinter in the import list of module pydoc and deletes it. There are other cases like this.

I am looking for the equivalent ability with MG. I think it might be, to find the pydoc node by name, and find the Tkinter node by name, and then use altgraph.ObjectGraph.removeReference(fromnode, tonode) on those nodes. Would that delete the Tkinter node if it had no other from-links, but retain it if it did?

In general, should I feel comfortable about dropping down to the ObjectGraph level of function with MG? Or should I request that something like this be surfaced as a member of MG directly?

Comments (3)

  1. david_cortesi reporter

    So it is approximately what I said,

    for ref in refs:
            mf.removeReference(m, ref)
    

    A surprise to me is that in this code, "ref" is a string. The altgraph doc page says "altgraph.ObjectGraph.removeReference(fromnode, tonode)" -- it appears to want a node at both places. So removeReference will accept an ident-string in place of a node? That is not obvious even in the altGraph code...?

  2. Log in to comment