/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/lazy_import.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-12 19:07:27 UTC
  • mto: This revision was merged to the branch mainline in revision 2004.
  • Revision ID: john@arbash-meinel.com-20060912190727-35ae1dff7a95b789
Write a simple wrapper function to make lazy imports easy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
190
190
        else:
191
191
            self._lazy_import_class = lazy_import_class
192
192
 
193
 
    def lazy_import(self, text, scope):
 
193
    def lazy_import(self, scope, text):
194
194
        """Convert the given text into a bunch of lazy import objects.
195
195
 
196
196
        This takes a text string, which should be similar to normal python
324
324
        if cur is not None:
325
325
            raise errors.InvalidImportLine(cur, 'Unmatched parenthesis')
326
326
        return out
 
327
 
 
328
 
 
329
def lazy_import(scope, text, lazy_import_class=None):
 
330
    """Create lazy imports for all of the imports in text.
 
331
 
 
332
    This is typically used as something like:
 
333
    from bzrlib.lazy_import import lazy_import
 
334
    lazy_import(globals(), '''
 
335
    from bzrlib import (
 
336
        foo,
 
337
        bar,
 
338
        baz,
 
339
        )
 
340
    import bzrlib.branch
 
341
    import bzrlib.transport
 
342
    ''')
 
343
 
 
344
    Then 'foo, bar, baz' and 'bzrlib' will exist as lazy-loaded
 
345
    objects which will be replaced with a real object on first use.
 
346
 
 
347
    In general, it is best to only load modules in this way. This is
 
348
    because other objects (functions/classes/variables) are frequently
 
349
    used without accessing a member, which means we cannot tell they
 
350
    have been used.
 
351
    """
 
352
    # This is just a helper around ImportProcessor.lazy_import
 
353
    proc = ImportProcessor(lazy_import_class=lazy_import_class)
 
354
    return proc.lazy_import(scope, text)