~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

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
 
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 should
246
 
        # be using something like _WIN32 or MS_WINDOWS, oh well, we can give it the
247
 
        # 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))
 
225
            ext_modules.append(Extension(module_name, [c_name], **kwargs))
260
226
 
261
227
 
262
228
add_pyrex_extension('bzrlib._btree_serializer_c')
263
 
add_pyrex_extension('bzrlib._groupcompress_pyx',
264
 
                    extra_source=['bzrlib/diff-delta.c'])
265
 
add_pyrex_extension('bzrlib._chunks_to_lines_pyx')
 
229
add_pyrex_extension('bzrlib._dirstate_helpers_c')
266
230
add_pyrex_extension('bzrlib._knit_load_data_c')
267
 
add_pyrex_extension('bzrlib._chk_map_pyx', libraries=['z'])
 
231
add_pyrex_extension('bzrlib._readdir_pyx')
268
232
if sys.platform == 'win32':
269
 
    add_pyrex_extension('bzrlib._dirstate_helpers_c',
270
 
                        libraries=['Ws2_32'])
271
 
    add_pyrex_extension('bzrlib._walkdirs_win32')
272
 
else:
273
 
    if have_pyrex and pyrex_version == '0.9.4.1':
274
 
        # Pyrex 0.9.4.1 fails to compile this extension correctly
275
 
        # The code it generates re-uses a "local" pointer and
276
 
        # calls "PY_DECREF" after having set it to NULL. (It mixes PY_XDECREF
277
 
        # which is NULL safe with PY_DECREF which is not.)
278
 
        print 'Cannot build extension "bzrlib._dirstate_helpers_c" using'
279
 
        print 'your version of pyrex "%s". Please upgrade your pyrex' % (
280
 
            pyrex_version,)
281
 
        print 'install. For now, the non-compiled (python) version will'
282
 
        print 'be used instead.'
283
 
    else:
284
 
        add_pyrex_extension('bzrlib._dirstate_helpers_c')
285
 
    add_pyrex_extension('bzrlib._readdir_pyx')
 
233
    # pyrex uses the macro WIN32 to detect the platform, even though it should
 
234
    # be using something like _WIN32 or MS_WINDOWS, oh well, we can give it the
 
235
    # right value.
 
236
    add_pyrex_extension('bzrlib._walkdirs_win32',
 
237
                        define_macros=[('WIN32', None)])
286
238
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
287
239
 
288
240
 
294
246
 
295
247
 
296
248
def get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
297
 
                         gui_targets, data_files):
 
249
                         gui_targets):
298
250
    packages.append('tbzrcommands')
299
251
 
300
252
    # ModuleFinder can't handle runtime changes to __path__, but
346
298
    excludes.extend("""pywin pywin.dialogs pywin.dialogs.list
347
299
                       win32ui crawler.Crawler""".split())
348
300
 
349
 
    # NOTE: We still create a DLL version of the Python implemented shell
350
 
    # extension for testing purposes - but it is *not* registered by
351
 
    # default - our C++ one is instead.  To discourage people thinking
352
 
    # this DLL is still necessary, its called 'tbzr_old.dll'
353
301
    tbzr = dict(
354
302
        modules=["tbzr"],
355
303
        create_exe = False, # we only want a .dll
356
 
        dest_base = 'tbzr_old',
357
304
    )
358
305
    com_targets.append(tbzr)
359
306
 
360
307
    # tbzrcache executables - a "console" version for debugging and a
361
308
    # GUI version that is generally used.
362
309
    tbzrcache = dict(
363
 
        script = os.path.join(tbzr_root, "scripts", "tbzrcache.py"),
 
310
        script = os.path.join(tbzr_root, "Scripts", "tbzrcache.py"),
364
311
        icon_resources = icon_resources,
365
312
        other_resources = other_resources,
366
313
    )
373
320
 
374
321
    # ditto for the tbzrcommand tool
375
322
    tbzrcommand = dict(
376
 
        script = os.path.join(tbzr_root, "scripts", "tbzrcommand.py"),
 
323
        script = os.path.join(tbzr_root, "Scripts", "tbzrcommand.py"),
377
324
        icon_resources = [(0,'bzr.ico')],
378
325
    )
379
326
    console_targets.append(tbzrcommand)
381
328
    tbzrcommandw["dest_base"]="tbzrcommandw"
382
329
    gui_targets.append(tbzrcommandw)
383
330
    
384
 
    # A utility to see python output from both C++ and Python based shell
385
 
    # extensions
386
 
    tracer = dict(script=os.path.join(tbzr_root, "scripts", "tbzrtrace.py"))
 
331
    # tbzr tests
 
332
    tbzrtest = dict(
 
333
        script = os.path.join(tbzr_root, "Scripts", "tbzrtest.py"),
 
334
    )
 
335
    console_targets.append(tbzrtest)
 
336
 
 
337
    # A utility to see python output from the shell extension - this will
 
338
    # die when we get a c++ extension
 
339
    # any .py file from pywin32's win32 lib will do (other than
 
340
    # win32traceutil itself that is)
 
341
    import winerror
 
342
    win32_lib_dir = os.path.dirname(winerror.__file__)
 
343
    tracer = dict(script = os.path.join(win32_lib_dir, "win32traceutil.py"),
 
344
                  dest_base="tbzr_tracer")
387
345
    console_targets.append(tracer)
388
346
 
389
 
    # The C++ implemented shell extensions.
390
 
    dist_dir = os.path.join(tbzr_root, "shellext", "cpp", "tbzrshellext",
391
 
                            "build", "dist")
392
 
    data_files.append(('', [os.path.join(dist_dir, 'tbzrshellext_x86.dll')]))
393
 
    data_files.append(('', [os.path.join(dist_dir, 'tbzrshellext_x64.dll')]))
394
 
 
395
347
 
396
348
def get_qbzr_py2exe_info(includes, excludes, packages):
397
349
    # PyQt4 itself still escapes the plugin detection code for some reason...
399
351
    excludes.append('PyQt4.elementtree.ElementTree')
400
352
    includes.append('sip') # extension module required for Qt.
401
353
    packages.append('pygments') # colorizer for qbzr
402
 
    packages.append('docutils') # html formatting
403
354
    # but we can avoid many Qt4 Dlls.
404
355
    dll_excludes.extend(
405
356
        """QtAssistantClient4.dll QtCLucene4.dll QtDesigner4.dll
413
364
        os.environ["PATH"] = path + os.pathsep + qt_dir
414
365
 
415
366
 
416
 
def get_svn_py2exe_info(includes, excludes, packages):
417
 
    packages.append('subvertpy')
418
 
 
419
 
 
420
367
if 'bdist_wininst' in sys.argv:
421
368
    def find_docs():
422
369
        docs = []
560
507
    for root, dirs, files in os.walk('bzrlib/plugins'):
561
508
        if root == 'bzrlib/plugins':
562
509
            plugins = set(dirs)
563
 
            # We ship plugins as normal files on the file-system - however,
564
 
            # the build process can cause *some* of these plugin files to end
565
 
            # up in library.zip. Thus, we saw (eg) "plugins/svn/test" in
566
 
            # library.zip, and then saw import errors related to that as the
567
 
            # rest of the svn plugin wasn't. So we tell py2exe to leave the
568
 
            # plugins out of the .zip file
569
 
            excludes.extend(["bzrlib.plugins." + d for d in dirs])
570
510
        x = []
571
511
        for i in files:
572
 
            if os.path.splitext(i)[1] not in [".py", ".pyd", ".dll", ".mo"]:
 
512
            if os.path.splitext(i)[1] not in [".py", ".pyd", ".dll"]:
573
513
                continue
574
514
            if i == '__init__.py' and root == 'bzrlib/plugins':
575
515
                continue
590
530
                       ]
591
531
    gui_targets = []
592
532
    com_targets = []
593
 
    data_files = topics_files + plugins_files
594
533
 
595
534
    if 'qbzr' in plugins:
596
535
        get_qbzr_py2exe_info(includes, excludes, packages)
597
536
 
598
 
    if 'svn' in plugins:
599
 
        get_svn_py2exe_info(includes, excludes, packages)
600
 
 
601
537
    if "TBZR" in os.environ:
602
538
        # TORTOISE_OVERLAYS_MSI_WIN32 must be set to the location of the
603
539
        # TortoiseOverlays MSI installer file. It is in the TSVN svn repo and
604
540
        # can be downloaded from (username=guest, blank password):
605
541
        # http://tortoisesvn.tigris.org/svn/tortoisesvn/TortoiseOverlays/version-1.0.4/bin/TortoiseOverlays-1.0.4.11886-win32.msi
606
 
        # Ditto for TORTOISE_OVERLAYS_MSI_X64, pointing at *-x64.msi.
607
 
        for needed in ('TORTOISE_OVERLAYS_MSI_WIN32',
608
 
                       'TORTOISE_OVERLAYS_MSI_X64'):
609
 
            if not os.path.isfile(os.environ.get(needed, '<nofile>')):
610
 
                raise RuntimeError("Please set %s to the"
611
 
                                   " location of the relevant TortoiseOverlays"
612
 
                                   " .msi installer file" % needed)
 
542
        if not os.path.isfile(os.environ.get('TORTOISE_OVERLAYS_MSI_WIN32',
 
543
                                             '<nofile>')):
 
544
            raise RuntimeError("Please set TORTOISE_OVERLAYS_MSI_WIN32 to the"
 
545
                               " location of the Win32 TortoiseOverlays .msi"
 
546
                               " installer file")
613
547
        get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
614
 
                             gui_targets, data_files)
 
548
                             gui_targets)
615
549
    else:
616
550
        # print this warning to stderr as output is redirected, so it is seen
617
551
        # at build time.  Also to stdout so it appears in the log
621
555
 
622
556
    # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls
623
557
    # in on Vista.
624
 
    dll_excludes.extend(["MSWSOCK.dll", "MSVCP60.dll", "powrprof.dll"])
 
558
    dll_excludes.append("MSWSOCK.dll")
625
559
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
626
560
                               "includes": includes,
627
561
                               "excludes": excludes,
636
570
          windows=gui_targets,
637
571
          com_server=com_targets,
638
572
          zipfile='lib/library.zip',
639
 
          data_files=data_files,
 
573
          data_files=topics_files + plugins_files,
640
574
          cmdclass={'install_data': install_data_with_bytecompile},
641
575
          )
642
576