/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 breezy/lazy_import.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 19:09:26 UTC
  • mfrom: (6622.1.36 breezy)
  • Revision ID: jelmer@jelmer.uk-20170521190926-5vtz8xaf0e9ylrpc
Merge rename to breezy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
Most commonly, the 'lazy_import' function is used to import other modules
22
22
in an on-demand fashion. Typically use looks like::
23
23
 
24
 
    from bzrlib.lazy_import import lazy_import
 
24
    from breezy.lazy_import import lazy_import
25
25
    lazy_import(globals(), '''
26
 
    from bzrlib import (
 
26
    from breezy import (
27
27
        errors,
28
28
        osutils,
29
29
        branch,
30
30
        )
31
 
    import bzrlib.branch
 
31
    import breezy.branch
32
32
    ''')
33
33
 
34
 
Then 'errors, osutils, branch' and 'bzrlib' will exist as lazy-loaded
 
34
Then 'errors, osutils, branch' and 'breezy' will exist as lazy-loaded
35
35
objects which will be replaced with a real object on first use.
36
36
 
37
37
In general, it is best to only load modules in this way. This is because
154
154
        :param scope: The scope that objects should be imported into.
155
155
            Typically this is globals()
156
156
        :param name: The variable name. Often this is the same as the
157
 
            module_path. 'bzrlib'
 
157
            module_path. 'breezy'
158
158
        :param module_path: A list for the fully specified module path
159
 
            ['bzrlib', 'foo', 'bar']
 
159
            ['breezy', 'foo', 'bar']
160
160
        :param member: The member inside the module to import, often this is
161
161
            None, indicating the module is being imported.
162
162
        :param children: Children entries to be imported later.
163
163
            This should be a map of children specifications.
164
164
            ::
165
165
            
166
 
                {'foo':(['bzrlib', 'foo'], None,
167
 
                    {'bar':(['bzrlib', 'foo', 'bar'], None {})})
 
166
                {'foo':(['breezy', 'foo'], None,
 
167
                    {'bar':(['breezy', 'foo', 'bar'], None {})})
168
168
                }
169
169
 
170
170
        Examples::
377
377
 
378
378
    This is typically used as something like::
379
379
 
380
 
        from bzrlib.lazy_import import lazy_import
 
380
        from breezy.lazy_import import lazy_import
381
381
        lazy_import(globals(), '''
382
 
        from bzrlib import (
 
382
        from breezy import (
383
383
            foo,
384
384
            bar,
385
385
            baz,
386
386
            )
387
 
        import bzrlib.branch
388
 
        import bzrlib.transport
 
387
        import breezy.branch
 
388
        import breezy.transport
389
389
        ''')
390
390
 
391
 
    Then 'foo, bar, baz' and 'bzrlib' will exist as lazy-loaded
 
391
    Then 'foo, bar, baz' and 'breezy' will exist as lazy-loaded
392
392
    objects which will be replaced with a real object on first use.
393
393
 
394
394
    In general, it is best to only load modules in this way. This is
401
401
    return proc.lazy_import(scope, text)
402
402
 
403
403
 
404
 
# The only module that this module depends on is 'bzrlib.errors'. But it
 
404
# The only module that this module depends on is 'breezy.errors'. But it
405
405
# can actually be imported lazily, since we only need it if there is a
406
406
# problem.
407
407
 
408
408
lazy_import(globals(), """
409
 
from bzrlib import errors
 
409
from breezy import errors
410
410
""")