~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil, Patch Queue Manager, Jelmer Vernooij
  • Date: 2017-01-17 16:20:41 UTC
  • mfrom: (6619.1.2 trunk)
  • Revision ID: tarmac-20170117162041-oo62uk1qsmgc9j31
Merge 2.7 into trunk including fixes for bugs #1622039, #1644003, #1579093 and #1645017. [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
import os.path
11
11
import sys
12
12
import copy
 
13
import glob
13
14
 
14
 
if sys.version_info < (2, 4):
15
 
    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")
16
17
    sys.exit(1)
17
18
 
18
19
# NOTE: The directory containing setup.py, whether run by 'python setup.py' or
66
67
            'package_data': {'bzrlib': ['doc/api/*.txt',
67
68
                                        'tests/test_patches_data/*',
68
69
                                        'help_topics/en/*.txt',
 
70
                                        'tests/ssl_certs/ca.crt',
69
71
                                        'tests/ssl_certs/server_without_pass.key',
70
72
                                        'tests/ssl_certs/server_with_pass.key',
71
 
                                        'tests/ssl_certs/server.crt'
 
73
                                        'tests/ssl_certs/server.crt',
72
74
                                       ]},
73
75
           }
74
 
 
 
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]))
75
81
 
76
82
def get_bzrlib_packages():
77
83
    """Recurse through the bzrlib directory, and extract the package names"""
99
105
 
100
106
from distutils import log
101
107
from distutils.core import setup
 
108
from distutils.version import LooseVersion
102
109
from distutils.command.install_scripts import install_scripts
103
110
from distutils.command.install_data import install_data
104
111
from distutils.command.build import build
151
158
    Generate bzr.1.
152
159
    """
153
160
 
 
161
    sub_commands = build.sub_commands + [
 
162
            ('build_mo', lambda _: True),
 
163
            ]
 
164
 
154
165
    def run(self):
155
166
        build.run(self)
156
167
 
162
173
## Setup
163
174
########################
164
175
 
 
176
from bzrlib.bzr_distutils import build_mo
 
177
 
165
178
command_classes = {'install_scripts': my_install_scripts,
166
 
                   'build': bzr_build}
 
179
                   'build': bzr_build,
 
180
                   'build_mo': build_mo,
 
181
                   }
167
182
from distutils import log
168
183
from distutils.errors import CCompilerError, DistutilsPlatformError
169
184
from distutils.extension import Extension
170
185
ext_modules = []
171
186
try:
172
187
    try:
 
188
        from Cython.Distutils import build_ext
 
189
        from Cython.Compiler.Version import version as pyrex_version
 
190
    except ImportError:
 
191
        print("No Cython, trying Pyrex...")
173
192
        from Pyrex.Distutils import build_ext
174
193
        from Pyrex.Compiler.Version import version as pyrex_version
175
 
    except ImportError:
176
 
        print("No Pyrex, trying Cython...")
177
 
        from Cython.Distutils import build_ext
178
 
        from Cython.Compiler.Version import version as pyrex_version
179
194
except ImportError:
180
195
    have_pyrex = False
181
196
    # try to build the extension from the prior generated source.
188
203
    from distutils.command.build_ext import build_ext
189
204
else:
190
205
    have_pyrex = True
191
 
    pyrex_version_info = tuple(map(int, pyrex_version.split('.')))
 
206
    pyrex_version_info = LooseVersion(pyrex_version)
192
207
 
193
208
 
194
209
class build_ext_if_possible(build_ext):
285
300
                        libraries=['Ws2_32'])
286
301
    add_pyrex_extension('bzrlib._walkdirs_win32')
287
302
else:
288
 
    if have_pyrex and pyrex_version_info[:3] == (0,9,4):
 
303
    if have_pyrex and pyrex_version_info == LooseVersion("0.9.4.1"):
289
304
        # Pyrex 0.9.4.1 fails to compile this extension correctly
290
305
        # The code it generates re-uses a "local" pointer and
291
306
        # calls "PY_DECREF" after having set it to NULL. (It mixes PY_XDECREF
292
307
        # which is NULL safe with PY_DECREF which is not.)
293
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/449372>
294
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/276868>
 
308
        # <https://bugs.launchpad.net/bzr/+bug/449372>
 
309
        # <https://bugs.launchpad.net/bzr/+bug/276868>
295
310
        print('Cannot build extension "bzrlib._dirstate_helpers_pyx" using')
296
 
        print('your version of pyrex "%s". Please upgrade your pyrex' % (
297
 
            pyrex_version,))
 
311
        print('your version of pyrex "%s". Please upgrade your pyrex'
 
312
              % (pyrex_version,))
298
313
        print('install. For now, the non-compiled (python) version will')
299
314
        print('be used instead.')
300
315
    else:
303
318
add_pyrex_extension('bzrlib._chk_map_pyx')
304
319
ext_modules.append(Extension('bzrlib._patiencediff_c',
305
320
                             ['bzrlib/_patiencediff_c.c']))
306
 
if have_pyrex and pyrex_version_info < (0, 9, 6, 3):
 
321
if have_pyrex and pyrex_version_info < LooseVersion("0.9.6.3"):
307
322
    print("")
308
323
    print('Your Pyrex/Cython version %s is too old to build the simple_set' % (
309
324
        pyrex_version))
394
409
    # ditto for the tbzrcommand tool
395
410
    tbzrcommand = dict(
396
411
        script = os.path.join(tbzr_root, "scripts", "tbzrcommand.py"),
397
 
        icon_resources = [(0,'bzr.ico')],
 
412
        icon_resources = icon_resources,
 
413
        other_resources = other_resources,
398
414
    )
399
415
    console_targets.append(tbzrcommand)
400
416
    tbzrcommandw = tbzrcommand.copy()
416
432
    # PyQt4 itself still escapes the plugin detection code for some reason...
417
433
    includes.append('PyQt4.QtCore')
418
434
    includes.append('PyQt4.QtGui')
 
435
    includes.append('PyQt4.QtTest')
419
436
    includes.append('sip') # extension module required for Qt.
420
437
    packages.append('pygments') # colorizer for qbzr
421
438
    packages.append('docutils') # html formatting
467
484
    packages.append('sqlite3')
468
485
 
469
486
 
 
487
def get_git_py2exe_info(includes, excludes, packages):
 
488
    packages.append('dulwich')
 
489
 
 
490
 
 
491
def get_fastimport_py2exe_info(includes, excludes, packages):
 
492
    # This is the python-fastimport package, not to be confused with the
 
493
    # bzr-fastimport plugin.
 
494
    packages.append('fastimport')
 
495
 
 
496
 
470
497
if 'bdist_wininst' in sys.argv:
471
498
    def find_docs():
472
499
        docs = []
491
518
            # help pages
492
519
            'data_files': find_docs(),
493
520
            # for building pyrex extensions
494
 
            'cmdclass': {'build_ext': build_ext_if_possible},
 
521
            'cmdclass': command_classes,
495
522
           }
496
523
 
497
524
    ARGS.update(META_INFO)
498
525
    ARGS.update(BZRLIB)
 
526
    PKG_DATA['package_data']['bzrlib'].append('locale/*/LC_MESSAGES/*.mo')
499
527
    ARGS.update(PKG_DATA)
500
 
    
 
528
 
501
529
    setup(**ARGS)
502
530
 
503
531
elif 'py2exe' in sys.argv:
504
 
    import glob
505
532
    # py2exe setup
506
533
    import py2exe
507
534
 
651
678
                       'tools/win32/bzr_postinstall.py',
652
679
                       ]
653
680
    gui_targets = [gui_target]
654
 
    data_files = topics_files + plugins_files
 
681
    data_files = topics_files + plugins_files + I18N_FILES
655
682
 
656
683
    if 'qbzr' in plugins:
657
684
        get_qbzr_py2exe_info(includes, excludes, packages, data_files)
659
686
    if 'svn' in plugins:
660
687
        get_svn_py2exe_info(includes, excludes, packages)
661
688
 
 
689
    if 'git' in plugins:
 
690
        get_git_py2exe_info(includes, excludes, packages)
 
691
 
 
692
    if 'fastimport' in plugins:
 
693
        get_fastimport_py2exe_info(includes, excludes, packages)
 
694
 
662
695
    if "TBZR" in os.environ:
663
696
        # TORTOISE_OVERLAYS_MSI_WIN32 must be set to the location of the
664
697
        # TortoiseOverlays MSI installer file. It is in the TSVN svn repo and
688
721
 
689
722
    # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls
690
723
    # in on Vista.
691
 
    dll_excludes.extend(["MSWSOCK.dll", "MSVCP60.dll", "powrprof.dll"])
 
724
    dll_excludes.extend(["MSWSOCK.dll",
 
725
                         "MSVCP60.dll",
 
726
                         "MSVCP90.dll",
 
727
                         "powrprof.dll",
 
728
                         "SHFOLDER.dll"])
692
729
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
693
730
                               "includes": includes,
694
731
                               "excludes": excludes,
710
747
            self.optimize = 2
711
748
 
712
749
    if __name__ == '__main__':
 
750
        command_classes['install_data'] = install_data_with_bytecompile
 
751
        command_classes['py2exe'] = py2exe_no_oo_exe
713
752
        setup(options=options_list,
714
753
              console=console_targets,
715
754
              windows=gui_targets,
716
755
              zipfile='lib/library.zip',
717
756
              data_files=data_files,
718
 
              cmdclass={'install_data': install_data_with_bytecompile,
719
 
                        'py2exe': py2exe_no_oo_exe},
 
757
              cmdclass=command_classes,
720
758
              )
721
759
 
722
760
else:
727
765
        # easy_install one
728
766
        DATA_FILES = [('man/man1', ['bzr.1'])]
729
767
 
730
 
    if sys.platform != 'win32':
731
 
        # see https://wiki.kubuntu.org/Apport/DeveloperHowTo
732
 
        #
733
 
        # checking the paths and hardcoding the check for root is a bit gross,
734
 
        # but I don't see a cleaner way to find out the locations in a way
735
 
        # that's going to align with the hardcoded paths in apport.
736
 
        if os.geteuid() == 0:
737
 
            DATA_FILES += [
738
 
                ('/usr/share/apport/package-hooks',
739
 
                    ['apport/source_bzr.py']),
740
 
                ('/etc/apport/crashdb.conf.d/',
741
 
                    ['apport/bzr-crashdb.conf']),]
742
 
 
 
768
    DATA_FILES = DATA_FILES + I18N_FILES
743
769
    # std setup
744
770
    ARGS = {'scripts': ['bzr'],
745
771
            'data_files': DATA_FILES,