~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Launchpad Translations on behalf of bzr-core
  • Date: 2012-12-24 04:30:21 UTC
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: launchpad_translations_on_behalf_of_bzr-core-20121224043021-0jvs6d37i2eagv7x
Launchpad automatic translations update.

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
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',
68
71
                                        'tests/ssl_certs/server_without_pass.key',
69
72
                                        'tests/ssl_certs/server_with_pass.key',
70
 
                                        'tests/ssl_certs/server.crt'
 
73
                                        'tests/ssl_certs/server.crt',
71
74
                                       ]},
72
75
           }
73
 
 
 
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]))
74
81
 
75
82
def get_bzrlib_packages():
76
83
    """Recurse through the bzrlib directory, and extract the package names"""
125
132
                f = file(batch_path, "w")
126
133
                f.write(batch_str)
127
134
                f.close()
128
 
                print "Created:", batch_path
129
 
            except Exception, e:
130
 
                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))
131
139
 
132
140
    def _quoted_path(self, path):
133
141
        if ' ' in path:
149
157
    Generate bzr.1.
150
158
    """
151
159
 
 
160
    sub_commands = build.sub_commands + [
 
161
            ('build_mo', lambda _: True),
 
162
            ]
 
163
 
152
164
    def run(self):
153
165
        build.run(self)
154
166
 
160
172
## Setup
161
173
########################
162
174
 
 
175
from bzrlib.bzr_distutils import build_mo
 
176
 
163
177
command_classes = {'install_scripts': my_install_scripts,
164
 
                   'build': bzr_build}
 
178
                   'build': bzr_build,
 
179
                   'build_mo': build_mo,
 
180
                   }
165
181
from distutils import log
166
182
from distutils.errors import CCompilerError, DistutilsPlatformError
167
183
from distutils.extension import Extension
168
184
ext_modules = []
169
185
try:
170
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...")
171
191
        from Pyrex.Distutils import build_ext
172
192
        from Pyrex.Compiler.Version import version as pyrex_version
173
 
    except ImportError:
174
 
        print "No Pyrex, trying Cython..."
175
 
        from Cython.Distutils import build_ext
176
 
        from Cython.Compiler.Version import version as pyrex_version
177
193
except ImportError:
178
194
    have_pyrex = False
179
195
    # try to build the extension from the prior generated source.
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
 
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("")
186
202
    from distutils.command.build_ext import build_ext
187
203
else:
188
204
    have_pyrex = True
189
 
    pyrex_version_info = tuple(map(int, pyrex_version.split('.')))
 
205
    pyrex_version_info = tuple(map(int, pyrex_version.rstrip("+").split('.')))
190
206
 
191
207
 
192
208
class build_ext_if_possible(build_ext):
204
220
    def run(self):
205
221
        try:
206
222
            build_ext.run(self)
207
 
        except DistutilsPlatformError, e:
 
223
        except DistutilsPlatformError:
 
224
            e = sys.exc_info()[1]
208
225
            if not self.allow_python_fallback:
209
226
                log.warn('\n  Cannot build extensions.\n'
210
227
                         '  Use "build_ext --allow-python-fallback" to use'
287
304
        # The code it generates re-uses a "local" pointer and
288
305
        # calls "PY_DECREF" after having set it to NULL. (It mixes PY_XDECREF
289
306
        # which is NULL safe with PY_DECREF which is not.)
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.'
 
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.')
297
314
    else:
298
315
        add_pyrex_extension('bzrlib._dirstate_helpers_pyx')
299
316
    add_pyrex_extension('bzrlib._readdir_pyx')
301
318
ext_modules.append(Extension('bzrlib._patiencediff_c',
302
319
                             ['bzrlib/_patiencediff_c.c']))
303
320
if have_pyrex and pyrex_version_info < (0, 9, 6, 3):
304
 
    print
305
 
    print 'Your Pyrex/Cython version %s is too old to build the simple_set' % (
306
 
        pyrex_version)
307
 
    print 'and static_tuple extensions.'
308
 
    print 'Please upgrade to at least Pyrex 0.9.6.3'
309
 
    print
 
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("")
310
327
    # TODO: Should this be a fatal error?
311
328
else:
312
329
    # We only need 0.9.6.3 to build _simple_set_pyx, but static_tuple depends
318
335
 
319
336
 
320
337
if unavailable_files:
321
 
    print 'C extension(s) not found:'
322
 
    print '   %s' % ('\n  '.join(unavailable_files),)
323
 
    print 'The python versions will be used instead.'
324
 
    print
 
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("")
325
342
 
326
343
 
327
344
def get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
391
408
    # ditto for the tbzrcommand tool
392
409
    tbzrcommand = dict(
393
410
        script = os.path.join(tbzr_root, "scripts", "tbzrcommand.py"),
394
 
        icon_resources = [(0,'bzr.ico')],
 
411
        icon_resources = icon_resources,
 
412
        other_resources = other_resources,
395
413
    )
396
414
    console_targets.append(tbzrcommand)
397
415
    tbzrcommandw = tbzrcommand.copy()
411
429
 
412
430
def get_qbzr_py2exe_info(includes, excludes, packages, data_files):
413
431
    # PyQt4 itself still escapes the plugin detection code for some reason...
414
 
    packages.append('PyQt4')
415
 
    excludes.append('PyQt4.elementtree.ElementTree')
416
 
    excludes.append('PyQt4.uic.port_v3')
 
432
    includes.append('PyQt4.QtCore')
 
433
    includes.append('PyQt4.QtGui')
 
434
    includes.append('PyQt4.QtTest')
417
435
    includes.append('sip') # extension module required for Qt.
418
436
    packages.append('pygments') # colorizer for qbzr
419
437
    packages.append('docutils') # html formatting
420
438
    includes.append('win32event')  # for qsubprocess stuff
421
 
    # but we can avoid many Qt4 Dlls.
422
 
    dll_excludes.extend(
423
 
        """QtAssistantClient4.dll QtCLucene4.dll QtDesigner4.dll
424
 
        QtHelp4.dll QtNetwork4.dll QtOpenGL4.dll QtScript4.dll
425
 
        QtSql4.dll QtTest4.dll QtWebKit4.dll QtXml4.dll
426
 
        qscintilla2.dll""".split())
427
439
    # the qt binaries might not be on PATH...
428
440
    # They seem to install to a place like C:\Python25\PyQt4\*
429
441
    # Which is not the same as C:\Python25\Lib\site-packages\PyQt4
471
483
    packages.append('sqlite3')
472
484
 
473
485
 
 
486
def get_git_py2exe_info(includes, excludes, packages):
 
487
    packages.append('dulwich')
 
488
 
 
489
 
 
490
def get_fastimport_py2exe_info(includes, excludes, packages):
 
491
    # This is the python-fastimport package, not to be confused with the
 
492
    # bzr-fastimport plugin.
 
493
    packages.append('fastimport')
 
494
 
 
495
 
474
496
if 'bdist_wininst' in sys.argv:
475
497
    def find_docs():
476
498
        docs = []
495
517
            # help pages
496
518
            'data_files': find_docs(),
497
519
            # for building pyrex extensions
498
 
            'cmdclass': {'build_ext': build_ext_if_possible},
 
520
            'cmdclass': command_classes,
499
521
           }
500
522
 
501
523
    ARGS.update(META_INFO)
502
524
    ARGS.update(BZRLIB)
 
525
    PKG_DATA['package_data']['bzrlib'].append('locale/*/LC_MESSAGES/*.mo')
503
526
    ARGS.update(PKG_DATA)
504
 
    
 
527
 
505
528
    setup(**ARGS)
506
529
 
507
530
elif 'py2exe' in sys.argv:
508
 
    import glob
509
531
    # py2exe setup
510
532
    import py2exe
511
533
 
536
558
            #                time before living with docstring stripping
537
559
            optimize = 1
538
560
            compile_names = [f for f in self.outfiles if f.endswith('.py')]
 
561
            # Round mtime to nearest even second so that installing on a FAT
 
562
            # filesystem bytecode internal and script timestamps will match
 
563
            for f in compile_names:
 
564
                mtime = os.stat(f).st_mtime
 
565
                remainder = mtime % 2
 
566
                if remainder:
 
567
                    mtime -= remainder
 
568
                    os.utime(f, (mtime, mtime))
539
569
            byte_compile(compile_names,
540
570
                         optimize=optimize,
541
571
                         force=self.force, prefix=self.install_dir,
554
584
                                     company_name = "Canonical Ltd.",
555
585
                                     comments = META_INFO['description'],
556
586
                                    )
 
587
    gui_target = copy.copy(target)
 
588
    gui_target.dest_base = "bzrw"
557
589
 
558
590
    packages = BZRLIB['packages']
559
591
    packages.remove('bzrlib')
644
676
    console_targets = [target,
645
677
                       'tools/win32/bzr_postinstall.py',
646
678
                       ]
647
 
    gui_targets = []
648
 
    data_files = topics_files + plugins_files
 
679
    gui_targets = [gui_target]
 
680
    data_files = topics_files + plugins_files + I18N_FILES
649
681
 
650
682
    if 'qbzr' in plugins:
651
683
        get_qbzr_py2exe_info(includes, excludes, packages, data_files)
653
685
    if 'svn' in plugins:
654
686
        get_svn_py2exe_info(includes, excludes, packages)
655
687
 
 
688
    if 'git' in plugins:
 
689
        get_git_py2exe_info(includes, excludes, packages)
 
690
 
 
691
    if 'fastimport' in plugins:
 
692
        get_fastimport_py2exe_info(includes, excludes, packages)
 
693
 
656
694
    if "TBZR" in os.environ:
657
695
        # TORTOISE_OVERLAYS_MSI_WIN32 must be set to the location of the
658
696
        # TortoiseOverlays MSI installer file. It is in the TSVN svn repo and
677
715
        # print this warning to stderr as output is redirected, so it is seen
678
716
        # at build time.  Also to stdout so it appears in the log
679
717
        for f in (sys.stderr, sys.stdout):
680
 
            print >> f, \
681
 
                "Skipping TBZR binaries - please set TBZR to a directory to enable"
 
718
            f.write("Skipping TBZR binaries - "
 
719
                "please set TBZR to a directory to enable\n")
682
720
 
683
721
    # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls
684
722
    # in on Vista.
685
 
    dll_excludes.extend(["MSWSOCK.dll", "MSVCP60.dll", "powrprof.dll"])
 
723
    dll_excludes.extend(["MSWSOCK.dll",
 
724
                         "MSVCP60.dll",
 
725
                         "MSVCP90.dll",
 
726
                         "powrprof.dll",
 
727
                         "SHFOLDER.dll"])
686
728
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
687
729
                               "includes": includes,
688
730
                               "excludes": excludes,
689
731
                               "dll_excludes": dll_excludes,
690
732
                               "dist_dir": "win32_bzr.exe",
691
733
                               "optimize": 2,
 
734
                               "custom_boot_script":
 
735
                                        "tools/win32/py2exe_boot_common.py",
692
736
                              },
693
737
                   }
694
738
 
695
 
    setup(options=options_list,
696
 
          console=console_targets,
697
 
          windows=gui_targets,
698
 
          zipfile='lib/library.zip',
699
 
          data_files=data_files,
700
 
          cmdclass={'install_data': install_data_with_bytecompile},
701
 
          )
 
739
    # We want the libaray.zip to have optimize = 2, but the exe to have
 
740
    # optimize = 1, so that .py files that get compilied at run time
 
741
    # (e.g. user installed plugins) dont have their doc strings removed.
 
742
    class py2exe_no_oo_exe(py2exe.build_exe.py2exe):
 
743
        def build_executable(self, *args, **kwargs):
 
744
            self.optimize = 1
 
745
            py2exe.build_exe.py2exe.build_executable(self, *args, **kwargs)
 
746
            self.optimize = 2
 
747
 
 
748
    if __name__ == '__main__':
 
749
        command_classes['install_data'] = install_data_with_bytecompile
 
750
        command_classes['py2exe'] = py2exe_no_oo_exe
 
751
        setup(options=options_list,
 
752
              console=console_targets,
 
753
              windows=gui_targets,
 
754
              zipfile='lib/library.zip',
 
755
              data_files=data_files,
 
756
              cmdclass=command_classes,
 
757
              )
702
758
 
703
759
else:
704
760
    # ad-hoc for easy_install
708
764
        # easy_install one
709
765
        DATA_FILES = [('man/man1', ['bzr.1'])]
710
766
 
711
 
    if sys.platform != 'win32':
712
 
        # see https://wiki.kubuntu.org/Apport/DeveloperHowTo
713
 
        #
714
 
        # checking the paths and hardcoding the check for root is a bit gross,
715
 
        # but I don't see a cleaner way to find out the locations in a way
716
 
        # that's going to align with the hardcoded paths in apport.
717
 
        if os.geteuid() == 0:
718
 
            DATA_FILES += [
719
 
                ('/usr/share/apport/package-hooks',
720
 
                    ['apport/source_bzr.py']),
721
 
                ('/etc/apport/crashdb.conf.d/',
722
 
                    ['apport/bzr-crashdb.conf']),]
723
 
 
 
767
    DATA_FILES = DATA_FILES + I18N_FILES
724
768
    # std setup
725
769
    ARGS = {'scripts': ['bzr'],
726
770
            'data_files': DATA_FILES,
732
776
    ARGS.update(BZRLIB)
733
777
    ARGS.update(PKG_DATA)
734
778
 
735
 
    setup(**ARGS)
 
779
    if __name__ == '__main__':
 
780
        setup(**ARGS)