~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-03 10:06:19 UTC
  • mfrom: (4999.3.2 apport)
  • Revision ID: pqm@pqm.ubuntu.com-20100203100619-f76bo5y5bd5c14wk
(mbp) use apport to send bugs, not just store them

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
14
12
 
15
 
if sys.version_info < (2, 6):
16
 
    sys.stderr.write("[ERROR] Not a supported Python version. Need 2.6+\n")
 
13
if sys.version_info < (2, 4):
 
14
    sys.stderr.write("[ERROR] Not a supported Python version. Need 2.4+\n")
17
15
    sys.exit(1)
18
16
 
19
17
# NOTE: The directory containing setup.py, whether run by 'python setup.py' or
39
37
    'version':      bzrlib.__version__,
40
38
    'author':       'Canonical Ltd',
41
39
    'author_email': 'bazaar@lists.canonical.com',
42
 
    'url':          'http://bazaar.canonical.com/',
 
40
    'url':          'http://www.bazaar.canonical.com/',
43
41
    'description':  'Friendly distributed version control system',
44
42
    'license':      'GNU GPL v2',
45
43
    'download_url': 'https://launchpad.net/bzr/+download',
67
65
            'package_data': {'bzrlib': ['doc/api/*.txt',
68
66
                                        'tests/test_patches_data/*',
69
67
                                        'help_topics/en/*.txt',
70
 
                                        'tests/ssl_certs/ca.crt',
71
68
                                        'tests/ssl_certs/server_without_pass.key',
72
69
                                        'tests/ssl_certs/server_with_pass.key',
73
 
                                        'tests/ssl_certs/server.crt',
 
70
                                        'tests/ssl_certs/server.crt'
74
71
                                       ]},
75
72
           }
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]))
 
73
 
81
74
 
82
75
def get_bzrlib_packages():
83
76
    """Recurse through the bzrlib directory, and extract the package names"""
132
125
                f = file(batch_path, "w")
133
126
                f.write(batch_str)
134
127
                f.close()
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))
 
128
                print "Created:", batch_path
 
129
            except Exception, e:
 
130
                print "ERROR: Unable to create %s: %s" % (batch_path, e)
139
131
 
140
132
    def _quoted_path(self, path):
141
133
        if ' ' in path:
157
149
    Generate bzr.1.
158
150
    """
159
151
 
160
 
    sub_commands = build.sub_commands + [
161
 
            ('build_mo', lambda _: True),
162
 
            ]
163
 
 
164
152
    def run(self):
165
153
        build.run(self)
166
154
 
172
160
## Setup
173
161
########################
174
162
 
175
 
from bzrlib.bzr_distutils import build_mo
176
 
 
177
163
command_classes = {'install_scripts': my_install_scripts,
178
 
                   'build': bzr_build,
179
 
                   'build_mo': build_mo,
180
 
                   }
 
164
                   'build': bzr_build}
181
165
from distutils import log
182
166
from distutils.errors import CCompilerError, DistutilsPlatformError
183
167
from distutils.extension import Extension
184
168
ext_modules = []
185
169
try:
186
170
    try:
 
171
        from Pyrex.Distutils import build_ext
 
172
        from Pyrex.Compiler.Version import version as pyrex_version
 
173
    except ImportError:
 
174
        print "No Pyrex, trying Cython..."
187
175
        from Cython.Distutils import build_ext
188
176
        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
193
177
except ImportError:
194
178
    have_pyrex = False
195
179
    # try to build the extension from the prior generated source.
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("")
 
180
    print
 
181
    print ("The python package 'Pyrex' is not available."
 
182
           " If the .c files are available,")
 
183
    print ("they will be built,"
 
184
           " but modifying the .pyx files will not rebuild them.")
 
185
    print
202
186
    from distutils.command.build_ext import build_ext
203
187
else:
204
188
    have_pyrex = True
205
 
    pyrex_version_info = tuple(map(int, pyrex_version.rstrip("+").split('.')))
206
189
 
207
190
 
208
191
class build_ext_if_possible(build_ext):
220
203
    def run(self):
221
204
        try:
222
205
            build_ext.run(self)
223
 
        except DistutilsPlatformError:
224
 
            e = sys.exc_info()[1]
 
206
        except DistutilsPlatformError, e:
225
207
            if not self.allow_python_fallback:
226
208
                log.warn('\n  Cannot build extensions.\n'
227
209
                         '  Use "build_ext --allow-python-fallback" to use'
298
280
    add_pyrex_extension('bzrlib._dirstate_helpers_pyx',
299
281
                        libraries=['Ws2_32'])
300
282
    add_pyrex_extension('bzrlib._walkdirs_win32')
 
283
    z_lib = 'zdll'
301
284
else:
302
 
    if have_pyrex and pyrex_version_info[:3] == (0,9,4):
 
285
    if have_pyrex and pyrex_version.startswith('0.9.4'):
303
286
        # Pyrex 0.9.4.1 fails to compile this extension correctly
304
287
        # The code it generates re-uses a "local" pointer and
305
288
        # calls "PY_DECREF" after having set it to NULL. (It mixes PY_XDECREF
306
289
        # which is NULL safe with PY_DECREF which is not.)
307
 
        # <https://bugs.launchpad.net/bzr/+bug/449372>
308
 
        # <https://bugs.launchpad.net/bzr/+bug/276868>
309
 
        print('Cannot build extension "bzrlib._dirstate_helpers_pyx" using')
310
 
        print('your version of pyrex "%s". Please upgrade your pyrex'
311
 
              % (pyrex_version,))
312
 
        print('install. For now, the non-compiled (python) version will')
313
 
        print('be used instead.')
 
290
        # <https://bugs.edge.launchpad.net/bzr/+bug/449372>
 
291
        # <https://bugs.edge.launchpad.net/bzr/+bug/276868>
 
292
        print 'Cannot build extension "bzrlib._dirstate_helpers_pyx" using'
 
293
        print 'your version of pyrex "%s". Please upgrade your pyrex' % (
 
294
            pyrex_version,)
 
295
        print 'install. For now, the non-compiled (python) version will'
 
296
        print 'be used instead.'
314
297
    else:
315
298
        add_pyrex_extension('bzrlib._dirstate_helpers_pyx')
316
299
    add_pyrex_extension('bzrlib._readdir_pyx')
317
 
add_pyrex_extension('bzrlib._chk_map_pyx')
 
300
    z_lib = 'z'
 
301
add_pyrex_extension('bzrlib._chk_map_pyx', libraries=[z_lib])
318
302
ext_modules.append(Extension('bzrlib._patiencediff_c',
319
303
                             ['bzrlib/_patiencediff_c.c']))
320
 
if have_pyrex and pyrex_version_info < (0, 9, 6, 3):
321
 
    print("")
322
 
    print('Your Pyrex/Cython version %s is too old to build the simple_set' % (
323
 
        pyrex_version))
324
 
    print('and static_tuple extensions.')
325
 
    print('Please upgrade to at least Pyrex 0.9.6.3')
326
 
    print("")
327
 
    # TODO: Should this be a fatal error?
328
 
else:
329
 
    # We only need 0.9.6.3 to build _simple_set_pyx, but static_tuple depends
330
 
    # on simple_set
331
 
    add_pyrex_extension('bzrlib._simple_set_pyx')
332
 
    ext_modules.append(Extension('bzrlib._static_tuple_c',
333
 
                                 ['bzrlib/_static_tuple_c.c']))
 
304
add_pyrex_extension('bzrlib._simple_set_pyx')
 
305
ext_modules.append(Extension('bzrlib._static_tuple_c',
 
306
                             ['bzrlib/_static_tuple_c.c']))
334
307
add_pyrex_extension('bzrlib._btree_serializer_pyx')
335
308
 
336
309
 
337
310
if unavailable_files:
338
 
    print('C extension(s) not found:')
339
 
    print('   %s' % ('\n  '.join(unavailable_files),))
340
 
    print('The python versions will be used instead.')
341
 
    print("")
 
311
    print 'C extension(s) not found:'
 
312
    print '   %s' % ('\n  '.join(unavailable_files),)
 
313
    print 'The python versions will be used instead.'
 
314
    print
342
315
 
343
316
 
344
317
def get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
408
381
    # ditto for the tbzrcommand tool
409
382
    tbzrcommand = dict(
410
383
        script = os.path.join(tbzr_root, "scripts", "tbzrcommand.py"),
411
 
        icon_resources = icon_resources,
412
 
        other_resources = other_resources,
 
384
        icon_resources = [(0,'bzr.ico')],
413
385
    )
414
386
    console_targets.append(tbzrcommand)
415
387
    tbzrcommandw = tbzrcommand.copy()
429
401
 
430
402
def get_qbzr_py2exe_info(includes, excludes, packages, data_files):
431
403
    # PyQt4 itself still escapes the plugin detection code for some reason...
432
 
    includes.append('PyQt4.QtCore')
433
 
    includes.append('PyQt4.QtGui')
 
404
    packages.append('PyQt4')
 
405
    excludes.append('PyQt4.elementtree.ElementTree')
 
406
    excludes.append('PyQt4.uic.port_v3')
434
407
    includes.append('sip') # extension module required for Qt.
435
408
    packages.append('pygments') # colorizer for qbzr
436
409
    packages.append('docutils') # html formatting
437
410
    includes.append('win32event')  # for qsubprocess stuff
 
411
    # but we can avoid many Qt4 Dlls.
 
412
    dll_excludes.extend(
 
413
        """QtAssistantClient4.dll QtCLucene4.dll QtDesigner4.dll
 
414
        QtHelp4.dll QtNetwork4.dll QtOpenGL4.dll QtScript4.dll
 
415
        QtSql4.dll QtTest4.dll QtWebKit4.dll QtXml4.dll
 
416
        qscintilla2.dll""".split())
438
417
    # the qt binaries might not be on PATH...
439
418
    # They seem to install to a place like C:\Python25\PyQt4\*
440
419
    # Which is not the same as C:\Python25\Lib\site-packages\PyQt4
479
458
 
480
459
def get_svn_py2exe_info(includes, excludes, packages):
481
460
    packages.append('subvertpy')
482
 
    packages.append('sqlite3')
483
 
 
484
 
 
485
 
def get_git_py2exe_info(includes, excludes, packages):
486
 
    packages.append('dulwich')
487
 
 
488
 
 
489
 
def get_fastimport_py2exe_info(includes, excludes, packages):
490
 
    # This is the python-fastimport package, not to be confused with the
491
 
    # bzr-fastimport plugin.
492
 
    packages.append('fastimport')
493
461
 
494
462
 
495
463
if 'bdist_wininst' in sys.argv:
516
484
            # help pages
517
485
            'data_files': find_docs(),
518
486
            # for building pyrex extensions
519
 
            'cmdclass': command_classes,
 
487
            'cmdclass': {'build_ext': build_ext_if_possible},
520
488
           }
521
489
 
522
490
    ARGS.update(META_INFO)
523
491
    ARGS.update(BZRLIB)
524
 
    PKG_DATA['package_data']['bzrlib'].append('locale/*/LC_MESSAGES/*.mo')
525
492
    ARGS.update(PKG_DATA)
526
 
 
 
493
    
527
494
    setup(**ARGS)
528
495
 
529
496
elif 'py2exe' in sys.argv:
 
497
    import glob
530
498
    # py2exe setup
531
499
    import py2exe
532
500
 
553
521
            install_data.run(self)
554
522
 
555
523
            py2exe = self.distribution.get_command_obj('py2exe', False)
556
 
            # GZ 2010-04-19: Setup has py2exe.optimize as 2, but give plugins
557
 
            #                time before living with docstring stripping
558
 
            optimize = 1
 
524
            optimize = py2exe.optimize
559
525
            compile_names = [f for f in self.outfiles if f.endswith('.py')]
560
 
            # Round mtime to nearest even second so that installing on a FAT
561
 
            # filesystem bytecode internal and script timestamps will match
562
 
            for f in compile_names:
563
 
                mtime = os.stat(f).st_mtime
564
 
                remainder = mtime % 2
565
 
                if remainder:
566
 
                    mtime -= remainder
567
 
                    os.utime(f, (mtime, mtime))
568
526
            byte_compile(compile_names,
569
527
                         optimize=optimize,
570
528
                         force=self.force, prefix=self.install_dir,
571
529
                         dry_run=self.dry_run)
572
 
            self.outfiles.extend([f + 'o' for f in compile_names])
 
530
            if optimize:
 
531
                suffix = 'o'
 
532
            else:
 
533
                suffix = 'c'
 
534
            self.outfiles.extend([f + suffix for f in compile_names])
573
535
    # end of class install_data_with_bytecompile
574
536
 
575
537
    target = py2exe.build_exe.Target(script = "bzr",
579
541
                                     version = version_str,
580
542
                                     description = META_INFO['description'],
581
543
                                     author = META_INFO['author'],
582
 
                                     copyright = "(c) Canonical Ltd, 2005-2010",
 
544
                                     copyright = "(c) Canonical Ltd, 2005-2009",
583
545
                                     company_name = "Canonical Ltd.",
584
546
                                     comments = META_INFO['description'],
585
547
                                    )
586
 
    gui_target = copy.copy(target)
587
 
    gui_target.dest_base = "bzrw"
588
548
 
589
549
    packages = BZRLIB['packages']
590
550
    packages.remove('bzrlib')
600
560
    if sys.version.startswith('2.4'):
601
561
        # adding elementtree package
602
562
        additional_packages.add('elementtree')
603
 
    elif sys.version.startswith('2.6') or sys.version.startswith('2.5'):
 
563
    elif sys.version.startswith('2.5'):
604
564
        additional_packages.add('xml.etree')
605
565
    else:
606
566
        import warnings
652
612
            excludes.extend(["bzrlib.plugins." + d for d in dirs])
653
613
        x = []
654
614
        for i in files:
655
 
            # Throw away files we don't want packaged. Note that plugins may
656
 
            # have data files with all sorts of extensions so we need to
657
 
            # be conservative here about what we ditch.
658
 
            ext = os.path.splitext(i)[1]
659
 
            if ext.endswith('~') or ext in [".pyc", ".swp"]:
 
615
            if os.path.splitext(i)[1] not in [".py", ".pyd", ".dll", ".mo"]:
660
616
                continue
661
617
            if i == '__init__.py' and root == 'bzrlib/plugins':
662
618
                continue
675
631
    console_targets = [target,
676
632
                       'tools/win32/bzr_postinstall.py',
677
633
                       ]
678
 
    gui_targets = [gui_target]
679
 
    data_files = topics_files + plugins_files + I18N_FILES
 
634
    gui_targets = []
 
635
    data_files = topics_files + plugins_files
680
636
 
681
637
    if 'qbzr' in plugins:
682
638
        get_qbzr_py2exe_info(includes, excludes, packages, data_files)
684
640
    if 'svn' in plugins:
685
641
        get_svn_py2exe_info(includes, excludes, packages)
686
642
 
687
 
    if 'git' in plugins:
688
 
        get_git_py2exe_info(includes, excludes, packages)
689
 
 
690
 
    if 'fastimport' in plugins:
691
 
        get_fastimport_py2exe_info(includes, excludes, packages)
692
 
 
693
643
    if "TBZR" in os.environ:
694
644
        # TORTOISE_OVERLAYS_MSI_WIN32 must be set to the location of the
695
645
        # TortoiseOverlays MSI installer file. It is in the TSVN svn repo and
714
664
        # print this warning to stderr as output is redirected, so it is seen
715
665
        # at build time.  Also to stdout so it appears in the log
716
666
        for f in (sys.stderr, sys.stdout):
717
 
            f.write("Skipping TBZR binaries - "
718
 
                "please set TBZR to a directory to enable\n")
 
667
            print >> f, \
 
668
                "Skipping TBZR binaries - please set TBZR to a directory to enable"
719
669
 
720
670
    # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls
721
671
    # in on Vista.
722
 
    dll_excludes.extend(["MSWSOCK.dll",
723
 
                         "MSVCP60.dll",
724
 
                         "MSVCP90.dll",
725
 
                         "powrprof.dll",
726
 
                         "SHFOLDER.dll"])
 
672
    dll_excludes.extend(["MSWSOCK.dll", "MSVCP60.dll", "powrprof.dll"])
727
673
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
728
674
                               "includes": includes,
729
675
                               "excludes": excludes,
730
676
                               "dll_excludes": dll_excludes,
731
677
                               "dist_dir": "win32_bzr.exe",
732
 
                               "optimize": 2,
733
 
                               "custom_boot_script":
734
 
                                        "tools/win32/py2exe_boot_common.py",
 
678
                               "optimize": 1,
735
679
                              },
736
680
                   }
737
681
 
738
 
    # We want the libaray.zip to have optimize = 2, but the exe to have
739
 
    # optimize = 1, so that .py files that get compilied at run time
740
 
    # (e.g. user installed plugins) dont have their doc strings removed.
741
 
    class py2exe_no_oo_exe(py2exe.build_exe.py2exe):
742
 
        def build_executable(self, *args, **kwargs):
743
 
            self.optimize = 1
744
 
            py2exe.build_exe.py2exe.build_executable(self, *args, **kwargs)
745
 
            self.optimize = 2
746
 
 
747
 
    if __name__ == '__main__':
748
 
        command_classes['install_data'] = install_data_with_bytecompile
749
 
        command_classes['py2exe'] = py2exe_no_oo_exe
750
 
        setup(options=options_list,
751
 
              console=console_targets,
752
 
              windows=gui_targets,
753
 
              zipfile='lib/library.zip',
754
 
              data_files=data_files,
755
 
              cmdclass=command_classes,
756
 
              )
 
682
    setup(options=options_list,
 
683
          console=console_targets,
 
684
          windows=gui_targets,
 
685
          zipfile='lib/library.zip',
 
686
          data_files=data_files,
 
687
          cmdclass={'install_data': install_data_with_bytecompile},
 
688
          )
757
689
 
758
690
else:
759
691
    # ad-hoc for easy_install
763
695
        # easy_install one
764
696
        DATA_FILES = [('man/man1', ['bzr.1'])]
765
697
 
766
 
    DATA_FILES = DATA_FILES + I18N_FILES
767
698
    # std setup
768
699
    ARGS = {'scripts': ['bzr'],
769
700
            'data_files': DATA_FILES,
775
706
    ARGS.update(BZRLIB)
776
707
    ARGS.update(PKG_DATA)
777
708
 
778
 
    if __name__ == '__main__':
779
 
        setup(**ARGS)
 
709
    setup(**ARGS)