~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to HACKING

  • Committer: Alexander Belchenko
  • Date: 2006-07-31 16:12:57 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060731161257-91a231523255332c
new official bzr.ico

Show diffs side-by-side

added added

removed removed

Lines of Context:
209
209
> factory, then yes, foo_factory is what I would use.
210
210
 
211
211
 
212
 
Lazy Imports
213
 
------------
214
 
 
215
 
To make startup time faster, we use the ``bzrlib.lazy_import`` module to
216
 
delay importing modules until they are actually used. ``lazy_import`` uses
217
 
the same syntax as regular python imports. So to import a few modules in a
218
 
lazy fashion do::
219
 
 
220
 
  from bzrlib.lazy_import import lazy_import
221
 
  lazy_import(globals(), """
222
 
  import os
223
 
  import subprocess
224
 
  import sys
225
 
  import time
226
 
 
227
 
  from bzrlib import (
228
 
     errors,
229
 
     transport,
230
 
     foo as bar,
231
 
     )
232
 
  import bzrlib.transport
233
 
  import bzrlib.xml5
234
 
  """)
235
 
 
236
 
At this point, all of these exist as a ``ImportReplacer`` object, ready to
237
 
be imported once a member is accessed.
238
 
 
239
 
 
240
 
Modules versus Members
241
 
~~~~~~~~~~~~~~~~~~~~~~
242
 
 
243
 
While it is possible for ``lazy_import()`` to import members of a module
244
 
wehn using the ``from module import member`` syntax, it is recommended to
245
 
only use that syntax to load sub modules ``from module import submodule``.
246
 
This is because variables and classes can frequently be used without
247
 
needing a sub-member for example::
248
 
 
249
 
  lazy_import(globals(), """
250
 
  from module import MyClass
251
 
  """)
252
 
 
253
 
  def test(x):
254
 
      return isinstance(x, MyClass)
255
 
 
256
 
This will incorrectly fail, because ``MyClass`` is a ``ImportReplacer``
257
 
object, rather than the real class.
258
 
 
259
 
 
260
 
Passing to other variables
261
 
~~~~~~~~~~~~~~~~~~~~~~~~~~
262
 
 
263
 
It also is incorrect to assign ``ImportReplacer`` objects to other variables.
264
 
Because the replacer only knows about the original name, it is unable to
265
 
replace other variables. The ``ImportReplacer`` class will raise an
266
 
``IllegalUseOfScopeReplacer`` exception if it can figure out that this
267
 
happened. But it requires accessing a member more than once from the new
268
 
variable, so some bugs are not detected right away.
269
 
 
270
 
 
271
212
Writing output
272
213
==============
273
214
 
534
475
so, please reply and say so.)
535
476
 
536
477
 
537
 
Making installers for OS Windows
538
 
================================
539
 
To build a win32 installer, see the instructions on the wiki page:
540
 
http://bazaar-vcs.org/BzrWin32Installer
541
 
 
542
 
 
543
478
:: vim: ft=rst tw=74 ai