~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
import os
10
10
import os.path
11
11
import sys
 
12
import copy
 
13
import glob
12
14
 
13
 
if sys.version_info < (2, 4):
14
 
    sys.stderr.write("[ERROR] Not a supported Python version. Need 2.4+\n")
 
15
if sys.version_info < (2, 6):
 
16
    sys.stderr.write("[ERROR] Not a supported Python version. Need 2.6+\n")
15
17
    sys.exit(1)
16
18
 
17
19
# NOTE: The directory containing setup.py, whether run by 'python setup.py' or
37
39
    'version':      bzrlib.__version__,
38
40
    'author':       'Canonical Ltd',
39
41
    'author_email': 'bazaar@lists.canonical.com',
40
 
    'url':          'http://www.bazaar-vcs.org/',
 
42
    'url':          'http://bazaar.canonical.com/',
41
43
    'description':  'Friendly distributed version control system',
42
44
    'license':      'GNU GPL v2',
43
 
    'download_url': 'http://bazaar-vcs.org/Download',
 
45
    'download_url': 'https://launchpad.net/bzr/+download',
44
46
    'long_description': get_long_description(),
45
47
    'classifiers': [
46
48
        'Development Status :: 6 - Mature',
65
67
            'package_data': {'bzrlib': ['doc/api/*.txt',
66
68
                                        'tests/test_patches_data/*',
67
69
                                        'help_topics/en/*.txt',
 
70
                                        'tests/ssl_certs/ca.crt',
 
71
                                        'tests/ssl_certs/server_without_pass.key',
 
72
                                        'tests/ssl_certs/server_with_pass.key',
 
73
                                        'tests/ssl_certs/server.crt',
68
74
                                       ]},
69
75
           }
70
 
 
 
76
I18N_FILES = []
 
77
for filepath in glob.glob("bzrlib/locale/*/LC_MESSAGES/*.mo"):
 
78
    langfile = filepath[len("bzrlib/locale/"):]
 
79
    targetpath = os.path.dirname(os.path.join("share/locale", langfile))
 
80
    I18N_FILES.append((targetpath, [filepath]))
71
81
 
72
82
def get_bzrlib_packages():
73
83
    """Recurse through the bzrlib directory, and extract the package names"""
93
103
BZRLIB['packages'] = get_bzrlib_packages()
94
104
 
95
105
 
 
106
from distutils import log
96
107
from distutils.core import setup
97
108
from distutils.command.install_scripts import install_scripts
98
109
from distutils.command.install_data import install_data
121
132
                f = file(batch_path, "w")
122
133
                f.write(batch_str)
123
134
                f.close()
124
 
                print "Created:", batch_path
125
 
            except Exception, e:
126
 
                print "ERROR: Unable to create %s: %s" % (batch_path, e)
 
135
                print("Created: %s" % batch_path)
 
136
            except Exception:
 
137
                e = sys.exc_info()[1]
 
138
                print("ERROR: Unable to create %s: %s" % (batch_path, e))
127
139
 
128
140
    def _quoted_path(self, path):
129
141
        if ' ' in path:
145
157
    Generate bzr.1.
146
158
    """
147
159
 
 
160
    sub_commands = build.sub_commands + [
 
161
            ('build_mo', lambda _: True),
 
162
            ]
 
163
 
148
164
    def run(self):
149
165
        build.run(self)
150
166
 
151
 
        import generate_docs
 
167
        from tools import generate_docs
152
168
        generate_docs.main(argv=["bzr", "man"])
153
169
 
154
170
 
156
172
## Setup
157
173
########################
158
174
 
 
175
from tools.build_mo import build_mo
 
176
 
159
177
command_classes = {'install_scripts': my_install_scripts,
160
 
                   'build': bzr_build}
 
178
                   'build': bzr_build,
 
179
                   'build_mo': build_mo,
 
180
                   }
161
181
from distutils import log
162
182
from distutils.errors import CCompilerError, DistutilsPlatformError
163
183
from distutils.extension import Extension
164
184
ext_modules = []
165
185
try:
166
 
    from Pyrex.Distutils import build_ext
 
186
    try:
 
187
        from Cython.Distutils import build_ext
 
188
        from Cython.Compiler.Version import version as pyrex_version
 
189
    except ImportError:
 
190
        print("No Cython, trying Pyrex...")
 
191
        from Pyrex.Distutils import build_ext
 
192
        from Pyrex.Compiler.Version import version as pyrex_version
167
193
except ImportError:
168
194
    have_pyrex = False
169
195
    # try to build the extension from the prior generated source.
170
 
    print
171
 
    print ("The python package 'Pyrex' is not available."
172
 
           " If the .c files are available,")
173
 
    print ("they will be built,"
174
 
           " but modifying the .pyx files will not rebuild them.")
175
 
    print
 
196
    print("")
 
197
    print("The python package 'Pyrex' is not available."
 
198
          " If the .c files are available,")
 
199
    print("they will be built,"
 
200
          " but modifying the .pyx files will not rebuild them.")
 
201
    print("")
176
202
    from distutils.command.build_ext import build_ext
177
203
else:
178
204
    have_pyrex = True
179
 
    from Pyrex.Compiler.Version import version as pyrex_version
 
205
    import re
 
206
    _version = re.match("^[0-9.]+", pyrex_version).group(0)
 
207
    pyrex_version_info = tuple(map(int, _version.split('.')))
180
208
 
181
209
 
182
210
class build_ext_if_possible(build_ext):
194
222
    def run(self):
195
223
        try:
196
224
            build_ext.run(self)
197
 
        except DistutilsPlatformError, e:
 
225
        except DistutilsPlatformError:
 
226
            e = sys.exc_info()[1]
198
227
            if not self.allow_python_fallback:
199
228
                log.warn('\n  Cannot build extensions.\n'
200
229
                         '  Use "build_ext --allow-python-fallback" to use'
209
238
            build_ext.build_extension(self, ext)
210
239
        except CCompilerError:
211
240
            if not self.allow_python_fallback:
212
 
                log.warn('\n  Cannot build extensions.\n'
 
241
                log.warn('\n  Cannot build extension "%s".\n'
213
242
                         '  Use "build_ext --allow-python-fallback" to use'
214
243
                         ' slower python implementations instead.\n'
215
244
                         % (ext.name,))
224
253
unavailable_files = []
225
254
 
226
255
 
227
 
def add_pyrex_extension(module_name, libraries=None):
 
256
def add_pyrex_extension(module_name, libraries=None, extra_source=[]):
228
257
    """Add a pyrex module to build.
229
258
 
230
259
    This will use Pyrex to auto-generate the .c file if it is available.
242
271
    c_name = path + '.c'
243
272
    define_macros = []
244
273
    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.
 
274
        # pyrex uses the macro WIN32 to detect the platform, even though it
 
275
        # should be using something like _WIN32 or MS_WINDOWS, oh well, we can
 
276
        # give it the right value.
248
277
        define_macros.append(('WIN32', None))
249
278
    if have_pyrex:
250
 
        ext_modules.append(Extension(module_name, [pyrex_name],
251
 
            define_macros=define_macros, libraries=libraries))
 
279
        source = [pyrex_name]
252
280
    else:
253
281
        if not os.path.isfile(c_name):
254
282
            unavailable_files.append(c_name)
 
283
            return
255
284
        else:
256
 
            ext_modules.append(Extension(module_name, [c_name],
257
 
                define_macros=define_macros, libraries=libraries))
258
 
 
259
 
 
260
 
add_pyrex_extension('bzrlib._btree_serializer_c')
 
285
            source = [c_name]
 
286
    source.extend(extra_source)
 
287
    ext_modules.append(Extension(module_name, source,
 
288
        define_macros=define_macros, libraries=libraries))
 
289
 
 
290
 
 
291
add_pyrex_extension('bzrlib._annotator_pyx')
 
292
add_pyrex_extension('bzrlib._bencode_pyx')
261
293
add_pyrex_extension('bzrlib._chunks_to_lines_pyx')
262
 
add_pyrex_extension('bzrlib._knit_load_data_c')
 
294
add_pyrex_extension('bzrlib._groupcompress_pyx',
 
295
                    extra_source=['bzrlib/diff-delta.c'])
 
296
add_pyrex_extension('bzrlib._knit_load_data_pyx')
 
297
add_pyrex_extension('bzrlib._known_graph_pyx')
 
298
add_pyrex_extension('bzrlib._rio_pyx')
263
299
if sys.platform == 'win32':
264
 
    add_pyrex_extension('bzrlib._dirstate_helpers_c',
 
300
    add_pyrex_extension('bzrlib._dirstate_helpers_pyx',
265
301
                        libraries=['Ws2_32'])
266
302
    add_pyrex_extension('bzrlib._walkdirs_win32')
267
303
else:
268
 
    if have_pyrex and pyrex_version == '0.9.4.1':
 
304
    if have_pyrex and pyrex_version_info[:3] == (0,9,4):
269
305
        # Pyrex 0.9.4.1 fails to compile this extension correctly
270
306
        # The code it generates re-uses a "local" pointer and
271
307
        # calls "PY_DECREF" after having set it to NULL. (It mixes PY_XDECREF
272
308
        # which is NULL safe with PY_DECREF which is not.)
273
 
        print 'Cannot build extension "bzrlib._dirstate_helpers_c" using'
274
 
        print 'your version of pyrex "%s". Please upgrade your pyrex' % (
275
 
            pyrex_version,)
276
 
        print 'install. For now, the non-compiled (python) version will'
277
 
        print 'be used instead.'
 
309
        # <https://bugs.launchpad.net/bzr/+bug/449372>
 
310
        # <https://bugs.launchpad.net/bzr/+bug/276868>
 
311
        print('Cannot build extension "bzrlib._dirstate_helpers_pyx" using')
 
312
        print('your version of pyrex "%s". Please upgrade your pyrex'
 
313
              % (pyrex_version,))
 
314
        print('install. For now, the non-compiled (python) version will')
 
315
        print('be used instead.')
278
316
    else:
279
 
        add_pyrex_extension('bzrlib._dirstate_helpers_c')
 
317
        add_pyrex_extension('bzrlib._dirstate_helpers_pyx')
280
318
    add_pyrex_extension('bzrlib._readdir_pyx')
281
 
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
 
319
add_pyrex_extension('bzrlib._chk_map_pyx')
 
320
ext_modules.append(Extension('bzrlib._patiencediff_c',
 
321
                             ['bzrlib/_patiencediff_c.c']))
 
322
if have_pyrex and pyrex_version_info < (0, 9, 6, 3):
 
323
    print("")
 
324
    print('Your Pyrex/Cython version %s is too old to build the simple_set' % (
 
325
        pyrex_version))
 
326
    print('and static_tuple extensions.')
 
327
    print('Please upgrade to at least Pyrex 0.9.6.3')
 
328
    print("")
 
329
    # TODO: Should this be a fatal error?
 
330
else:
 
331
    # We only need 0.9.6.3 to build _simple_set_pyx, but static_tuple depends
 
332
    # on simple_set
 
333
    add_pyrex_extension('bzrlib._simple_set_pyx')
 
334
    ext_modules.append(Extension('bzrlib._static_tuple_c',
 
335
                                 ['bzrlib/_static_tuple_c.c']))
 
336
add_pyrex_extension('bzrlib._btree_serializer_pyx')
282
337
 
283
338
 
284
339
if unavailable_files:
285
 
    print 'C extension(s) not found:'
286
 
    print '   %s' % ('\n  '.join(unavailable_files),)
287
 
    print 'The python versions will be used instead.'
288
 
    print
 
340
    print('C extension(s) not found:')
 
341
    print('   %s' % ('\n  '.join(unavailable_files),))
 
342
    print('The python versions will be used instead.')
 
343
    print("")
289
344
 
290
345
 
291
346
def get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
311
366
    # Ensure tbzrlib itself is on sys.path
312
367
    sys.path.append(tbzr_root)
313
368
 
314
 
    # Ensure our COM "entry-point" is on sys.path
315
 
    sys.path.append(os.path.join(tbzr_root, "shellext", "python"))
316
 
 
317
369
    packages.append("tbzrlib")
318
370
 
319
371
    # collect up our icons.
341
393
    excludes.extend("""pywin pywin.dialogs pywin.dialogs.list
342
394
                       win32ui crawler.Crawler""".split())
343
395
 
344
 
    # NOTE: We still create a DLL version of the Python implemented shell
345
 
    # extension for testing purposes - but it is *not* registered by
346
 
    # default - our C++ one is instead.  To discourage people thinking
347
 
    # this DLL is still necessary, its called 'tbzr_old.dll'
348
 
    tbzr = dict(
349
 
        modules=["tbzr"],
350
 
        create_exe = False, # we only want a .dll
351
 
        dest_base = 'tbzr_old',
352
 
    )
353
 
    com_targets.append(tbzr)
354
 
 
355
396
    # tbzrcache executables - a "console" version for debugging and a
356
397
    # GUI version that is generally used.
357
398
    tbzrcache = dict(
369
410
    # ditto for the tbzrcommand tool
370
411
    tbzrcommand = dict(
371
412
        script = os.path.join(tbzr_root, "scripts", "tbzrcommand.py"),
372
 
        icon_resources = [(0,'bzr.ico')],
 
413
        icon_resources = icon_resources,
 
414
        other_resources = other_resources,
373
415
    )
374
416
    console_targets.append(tbzrcommand)
375
417
    tbzrcommandw = tbzrcommand.copy()
382
424
    console_targets.append(tracer)
383
425
 
384
426
    # The C++ implemented shell extensions.
385
 
    dist_dir = os.path.join(tbzr_root, "shellext", "cpp", "tbzrshellext",
386
 
                            "build", "dist")
 
427
    dist_dir = os.path.join(tbzr_root, "shellext", "build")
387
428
    data_files.append(('', [os.path.join(dist_dir, 'tbzrshellext_x86.dll')]))
388
429
    data_files.append(('', [os.path.join(dist_dir, 'tbzrshellext_x64.dll')]))
389
430
 
390
431
 
391
 
def get_qbzr_py2exe_info(includes, excludes, packages):
 
432
def get_qbzr_py2exe_info(includes, excludes, packages, data_files):
392
433
    # PyQt4 itself still escapes the plugin detection code for some reason...
393
 
    packages.append('PyQt4')
394
 
    excludes.append('PyQt4.elementtree.ElementTree')
 
434
    includes.append('PyQt4.QtCore')
 
435
    includes.append('PyQt4.QtGui')
395
436
    includes.append('sip') # extension module required for Qt.
396
437
    packages.append('pygments') # colorizer for qbzr
397
438
    packages.append('docutils') # html formatting
398
 
    # but we can avoid many Qt4 Dlls.
399
 
    dll_excludes.extend(
400
 
        """QtAssistantClient4.dll QtCLucene4.dll QtDesigner4.dll
401
 
        QtHelp4.dll QtNetwork4.dll QtOpenGL4.dll QtScript4.dll
402
 
        QtSql4.dll QtTest4.dll QtWebKit4.dll QtXml4.dll
403
 
        qscintilla2.dll""".split())
 
439
    includes.append('win32event')  # for qsubprocess stuff
404
440
    # the qt binaries might not be on PATH...
405
 
    qt_dir = os.path.join(sys.prefix, "PyQt4", "bin")
406
 
    path = os.environ.get("PATH","")
407
 
    if qt_dir.lower() not in [p.lower() for p in path.split(os.pathsep)]:
408
 
        os.environ["PATH"] = path + os.pathsep + qt_dir
 
441
    # They seem to install to a place like C:\Python25\PyQt4\*
 
442
    # Which is not the same as C:\Python25\Lib\site-packages\PyQt4
 
443
    pyqt_dir = os.path.join(sys.prefix, "PyQt4")
 
444
    pyqt_bin_dir = os.path.join(pyqt_dir, "bin")
 
445
    if os.path.isdir(pyqt_bin_dir):
 
446
        path = os.environ.get("PATH", "")
 
447
        if pyqt_bin_dir.lower() not in [p.lower() for p in path.split(os.pathsep)]:
 
448
            os.environ["PATH"] = path + os.pathsep + pyqt_bin_dir
 
449
    # also add all imageformat plugins to distribution
 
450
    # We will look in 2 places, dirname(PyQt4.__file__) and pyqt_dir
 
451
    base_dirs_to_check = []
 
452
    if os.path.isdir(pyqt_dir):
 
453
        base_dirs_to_check.append(pyqt_dir)
 
454
    try:
 
455
        import PyQt4
 
456
    except ImportError:
 
457
        pass
 
458
    else:
 
459
        pyqt4_base_dir = os.path.dirname(PyQt4.__file__)
 
460
        if pyqt4_base_dir != pyqt_dir:
 
461
            base_dirs_to_check.append(pyqt4_base_dir)
 
462
    if not base_dirs_to_check:
 
463
        log.warn("Can't find PyQt4 installation -> not including imageformat"
 
464
                 " plugins")
 
465
    else:
 
466
        files = []
 
467
        for base_dir in base_dirs_to_check:
 
468
            plug_dir = os.path.join(base_dir, 'plugins', 'imageformats')
 
469
            if os.path.isdir(plug_dir):
 
470
                for fname in os.listdir(plug_dir):
 
471
                    # Include plugin dlls, but not debugging dlls
 
472
                    fullpath = os.path.join(plug_dir, fname)
 
473
                    if fname.endswith('.dll') and not fname.endswith('d4.dll'):
 
474
                        files.append(fullpath)
 
475
        if files:
 
476
            data_files.append(('imageformats', files))
 
477
        else:
 
478
            log.warn('PyQt4 was found, but we could not find any imageformat'
 
479
                     ' plugins. Are you sure your configuration is correct?')
 
480
 
 
481
 
 
482
def get_svn_py2exe_info(includes, excludes, packages):
 
483
    packages.append('subvertpy')
 
484
    packages.append('sqlite3')
 
485
 
 
486
 
 
487
def get_fastimport_py2exe_info(includes, excludes, packages):
 
488
    # This is the python-fastimport package, not to be confused with the
 
489
    # bzr-fastimport plugin.
 
490
    packages.append('fastimport')
409
491
 
410
492
 
411
493
if 'bdist_wininst' in sys.argv:
432
514
            # help pages
433
515
            'data_files': find_docs(),
434
516
            # for building pyrex extensions
435
 
            'cmdclass': {'build_ext': build_ext_if_possible},
 
517
            'cmdclass': command_classes,
436
518
           }
437
519
 
438
520
    ARGS.update(META_INFO)
439
521
    ARGS.update(BZRLIB)
 
522
    PKG_DATA['package_data']['bzrlib'].append('locale/*/LC_MESSAGES/*.mo')
440
523
    ARGS.update(PKG_DATA)
441
 
    
 
524
 
442
525
    setup(**ARGS)
443
526
 
444
527
elif 'py2exe' in sys.argv:
445
 
    import glob
446
528
    # py2exe setup
447
529
    import py2exe
448
530
 
469
551
            install_data.run(self)
470
552
 
471
553
            py2exe = self.distribution.get_command_obj('py2exe', False)
472
 
            optimize = py2exe.optimize
 
554
            # GZ 2010-04-19: Setup has py2exe.optimize as 2, but give plugins
 
555
            #                time before living with docstring stripping
 
556
            optimize = 1
473
557
            compile_names = [f for f in self.outfiles if f.endswith('.py')]
 
558
            # Round mtime to nearest even second so that installing on a FAT
 
559
            # filesystem bytecode internal and script timestamps will match
 
560
            for f in compile_names:
 
561
                mtime = os.stat(f).st_mtime
 
562
                remainder = mtime % 2
 
563
                if remainder:
 
564
                    mtime -= remainder
 
565
                    os.utime(f, (mtime, mtime))
474
566
            byte_compile(compile_names,
475
567
                         optimize=optimize,
476
568
                         force=self.force, prefix=self.install_dir,
477
569
                         dry_run=self.dry_run)
478
 
            if optimize:
479
 
                suffix = 'o'
480
 
            else:
481
 
                suffix = 'c'
482
 
            self.outfiles.extend([f + suffix for f in compile_names])
 
570
            self.outfiles.extend([f + 'o' for f in compile_names])
483
571
    # end of class install_data_with_bytecompile
484
572
 
485
573
    target = py2exe.build_exe.Target(script = "bzr",
489
577
                                     version = version_str,
490
578
                                     description = META_INFO['description'],
491
579
                                     author = META_INFO['author'],
492
 
                                     copyright = "(c) Canonical Ltd, 2005-2007",
 
580
                                     copyright = "(c) Canonical Ltd, 2005-2010",
493
581
                                     company_name = "Canonical Ltd.",
494
582
                                     comments = META_INFO['description'],
495
583
                                    )
 
584
    gui_target = copy.copy(target)
 
585
    gui_target.dest_base = "bzrw"
496
586
 
497
587
    packages = BZRLIB['packages']
498
588
    packages.remove('bzrlib')
508
598
    if sys.version.startswith('2.4'):
509
599
        # adding elementtree package
510
600
        additional_packages.add('elementtree')
511
 
    elif sys.version.startswith('2.5'):
 
601
    elif sys.version.startswith('2.6') or sys.version.startswith('2.5'):
512
602
        additional_packages.add('xml.etree')
513
603
    else:
514
604
        import warnings
522
612
                  ImaginaryModule cElementTree elementtree.ElementTree
523
613
                  Crypto.PublicKey._fastmath
524
614
                  medusa medusa.filesys medusa.ftp_server
525
 
                  tools tools.doc_generate
 
615
                  tools
526
616
                  resource validate""".split()
527
617
    dll_excludes = []
528
618
 
560
650
            excludes.extend(["bzrlib.plugins." + d for d in dirs])
561
651
        x = []
562
652
        for i in files:
563
 
            if os.path.splitext(i)[1] not in [".py", ".pyd", ".dll", ".mo"]:
 
653
            # Throw away files we don't want packaged. Note that plugins may
 
654
            # have data files with all sorts of extensions so we need to
 
655
            # be conservative here about what we ditch.
 
656
            ext = os.path.splitext(i)[1]
 
657
            if ext.endswith('~') or ext in [".pyc", ".swp"]:
564
658
                continue
565
659
            if i == '__init__.py' and root == 'bzrlib/plugins':
566
660
                continue
579
673
    console_targets = [target,
580
674
                       'tools/win32/bzr_postinstall.py',
581
675
                       ]
582
 
    gui_targets = []
583
 
    com_targets = []
584
 
    data_files = topics_files + plugins_files
 
676
    gui_targets = [gui_target]
 
677
    data_files = topics_files + plugins_files + I18N_FILES
585
678
 
586
679
    if 'qbzr' in plugins:
587
 
        get_qbzr_py2exe_info(includes, excludes, packages)
 
680
        get_qbzr_py2exe_info(includes, excludes, packages, data_files)
 
681
 
 
682
    if 'svn' in plugins:
 
683
        get_svn_py2exe_info(includes, excludes, packages)
 
684
 
 
685
    if 'fastimport' in plugins:
 
686
        get_fastimport_py2exe_info(includes, excludes, packages)
588
687
 
589
688
    if "TBZR" in os.environ:
590
689
        # TORTOISE_OVERLAYS_MSI_WIN32 must be set to the location of the
591
690
        # TortoiseOverlays MSI installer file. It is in the TSVN svn repo and
592
691
        # can be downloaded from (username=guest, blank password):
593
 
        # http://tortoisesvn.tigris.org/svn/tortoisesvn/TortoiseOverlays/version-1.0.4/bin/TortoiseOverlays-1.0.4.11886-win32.msi
 
692
        # http://tortoisesvn.tigris.org/svn/tortoisesvn/TortoiseOverlays
 
693
        # look for: version-1.0.4/bin/TortoiseOverlays-1.0.4.11886-win32.msi
594
694
        # Ditto for TORTOISE_OVERLAYS_MSI_X64, pointing at *-x64.msi.
595
695
        for needed in ('TORTOISE_OVERLAYS_MSI_WIN32',
596
696
                       'TORTOISE_OVERLAYS_MSI_X64'):
 
697
            url = ('http://guest:@tortoisesvn.tigris.org/svn/tortoisesvn'
 
698
                   '/TortoiseOverlays')
597
699
            if not os.path.isfile(os.environ.get(needed, '<nofile>')):
598
 
                raise RuntimeError("Please set %s to the"
599
 
                                   " location of the relevant TortoiseOverlays"
600
 
                                   " .msi installer file" % needed)
 
700
                raise RuntimeError(
 
701
                    "\nPlease set %s to the location of the relevant"
 
702
                    "\nTortoiseOverlays .msi installer file."
 
703
                    " The installers can be found at"
 
704
                    "\n  %s"
 
705
                    "\ncheck in the version-X.Y.Z/bin/ subdir" % (needed, url))
601
706
        get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
602
707
                             gui_targets, data_files)
603
708
    else:
604
709
        # print this warning to stderr as output is redirected, so it is seen
605
710
        # at build time.  Also to stdout so it appears in the log
606
711
        for f in (sys.stderr, sys.stdout):
607
 
            print >> f, \
608
 
                "Skipping TBZR binaries - please set TBZR to a directory to enable"
 
712
            f.write("Skipping TBZR binaries - "
 
713
                "please set TBZR to a directory to enable\n")
609
714
 
610
715
    # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls
611
716
    # in on Vista.
612
 
    dll_excludes.append("MSWSOCK.dll")
 
717
    dll_excludes.extend(["MSWSOCK.dll",
 
718
                         "MSVCP60.dll",
 
719
                         "MSVCP90.dll",
 
720
                         "powrprof.dll",
 
721
                         "SHFOLDER.dll"])
613
722
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
614
723
                               "includes": includes,
615
724
                               "excludes": excludes,
616
725
                               "dll_excludes": dll_excludes,
617
726
                               "dist_dir": "win32_bzr.exe",
618
 
                               "optimize": 1,
 
727
                               "optimize": 2,
 
728
                               "custom_boot_script":
 
729
                                        "tools/win32/py2exe_boot_common.py",
619
730
                              },
620
731
                   }
621
732
 
622
 
    setup(options=options_list,
623
 
          console=console_targets,
624
 
          windows=gui_targets,
625
 
          com_server=com_targets,
626
 
          zipfile='lib/library.zip',
627
 
          data_files=data_files,
628
 
          cmdclass={'install_data': install_data_with_bytecompile},
629
 
          )
 
733
    # We want the libaray.zip to have optimize = 2, but the exe to have
 
734
    # optimize = 1, so that .py files that get compilied at run time
 
735
    # (e.g. user installed plugins) dont have their doc strings removed.
 
736
    class py2exe_no_oo_exe(py2exe.build_exe.py2exe):
 
737
        def build_executable(self, *args, **kwargs):
 
738
            self.optimize = 1
 
739
            py2exe.build_exe.py2exe.build_executable(self, *args, **kwargs)
 
740
            self.optimize = 2
 
741
 
 
742
    if __name__ == '__main__':
 
743
        command_classes['install_data'] = install_data_with_bytecompile
 
744
        command_classes['py2exe'] = py2exe_no_oo_exe
 
745
        setup(options=options_list,
 
746
              console=console_targets,
 
747
              windows=gui_targets,
 
748
              zipfile='lib/library.zip',
 
749
              data_files=data_files,
 
750
              cmdclass=command_classes,
 
751
              )
630
752
 
631
753
else:
632
754
    # ad-hoc for easy_install
633
755
    DATA_FILES = []
634
756
    if not 'bdist_egg' in sys.argv:
635
 
        # generate and install bzr.1 only with plain install, not easy_install one
 
757
        # generate and install bzr.1 only with plain install, not the
 
758
        # easy_install one
636
759
        DATA_FILES = [('man/man1', ['bzr.1'])]
637
760
 
 
761
    DATA_FILES = DATA_FILES + I18N_FILES
638
762
    # std setup
639
763
    ARGS = {'scripts': ['bzr'],
640
764
            'data_files': DATA_FILES,
646
770
    ARGS.update(BZRLIB)
647
771
    ARGS.update(PKG_DATA)
648
772
 
649
 
    setup(**ARGS)
 
773
    if __name__ == '__main__':
 
774
        setup(**ARGS)