~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Andrew Bennetts
  • Date: 2009-12-03 02:24:54 UTC
  • mfrom: (4634.101.4 2.0)
  • mto: This revision was merged to the branch mainline in revision 4857.
  • Revision ID: andrew.bennetts@canonical.com-20091203022454-m2gyhbcdqi1t7ujz
Merge lp:bzr/2.0 into lp:bzr.

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-vcs.org/',
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 == '0.9.4.1':
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
        print 'Cannot build extension "bzrlib._dirstate_helpers_pyx" using'
 
291
        print 'your version of pyrex "%s". Please upgrade your pyrex' % (
 
292
            pyrex_version,)
 
293
        print 'install. For now, the non-compiled (python) version will'
 
294
        print 'be used instead.'
314
295
    else:
315
296
        add_pyrex_extension('bzrlib._dirstate_helpers_pyx')
316
297
    add_pyrex_extension('bzrlib._readdir_pyx')
317
 
add_pyrex_extension('bzrlib._chk_map_pyx')
 
298
    z_lib = 'z'
 
299
add_pyrex_extension('bzrlib._chk_map_pyx', libraries=[z_lib])
318
300
ext_modules.append(Extension('bzrlib._patiencediff_c',
319
301
                             ['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']))
 
302
add_pyrex_extension('bzrlib._simple_set_pyx')
 
303
ext_modules.append(Extension('bzrlib._static_tuple_c',
 
304
                             ['bzrlib/_static_tuple_c.c']))
334
305
add_pyrex_extension('bzrlib._btree_serializer_pyx')
335
306
 
336
307
 
337
308
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("")
 
309
    print 'C extension(s) not found:'
 
310
    print '   %s' % ('\n  '.join(unavailable_files),)
 
311
    print 'The python versions will be used instead.'
 
312
    print
342
313
 
343
314
 
344
315
def get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
408
379
    # ditto for the tbzrcommand tool
409
380
    tbzrcommand = dict(
410
381
        script = os.path.join(tbzr_root, "scripts", "tbzrcommand.py"),
411
 
        icon_resources = icon_resources,
412
 
        other_resources = other_resources,
 
382
        icon_resources = [(0,'bzr.ico')],
413
383
    )
414
384
    console_targets.append(tbzrcommand)
415
385
    tbzrcommandw = tbzrcommand.copy()
429
399
 
430
400
def get_qbzr_py2exe_info(includes, excludes, packages, data_files):
431
401
    # PyQt4 itself still escapes the plugin detection code for some reason...
432
 
    includes.append('PyQt4.QtCore')
433
 
    includes.append('PyQt4.QtGui')
 
402
    packages.append('PyQt4')
 
403
    excludes.append('PyQt4.elementtree.ElementTree')
434
404
    includes.append('sip') # extension module required for Qt.
435
405
    packages.append('pygments') # colorizer for qbzr
436
406
    packages.append('docutils') # html formatting
437
407
    includes.append('win32event')  # for qsubprocess stuff
 
408
    # but we can avoid many Qt4 Dlls.
 
409
    dll_excludes.extend(
 
410
        """QtAssistantClient4.dll QtCLucene4.dll QtDesigner4.dll
 
411
        QtHelp4.dll QtNetwork4.dll QtOpenGL4.dll QtScript4.dll
 
412
        QtSql4.dll QtTest4.dll QtWebKit4.dll QtXml4.dll
 
413
        qscintilla2.dll""".split())
438
414
    # the qt binaries might not be on PATH...
439
415
    # They seem to install to a place like C:\Python25\PyQt4\*
440
416
    # Which is not the same as C:\Python25\Lib\site-packages\PyQt4
479
455
 
480
456
def get_svn_py2exe_info(includes, excludes, packages):
481
457
    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
458
 
494
459
 
495
460
if 'bdist_wininst' in sys.argv:
516
481
            # help pages
517
482
            'data_files': find_docs(),
518
483
            # for building pyrex extensions
519
 
            'cmdclass': command_classes,
 
484
            'cmdclass': {'build_ext': build_ext_if_possible},
520
485
           }
521
486
 
522
487
    ARGS.update(META_INFO)
523
488
    ARGS.update(BZRLIB)
524
 
    PKG_DATA['package_data']['bzrlib'].append('locale/*/LC_MESSAGES/*.mo')
525
489
    ARGS.update(PKG_DATA)
526
 
 
 
490
    
527
491
    setup(**ARGS)
528
492
 
529
493
elif 'py2exe' in sys.argv:
 
494
    import glob
530
495
    # py2exe setup
531
496
    import py2exe
532
497
 
553
518
            install_data.run(self)
554
519
 
555
520
            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
 
521
            optimize = py2exe.optimize
559
522
            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
523
            byte_compile(compile_names,
569
524
                         optimize=optimize,
570
525
                         force=self.force, prefix=self.install_dir,
571
526
                         dry_run=self.dry_run)
572
 
            self.outfiles.extend([f + 'o' for f in compile_names])
 
527
            if optimize:
 
528
                suffix = 'o'
 
529
            else:
 
530
                suffix = 'c'
 
531
            self.outfiles.extend([f + suffix for f in compile_names])
573
532
    # end of class install_data_with_bytecompile
574
533
 
575
534
    target = py2exe.build_exe.Target(script = "bzr",
579
538
                                     version = version_str,
580
539
                                     description = META_INFO['description'],
581
540
                                     author = META_INFO['author'],
582
 
                                     copyright = "(c) Canonical Ltd, 2005-2010",
 
541
                                     copyright = "(c) Canonical Ltd, 2005-2009",
583
542
                                     company_name = "Canonical Ltd.",
584
543
                                     comments = META_INFO['description'],
585
544
                                    )
586
 
    gui_target = copy.copy(target)
587
 
    gui_target.dest_base = "bzrw"
588
545
 
589
546
    packages = BZRLIB['packages']
590
547
    packages.remove('bzrlib')
600
557
    if sys.version.startswith('2.4'):
601
558
        # adding elementtree package
602
559
        additional_packages.add('elementtree')
603
 
    elif sys.version.startswith('2.6') or sys.version.startswith('2.5'):
 
560
    elif sys.version.startswith('2.5'):
604
561
        additional_packages.add('xml.etree')
605
562
    else:
606
563
        import warnings
652
609
            excludes.extend(["bzrlib.plugins." + d for d in dirs])
653
610
        x = []
654
611
        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"]:
 
612
            if os.path.splitext(i)[1] not in [".py", ".pyd", ".dll", ".mo"]:
660
613
                continue
661
614
            if i == '__init__.py' and root == 'bzrlib/plugins':
662
615
                continue
675
628
    console_targets = [target,
676
629
                       'tools/win32/bzr_postinstall.py',
677
630
                       ]
678
 
    gui_targets = [gui_target]
679
 
    data_files = topics_files + plugins_files + I18N_FILES
 
631
    gui_targets = []
 
632
    data_files = topics_files + plugins_files
680
633
 
681
634
    if 'qbzr' in plugins:
682
635
        get_qbzr_py2exe_info(includes, excludes, packages, data_files)
684
637
    if 'svn' in plugins:
685
638
        get_svn_py2exe_info(includes, excludes, packages)
686
639
 
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
640
    if "TBZR" in os.environ:
694
641
        # TORTOISE_OVERLAYS_MSI_WIN32 must be set to the location of the
695
642
        # TortoiseOverlays MSI installer file. It is in the TSVN svn repo and
714
661
        # print this warning to stderr as output is redirected, so it is seen
715
662
        # at build time.  Also to stdout so it appears in the log
716
663
        for f in (sys.stderr, sys.stdout):
717
 
            f.write("Skipping TBZR binaries - "
718
 
                "please set TBZR to a directory to enable\n")
 
664
            print >> f, \
 
665
                "Skipping TBZR binaries - please set TBZR to a directory to enable"
719
666
 
720
667
    # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls
721
668
    # in on Vista.
722
 
    dll_excludes.extend(["MSWSOCK.dll",
723
 
                         "MSVCP60.dll",
724
 
                         "MSVCP90.dll",
725
 
                         "powrprof.dll",
726
 
                         "SHFOLDER.dll"])
 
669
    dll_excludes.extend(["MSWSOCK.dll", "MSVCP60.dll", "powrprof.dll"])
727
670
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
728
671
                               "includes": includes,
729
672
                               "excludes": excludes,
730
673
                               "dll_excludes": dll_excludes,
731
674
                               "dist_dir": "win32_bzr.exe",
732
 
                               "optimize": 2,
733
 
                               "custom_boot_script":
734
 
                                        "tools/win32/py2exe_boot_common.py",
 
675
                               "optimize": 1,
735
676
                              },
736
677
                   }
737
678
 
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
 
              )
 
679
    setup(options=options_list,
 
680
          console=console_targets,
 
681
          windows=gui_targets,
 
682
          zipfile='lib/library.zip',
 
683
          data_files=data_files,
 
684
          cmdclass={'install_data': install_data_with_bytecompile},
 
685
          )
757
686
 
758
687
else:
759
688
    # ad-hoc for easy_install
763
692
        # easy_install one
764
693
        DATA_FILES = [('man/man1', ['bzr.1'])]
765
694
 
766
 
    DATA_FILES = DATA_FILES + I18N_FILES
767
695
    # std setup
768
696
    ARGS = {'scripts': ['bzr'],
769
697
            'data_files': DATA_FILES,
775
703
    ARGS.update(BZRLIB)
776
704
    ARGS.update(PKG_DATA)
777
705
 
778
 
    if __name__ == '__main__':
779
 
        setup(**ARGS)
 
706
    setup(**ARGS)