[Import-sig] freezing (was: Long-awaited imputil comments)

Greg Stein gstein@lyra.org
Wed, 16 Feb 2000 15:05:11 -0800 (PST)

On Wed, 16 Feb 2000, Gordon McMillan wrote:
> [Greg]
> > You're asking for something that is impossible in practice. Consider the
> > following code fragment:
> > 
> > ------------------------
> > import my_imp_tools
> > my_imp_tools.HTTPImporter("http://www.lyra.org/greg/python/")
> > 
> > import qp_xml
> > ------------------------
> > 
> > There is no way that you can create a freeze tool that will be able to
> > manage this kind of scenario.
> Sure. Dynamically replace the Importer in __bases__ with a 
> hacked one that doesn't affect sys.modules, grabs the code 
> object and analyzes byte code (like modulefinder does) to find 
> further imports.

The HTTPImporter is parameterized -- analyzing bytecode or a parse tree
won't discover those parameter values (without a lot of work).

You'd have to run the code to get the Importers instantiated and
installed, but then you could have a problem with code that is executing
outside of a classdef or funcdef.

Guido suggested a custom ImportManager, but that would run into the same
kind of problem.

Effectively, I think what needs to happen is that the freeze tool
understands Importer classes. The configuration input to the tool would
specify how to set up the Importers, which the tool would directly query.
In other words... it would still be a pretty custom approach *if* the
application uses any custom import stuff.


Greg Stein, http://www.lyra.org/