~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

Initial commit for russian version of documents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
144
144
    """Customized build distutils action.
145
145
    Generate bzr.1.
146
146
    """
147
 
 
148
147
    def run(self):
149
148
        build.run(self)
150
149
 
151
 
        from tools import generate_docs
 
150
        import generate_docs
152
151
        generate_docs.main(argv=["bzr", "man"])
153
152
 
154
153
 
176
175
    from distutils.command.build_ext import build_ext
177
176
else:
178
177
    have_pyrex = True
179
 
    from Pyrex.Compiler.Version import version as pyrex_version
180
178
 
181
179
 
182
180
class build_ext_if_possible(build_ext):
183
181
 
184
 
    user_options = build_ext.user_options + [
185
 
        ('allow-python-fallback', None,
186
 
         "When an extension cannot be built, allow falling"
187
 
         " back to the pure-python implementation.")
188
 
        ]
189
 
 
190
 
    def initialize_options(self):
191
 
        build_ext.initialize_options(self)
192
 
        self.allow_python_fallback = False
193
 
 
194
182
    def run(self):
195
183
        try:
196
184
            build_ext.run(self)
197
185
        except DistutilsPlatformError, e:
198
 
            if not self.allow_python_fallback:
199
 
                log.warn('\n  Cannot build extensions.\n'
200
 
                         '  Use "build_ext --allow-python-fallback" to use'
201
 
                         ' slower python implementations instead.\n')
202
 
                raise
203
186
            log.warn(str(e))
204
 
            log.warn('\n  Extensions cannot be built.\n'
205
 
                     '  Using the slower Python implementations instead.\n')
 
187
            log.warn('Extensions cannot be built, '
 
188
                     'will use the Python versions instead')
206
189
 
207
190
    def build_extension(self, ext):
208
191
        try:
209
192
            build_ext.build_extension(self, ext)
210
193
        except CCompilerError:
211
 
            if not self.allow_python_fallback:
212
 
                log.warn('\n  Cannot build extension "%s".\n'
213
 
                         '  Use "build_ext --allow-python-fallback" to use'
214
 
                         ' slower python implementations instead.\n'
215
 
                         % (ext.name,))
216
 
                raise
217
 
            log.warn('\n  Building of "%s" extension failed.\n'
218
 
                     '  Using the slower Python implementation instead.'
219
 
                     % (ext.name,))
 
194
            log.warn('Building of "%s" extension failed, '
 
195
                     'will use the Python version instead' % (ext.name,))
220
196
 
221
197
 
222
198
# Override the build_ext if we have Pyrex available
224
200
unavailable_files = []
225
201
 
226
202
 
227
 
def add_pyrex_extension(module_name, libraries=None, extra_source=[]):
 
203
def add_pyrex_extension(module_name, **kwargs):
228
204
    """Add a pyrex module to build.
229
205
 
230
206
    This will use Pyrex to auto-generate the .c file if it is available.
240
216
    path = module_name.replace('.', '/')
241
217
    pyrex_name = path + '.pyx'
242
218
    c_name = path + '.c'
243
 
    define_macros = []
244
 
    if sys.platform == 'win32':
245
 
        # pyrex uses the macro WIN32 to detect the platform, even though it
246
 
        # should be using something like _WIN32 or MS_WINDOWS, oh well, we can
247
 
        # give it the right value.
248
 
        define_macros.append(('WIN32', None))
249
219
    if have_pyrex:
250
 
        source = [pyrex_name]
 
220
        ext_modules.append(Extension(module_name, [pyrex_name], **kwargs))
251
221
    else:
252
222
        if not os.path.isfile(c_name):
253
223
            unavailable_files.append(c_name)
254
 
            return
255
224
        else:
256
 
            source = [c_name]
257
 
    source.extend(extra_source)
258
 
    ext_modules.append(Extension(module_name, source,
259
 
        define_macros=define_macros, libraries=libraries))
260
 
 
261
 
 
262
 
add_pyrex_extension('bzrlib._annotator_pyx')
263
 
add_pyrex_extension('bzrlib._bencode_pyx')
264
 
add_pyrex_extension('bzrlib._btree_serializer_pyx')
265
 
add_pyrex_extension('bzrlib._chunks_to_lines_pyx')
266
 
add_pyrex_extension('bzrlib._groupcompress_pyx',
267
 
                    extra_source=['bzrlib/diff-delta.c'])
268
 
add_pyrex_extension('bzrlib._knit_load_data_pyx')
269
 
add_pyrex_extension('bzrlib._known_graph_pyx')
270
 
add_pyrex_extension('bzrlib._rio_pyx')
 
225
            ext_modules.append(Extension(module_name, [c_name], **kwargs))
 
226
 
 
227
 
 
228
add_pyrex_extension('bzrlib._dirstate_helpers_c')
 
229
add_pyrex_extension('bzrlib._knit_load_data_c')
271
230
if sys.platform == 'win32':
272
 
    add_pyrex_extension('bzrlib._dirstate_helpers_pyx',
273
 
                        libraries=['Ws2_32'])
274
 
    add_pyrex_extension('bzrlib._walkdirs_win32')
275
 
    z_lib = 'zdll'
276
 
else:
277
 
    if have_pyrex and pyrex_version == '0.9.4.1':
278
 
        # Pyrex 0.9.4.1 fails to compile this extension correctly
279
 
        # The code it generates re-uses a "local" pointer and
280
 
        # calls "PY_DECREF" after having set it to NULL. (It mixes PY_XDECREF
281
 
        # which is NULL safe with PY_DECREF which is not.)
282
 
        print 'Cannot build extension "bzrlib._dirstate_helpers_pyx" using'
283
 
        print 'your version of pyrex "%s". Please upgrade your pyrex' % (
284
 
            pyrex_version,)
285
 
        print 'install. For now, the non-compiled (python) version will'
286
 
        print 'be used instead.'
287
 
    else:
288
 
        add_pyrex_extension('bzrlib._dirstate_helpers_pyx')
289
 
    add_pyrex_extension('bzrlib._readdir_pyx')
290
 
    z_lib = 'z'
291
 
add_pyrex_extension('bzrlib._chk_map_pyx', libraries=[z_lib])
292
 
ext_modules.append(Extension('bzrlib._patiencediff_c',
293
 
                             ['bzrlib/_patiencediff_c.c']))
 
231
    # pyrex uses the macro WIN32 to detect the platform, even though it should
 
232
    # be using something like _WIN32 or MS_WINDOWS, oh well, we can give it the
 
233
    # right value.
 
234
    add_pyrex_extension('bzrlib._walkdirs_win32',
 
235
                        define_macros=[('WIN32', None)])
 
236
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
294
237
 
295
238
 
296
239
if unavailable_files:
301
244
 
302
245
 
303
246
def get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
304
 
                         gui_targets, data_files):
 
247
                         gui_targets):
305
248
    packages.append('tbzrcommands')
306
249
 
307
250
    # ModuleFinder can't handle runtime changes to __path__, but
308
251
    # win32com uses them.  Hook this in so win32com.shell is found.
309
252
    import modulefinder
310
253
    import win32com
311
 
    import cPickle as pickle
312
254
    for p in win32com.__path__[1:]:
313
255
        modulefinder.AddPackagePath("win32com", p)
314
256
    for extra in ["win32com.shell"]:
327
269
    sys.path.append(os.path.join(tbzr_root, "shellext", "python"))
328
270
 
329
271
    packages.append("tbzrlib")
330
 
 
331
 
    # collect up our icons.
332
 
    cwd = os.getcwd()
333
 
    ico_root = os.path.join(tbzr_root, 'tbzrlib', 'resources')
334
 
    icos = [] # list of (path_root, relative_ico_path)
335
 
    # First always bzr's icon and its in the root of the bzr tree.
336
 
    icos.append(('', 'bzr.ico'))
337
 
    for root, dirs, files in os.walk(ico_root):
338
 
        icos.extend([(ico_root, os.path.join(root, f)[len(ico_root)+1:])
339
 
                     for f in files if f.endswith('.ico')])
340
 
    # allocate an icon ID for each file and the full path to the ico
341
 
    icon_resources = [(rid, os.path.join(ico_dir, ico_name))
342
 
                      for rid, (ico_dir, ico_name) in enumerate(icos)]
343
 
    # create a string resource with the mapping.  Might as well save the
344
 
    # runtime some effort and write a pickle.
345
 
    # Runtime expects unicode objects with forward-slash seps.
346
 
    fse = sys.getfilesystemencoding()
347
 
    map_items = [(f.replace('\\', '/').decode(fse), rid)
348
 
                 for rid, (_, f) in enumerate(icos)]
349
 
    ico_map = dict(map_items)
350
 
    # Create a new resource type of 'ICON_MAP', and use ID=1
351
 
    other_resources = [ ("ICON_MAP", 1, pickle.dumps(ico_map))]
352
 
 
353
272
    excludes.extend("""pywin pywin.dialogs pywin.dialogs.list
354
273
                       win32ui crawler.Crawler""".split())
355
274
 
356
 
    # NOTE: We still create a DLL version of the Python implemented shell
357
 
    # extension for testing purposes - but it is *not* registered by
358
 
    # default - our C++ one is instead.  To discourage people thinking
359
 
    # this DLL is still necessary, its called 'tbzr_old.dll'
360
275
    tbzr = dict(
361
276
        modules=["tbzr"],
362
277
        create_exe = False, # we only want a .dll
363
 
        dest_base = 'tbzr_old',
364
278
    )
365
279
    com_targets.append(tbzr)
366
280
 
367
281
    # tbzrcache executables - a "console" version for debugging and a
368
282
    # GUI version that is generally used.
369
283
    tbzrcache = dict(
370
 
        script = os.path.join(tbzr_root, "scripts", "tbzrcache.py"),
371
 
        icon_resources = icon_resources,
372
 
        other_resources = other_resources,
 
284
        script = os.path.join(tbzr_root, "Scripts", "tbzrcache.py"),
 
285
        icon_resources = [(0,'bzr.ico')],
373
286
    )
374
287
    console_targets.append(tbzrcache)
375
288
 
380
293
 
381
294
    # ditto for the tbzrcommand tool
382
295
    tbzrcommand = dict(
383
 
        script = os.path.join(tbzr_root, "scripts", "tbzrcommand.py"),
 
296
        script = os.path.join(tbzr_root, "Scripts", "tbzrcommand.py"),
384
297
        icon_resources = [(0,'bzr.ico')],
385
298
    )
386
299
    console_targets.append(tbzrcommand)
388
301
    tbzrcommandw["dest_base"]="tbzrcommandw"
389
302
    gui_targets.append(tbzrcommandw)
390
303
    
391
 
    # A utility to see python output from both C++ and Python based shell
392
 
    # extensions
393
 
    tracer = dict(script=os.path.join(tbzr_root, "scripts", "tbzrtrace.py"))
 
304
    # tbzr tests
 
305
    tbzrtest = dict(
 
306
        script = os.path.join(tbzr_root, "Scripts", "tbzrtest.py"),
 
307
    )
 
308
    console_targets.append(tbzrtest)
 
309
 
 
310
    # A utility to see python output from the shell extension - this will
 
311
    # die when we get a c++ extension
 
312
    # any .py file from pywin32's win32 lib will do (other than
 
313
    # win32traceutil itself that is)
 
314
    import winerror
 
315
    win32_lib_dir = os.path.dirname(winerror.__file__)
 
316
    tracer = dict(script = os.path.join(win32_lib_dir, "win32traceutil.py"),
 
317
                  dest_base="tbzr_tracer")
394
318
    console_targets.append(tracer)
395
319
 
396
 
    # The C++ implemented shell extensions.
397
 
    dist_dir = os.path.join(tbzr_root, "shellext", "cpp", "tbzrshellext",
398
 
                            "build", "dist")
399
 
    data_files.append(('', [os.path.join(dist_dir, 'tbzrshellext_x86.dll')]))
400
 
    data_files.append(('', [os.path.join(dist_dir, 'tbzrshellext_x64.dll')]))
401
 
 
402
320
 
403
321
def get_qbzr_py2exe_info(includes, excludes, packages):
404
322
    # PyQt4 itself still escapes the plugin detection code for some reason...
406
324
    excludes.append('PyQt4.elementtree.ElementTree')
407
325
    includes.append('sip') # extension module required for Qt.
408
326
    packages.append('pygments') # colorizer for qbzr
409
 
    packages.append('docutils') # html formatting
410
327
    # but we can avoid many Qt4 Dlls.
411
328
    dll_excludes.extend(
412
329
        """QtAssistantClient4.dll QtCLucene4.dll QtDesigner4.dll
420
337
        os.environ["PATH"] = path + os.pathsep + qt_dir
421
338
 
422
339
 
423
 
def get_svn_py2exe_info(includes, excludes, packages):
424
 
    packages.append('subvertpy')
425
 
 
426
 
 
427
340
if 'bdist_wininst' in sys.argv:
428
341
    def find_docs():
429
342
        docs = []
538
451
                  ImaginaryModule cElementTree elementtree.ElementTree
539
452
                  Crypto.PublicKey._fastmath
540
453
                  medusa medusa.filesys medusa.ftp_server
541
 
                  tools
 
454
                  tools tools.doc_generate
542
455
                  resource validate""".split()
543
456
    dll_excludes = []
544
457
 
567
480
    for root, dirs, files in os.walk('bzrlib/plugins'):
568
481
        if root == 'bzrlib/plugins':
569
482
            plugins = set(dirs)
570
 
            # We ship plugins as normal files on the file-system - however,
571
 
            # the build process can cause *some* of these plugin files to end
572
 
            # up in library.zip. Thus, we saw (eg) "plugins/svn/test" in
573
 
            # library.zip, and then saw import errors related to that as the
574
 
            # rest of the svn plugin wasn't. So we tell py2exe to leave the
575
 
            # plugins out of the .zip file
576
 
            excludes.extend(["bzrlib.plugins." + d for d in dirs])
577
483
        x = []
578
484
        for i in files:
579
 
            if os.path.splitext(i)[1] not in [".py", ".pyd", ".dll", ".mo"]:
 
485
            if os.path.splitext(i)[1] not in [".py", ".pyd", ".dll"]:
580
486
                continue
581
487
            if i == '__init__.py' and root == 'bzrlib/plugins':
582
488
                continue
597
503
                       ]
598
504
    gui_targets = []
599
505
    com_targets = []
600
 
    data_files = topics_files + plugins_files
601
506
 
602
507
    if 'qbzr' in plugins:
603
508
        get_qbzr_py2exe_info(includes, excludes, packages)
604
509
 
605
 
    if 'svn' in plugins:
606
 
        get_svn_py2exe_info(includes, excludes, packages)
607
 
 
608
510
    if "TBZR" in os.environ:
609
511
        # TORTOISE_OVERLAYS_MSI_WIN32 must be set to the location of the
610
512
        # TortoiseOverlays MSI installer file. It is in the TSVN svn repo and
611
513
        # can be downloaded from (username=guest, blank password):
612
 
        # http://tortoisesvn.tigris.org/svn/tortoisesvn/TortoiseOverlays
613
 
        # look for: version-1.0.4/bin/TortoiseOverlays-1.0.4.11886-win32.msi
614
 
        # Ditto for TORTOISE_OVERLAYS_MSI_X64, pointing at *-x64.msi.
615
 
        for needed in ('TORTOISE_OVERLAYS_MSI_WIN32',
616
 
                       'TORTOISE_OVERLAYS_MSI_X64'):
617
 
            url = ('http://guest:@tortoisesvn.tigris.org/svn/tortoisesvn'
618
 
                   '/TortoiseOverlays')
619
 
            if not os.path.isfile(os.environ.get(needed, '<nofile>')):
620
 
                raise RuntimeError(
621
 
                    "\nPlease set %s to the location of the relevant"
622
 
                    "\nTortoiseOverlays .msi installer file."
623
 
                    " The installers can be found at"
624
 
                    "\n  %s"
625
 
                    "\ncheck in the version-X.Y.Z/bin/ subdir" % (needed, url))
 
514
        # http://tortoisesvn.tigris.org/svn/tortoisesvn/TortoiseOverlays/version-1.0.4/bin/TortoiseOverlays-1.0.4.11886-win32.msi
 
515
        if not os.path.isfile(os.environ.get('TORTOISE_OVERLAYS_MSI_WIN32',
 
516
                                             '<nofile>')):
 
517
            raise RuntimeError("Please set TORTOISE_OVERLAYS_MSI_WIN32 to the"
 
518
                               " location of the Win32 TortoiseOverlays .msi"
 
519
                               " installer file")
626
520
        get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
627
 
                             gui_targets, data_files)
 
521
                             gui_targets)
628
522
    else:
629
523
        # print this warning to stderr as output is redirected, so it is seen
630
524
        # at build time.  Also to stdout so it appears in the log
634
528
 
635
529
    # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls
636
530
    # in on Vista.
637
 
    dll_excludes.extend(["MSWSOCK.dll", "MSVCP60.dll", "powrprof.dll"])
 
531
    dll_excludes.append("MSWSOCK.dll")
638
532
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
639
533
                               "includes": includes,
640
534
                               "excludes": excludes,
649
543
          windows=gui_targets,
650
544
          com_server=com_targets,
651
545
          zipfile='lib/library.zip',
652
 
          data_files=data_files,
 
546
          data_files=topics_files + plugins_files,
653
547
          cmdclass={'install_data': install_data_with_bytecompile},
654
548
          )
655
549
 
657
551
    # ad-hoc for easy_install
658
552
    DATA_FILES = []
659
553
    if not 'bdist_egg' in sys.argv:
660
 
        # generate and install bzr.1 only with plain install, not the
661
 
        # easy_install one
 
554
        # generate and install bzr.1 only with plain install, not easy_install one
662
555
        DATA_FILES = [('man/man1', ['bzr.1'])]
663
556
 
664
557
    # std setup