Re: [Distutils] Re: [PSA MEMBERS] packages in Python
I think in this case the only problem is getting all the right directories on the package's __path__; am I missing something? It avoids the need for the "conditional" import, but that's largely separate.
Fred, Good point. Can you recommend a concise place that the import mechanism (in all it's glory) is documented? That should solve the problem, except for when freeze-ing or making a static python binary (as previously mentioned by Konrad). I was poking around in ihooks.py. It looks like it should be possible to cook up something approximating this using ihooks. What do you think? -Perry
Perry A. Stoll writes:
Good point. Can you recommend a concise place that the import mechanism (in all it's glory) is documented?
Documentation? Ha! I don't have no stinkin' documentation! ;-) I think going over Python/import.c is the best bet. There's an import_package() function (I think that's the name); probably the best bet is to modify that to build the right __path__ value; at this point we know it's a package, so we're not interfering with the performance of importing non-packages, only the package/subpackages themselves.
That should solve the problem, except for when freeze-ing or making a static python binary (as previously mentioned by Konrad).
I don't know enough about freezing, but I suspect that's not too difficult; probably about the same as staticly linked package-ized modules. ;-) I don't think those will actually be that difficult for someone that has time to read the code; the only real problem is the public symbol for the module init function.
I was poking around in ihooks.py. It looks like it should be possible to cook up something approximating this using ihooks. What do you think?
That can probably be done, but places the import machinery in Python rather than in C, so it'll be slow. -Fred -- Fred L. Drake, Jr. <fdrake@acm.org> Corporation for National Research Initiatives
participants (2)
-
Fred L. Drake
-
Perry A. Stoll