~bzr-pqm/bzr/bzr.dev

45 by Martin Pool
- add setup.py and install instructions
1
#! /usr/bin/env python
2
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
3
"""Installation script for bzr.
4
Run it with
5
 './setup.py install', or
6
 './setup.py --help' for more options
7
"""
8
1930.3.1 by John Arbash Meinel
Change setup.py to auto-generate the list of packages to install
9
import os
10
import sys
11
1861.2.21 by Alexander Belchenko
setup.py: automatically grab version info from bzrlib
12
import bzrlib
13
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
14
##
15
# META INFORMATION FOR SETUP
16
17
META_INFO = {'name':         'bzr',
1861.2.21 by Alexander Belchenko
setup.py: automatically grab version info from bzrlib
18
             'version':      bzrlib.__version__,
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
19
             'author':       'Canonical Ltd',
2234.5.1 by Wouter van Heyst
Update the mailing list address.
20
             'author_email': 'bazaar@lists.canonical.com',
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
21
             'url':          'http://www.bazaar-vcs.org/',
22
             'description':  'Friendly distributed version control system',
23
             'license':      'GNU GPL v2',
24
            }
25
1930.3.3 by John Arbash Meinel
Fix a stupid error in code declaration order
26
# The list of packages is automatically generated later. Add other things
27
# that are part of BZRLIB here.
28
BZRLIB = {}
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
29
1911.1.1 by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data
30
PKG_DATA = {# install files from selftest suite
31
            'package_data': {'bzrlib': ['doc/api/*.txt',
32
                                        'tests/test_patches_data/*',
3089.3.6 by Ian Clatworthy
make help topics more discoverable
33
                                        'help_topics/en/*.txt',
1911.1.1 by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data
34
                                       ]},
35
           }
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
36
1861.2.12 by Alexander Belchenko
setup.py: get version info from bzrlib
37
######################################################################
1185.29.5 by Wouter van Heyst
Add reinvocation code to ensure setup.py is run by python2.4
38
# Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
39
# including bzrlib.help
40
41
try:
42
    version_info = sys.version_info
43
except AttributeError:
44
    version_info = 1, 5 # 1.5 or older
45
46
REINVOKE = "__BZR_REINVOKE"
47
NEED_VERS = (2, 4)
48
KNOWN_PYTHONS = ('python2.4',)
49
50
if version_info < NEED_VERS:
51
    if not os.environ.has_key(REINVOKE):
52
        # mutating os.environ doesn't work in old Pythons
53
        os.putenv(REINVOKE, "1")
54
        for python in KNOWN_PYTHONS:
55
            try:
56
                os.execvp(python, [python] + sys.argv)
57
            except OSError:
58
                pass
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
59
    sys.stderr.write("bzr: error: cannot find a suitable python interpreter\n")
60
    sys.stderr.write("  (need %d.%d or later)" % NEED_VERS)
61
    sys.stderr.write('\n')
1185.29.5 by Wouter van Heyst
Add reinvocation code to ensure setup.py is run by python2.4
62
    sys.exit(1)
1963.2.6 by Robey Pointer
pychecker is on crack; go back to using 'is None'.
63
if getattr(os, "unsetenv", None) is not None:
1185.29.5 by Wouter van Heyst
Add reinvocation code to ensure setup.py is run by python2.4
64
    os.unsetenv(REINVOKE)
65
66
1930.3.1 by John Arbash Meinel
Change setup.py to auto-generate the list of packages to install
67
def get_bzrlib_packages():
68
    """Recurse through the bzrlib directory, and extract the package names"""
69
70
    packages = []
71
    base_path = os.path.dirname(os.path.abspath(bzrlib.__file__))
72
    for root, dirs, files in os.walk(base_path):
73
        if '__init__.py' in files:
74
            assert root.startswith(base_path)
75
            # Get just the path below bzrlib
76
            package_path = root[len(base_path):]
77
            # Remove leading and trailing slashes
78
            package_path = package_path.strip('\\/')
79
            if not package_path:
80
                package_name = 'bzrlib'
81
            else:
82
                package_name = ('bzrlib.' +
83
                            package_path.replace('/', '.').replace('\\', '.'))
84
            packages.append(package_name)
85
    return sorted(packages)
86
87
1930.3.3 by John Arbash Meinel
Fix a stupid error in code declaration order
88
BZRLIB['packages'] = get_bzrlib_packages()
89
90
45 by Martin Pool
- add setup.py and install instructions
91
from distutils.core import setup
1185.23.1 by Aaron Bentley
win32 setup fixes from Belchenko
92
from distutils.command.install_scripts import install_scripts
1185.29.3 by Wouter van Heyst
Create bzr.1 manpage from setup.py
93
from distutils.command.build import build
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
94
95
###############################
96
# Overridden distutils actions
97
###############################
98
1185.23.1 by Aaron Bentley
win32 setup fixes from Belchenko
99
class my_install_scripts(install_scripts):
100
    """ Customized install_scripts distutils action.
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
101
    Create bzr.bat for win32.
102
    """
103
    def run(self):
1185.23.1 by Aaron Bentley
win32 setup fixes from Belchenko
104
        install_scripts.run(self)   # standard action
105
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
106
        if sys.platform == "win32":
1185.23.1 by Aaron Bentley
win32 setup fixes from Belchenko
107
            try:
2662.1.1 by Alexander Belchenko
allow ``easy_install bzr`` runs without fatal errors. (Alexander Belchenko, #125521)
108
                scripts_dir = os.path.join(sys.prefix, 'Scripts')
1861.2.10 by Alexander Belchenko
setup.py: improved bzr.bat creation
109
                script_path = self._quoted_path(os.path.join(scripts_dir,
110
                                                             "bzr"))
111
                python_exe = self._quoted_path(sys.executable)
112
                args = self._win_batch_args()
113
                batch_str = "@%s %s %s" % (python_exe, script_path, args)
2662.1.1 by Alexander Belchenko
allow ``easy_install bzr`` runs without fatal errors. (Alexander Belchenko, #125521)
114
                batch_path = os.path.join(self.install_dir, "bzr.bat")
1185.23.1 by Aaron Bentley
win32 setup fixes from Belchenko
115
                f = file(batch_path, "w")
116
                f.write(batch_str)
117
                f.close()
118
                print "Created:", batch_path
119
            except Exception, e:
120
                print "ERROR: Unable to create %s: %s" % (batch_path, e)
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
121
1861.2.10 by Alexander Belchenko
setup.py: improved bzr.bat creation
122
    def _quoted_path(self, path):
123
        if ' ' in path:
124
            return '"' + path + '"'
125
        else:
126
            return path
127
128
    def _win_batch_args(self):
2245.4.4 by Alexander Belchenko
setup.py: fix plain 'python setup.py install' for win98
129
        from bzrlib.win32utils import winver
130
        if winver == 'Windows NT':
1861.2.10 by Alexander Belchenko
setup.py: improved bzr.bat creation
131
            return '%*'
132
        else:
133
            return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
134
#/class my_install_scripts
135
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
136
1185.29.3 by Wouter van Heyst
Create bzr.1 manpage from setup.py
137
class bzr_build(build):
138
    """Customized build distutils action.
139
    Generate bzr.1.
140
    """
141
    def run(self):
142
        build.run(self)
143
1551.3.11 by Aaron Bentley
Merge from Robert
144
        import generate_docs
145
        generate_docs.main(argv=["bzr", "man"])
1185.29.3 by Wouter van Heyst
Create bzr.1 manpage from setup.py
146
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
147
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
148
########################
149
## Setup
150
########################
151
1739.1.1 by Robert Collins
First cut at adding pyrex facilities.
152
command_classes = {'install_scripts': my_install_scripts,
2571.3.1 by Alexander Belchenko
Building Python-based installer for bot Python 2.4 and 2.5
153
                   'build': bzr_build}
2814.4.1 by Lukáš Lalinský
Don't abort ``python setup.py install`` if building of a C extension is not possible.
154
from distutils import log
2814.4.2 by Alexander Belchenko
support for win32
155
from distutils.errors import CCompilerError, DistutilsPlatformError
2617.1.1 by John Arbash Meinel
Update setup.py to just skip extensions that are not available.
156
from distutils.extension import Extension
1739.1.1 by Robert Collins
First cut at adding pyrex facilities.
157
ext_modules = []
158
try:
159
    from Pyrex.Distutils import build_ext
160
except ImportError:
2617.1.1 by John Arbash Meinel
Update setup.py to just skip extensions that are not available.
161
    have_pyrex = False
1739.1.1 by Robert Collins
First cut at adding pyrex facilities.
162
    # try to build the extension from the prior generated source.
2617.1.1 by John Arbash Meinel
Update setup.py to just skip extensions that are not available.
163
    print
2617.1.2 by John Arbash Meinel
Try another form of comment
164
    print ("The python package 'Pyrex' is not available."
165
           " If the .c files are available,")
166
    print ("they will be built,"
167
           " but modifying the .pyx files will not rebuild them.")
2617.1.3 by John Arbash Meinel
Add another blank line to make it show up better
168
    print
1739.1.4 by Robert Collins
Fix building of C modules without pyrex installed.
169
    from distutils.command.build_ext import build_ext
1739.1.1 by Robert Collins
First cut at adding pyrex facilities.
170
else:
2617.1.1 by John Arbash Meinel
Update setup.py to just skip extensions that are not available.
171
    have_pyrex = True
2814.4.1 by Lukáš Lalinský
Don't abort ``python setup.py install`` if building of a C extension is not possible.
172
173
174
class build_ext_if_possible(build_ext):
175
2814.4.2 by Alexander Belchenko
support for win32
176
    def run(self):
177
        try:
178
            build_ext.run(self)
179
        except DistutilsPlatformError, e:
2814.4.4 by Alexander Belchenko
changes suggested by Aaron and Martin
180
            log.warn(str(e))
2814.4.5 by Alexander Belchenko
double quotes for extension name
181
            log.warn('Extensions cannot be built, '
182
                     'will use the Python versions instead')
2814.4.2 by Alexander Belchenko
support for win32
183
2814.4.1 by Lukáš Lalinský
Don't abort ``python setup.py install`` if building of a C extension is not possible.
184
    def build_extension(self, ext):
185
        try:
186
            build_ext.build_extension(self, ext)
187
        except CCompilerError:
2814.4.5 by Alexander Belchenko
double quotes for extension name
188
            log.warn('Building of "%s" extension failed, '
189
                     'will use the Python version instead' % (ext.name,))
2814.4.1 by Lukáš Lalinský
Don't abort ``python setup.py install`` if building of a C extension is not possible.
190
191
2617.1.1 by John Arbash Meinel
Update setup.py to just skip extensions that are not available.
192
# Override the build_ext if we have Pyrex available
2814.4.1 by Lukáš Lalinský
Don't abort ``python setup.py install`` if building of a C extension is not possible.
193
command_classes['build_ext'] = build_ext_if_possible
2617.1.1 by John Arbash Meinel
Update setup.py to just skip extensions that are not available.
194
unavailable_files = []
195
2617.1.2 by John Arbash Meinel
Try another form of comment
196
2617.1.1 by John Arbash Meinel
Update setup.py to just skip extensions that are not available.
197
def add_pyrex_extension(module_name, **kwargs):
198
    """Add a pyrex module to build.
199
200
    This will use Pyrex to auto-generate the .c file if it is available.
201
    Otherwise it will fall back on the .c file. If the .c file is not
202
    available, it will warn, and not add anything.
203
204
    You can pass any extra options to Extension through kwargs. One example is
205
    'libraries = []'.
206
207
    :param module_name: The python path to the module. This will be used to
208
        determine the .pyx and .c files to use.
209
    """
210
    path = module_name.replace('.', '/')
211
    pyrex_name = path + '.pyx'
212
    c_name = path + '.c'
213
    if have_pyrex:
214
        ext_modules.append(Extension(module_name, [pyrex_name]))
215
    else:
216
        if not os.path.isfile(c_name):
217
            unavailable_files.append(c_name)
218
        else:
219
            ext_modules.append(Extension(module_name, [c_name]))
220
221
2474.1.71 by John Arbash Meinel
[merge] bzr.dev 2625
222
add_pyrex_extension('bzrlib._dirstate_helpers_c')
2617.1.1 by John Arbash Meinel
Update setup.py to just skip extensions that are not available.
223
add_pyrex_extension('bzrlib._knit_load_data_c')
2781.1.1 by Martin Pool
merge cpatiencediff from Lukas
224
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
2617.1.1 by John Arbash Meinel
Update setup.py to just skip extensions that are not available.
225
226
227
if unavailable_files:
228
    print 'C extension(s) not found:'
229
    print '   %s' % ('\n  '.join(unavailable_files),)
230
    print 'The python versions will be used instead.'
231
    print
232
1739.1.1 by Robert Collins
First cut at adding pyrex facilities.
233
1860.1.2 by Alexander Belchenko
setup.py:
234
if 'bdist_wininst' in sys.argv:
2691.1.18 by Alexander Belchenko
teach windows python installer to find docs in all subdirectories
235
    def find_docs():
236
        docs = []
237
        for root, dirs, files in os.walk('doc'):
238
            r = []
239
            for f in files:
3113.4.1 by Alexander Belchenko
Python-based installer should contain png and pdf in Docs.
240
                if os.path.splitext(f)[1] in ('.html','.css','.png','.pdf'):
2691.1.18 by Alexander Belchenko
teach windows python installer to find docs in all subdirectories
241
                    r.append(os.path.join(root, f))
242
            if r:
243
                relative = root[4:]
244
                if relative:
245
                    target = os.path.join('Doc\\Bazaar', relative)
246
                else:
247
                    target = 'Doc\\Bazaar'
248
                docs.append((target, r))
249
        return docs
250
1860.1.2 by Alexander Belchenko
setup.py:
251
    # python's distutils-based win32 installer
252
    ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
2571.3.1 by Alexander Belchenko
Building Python-based installer for bot Python 2.4 and 2.5
253
            'ext_modules': ext_modules,
1860.1.3 by Alexander Belchenko
python-installer:
254
            # help pages
2691.1.18 by Alexander Belchenko
teach windows python installer to find docs in all subdirectories
255
            'data_files': find_docs(),
2571.3.1 by Alexander Belchenko
Building Python-based installer for bot Python 2.4 and 2.5
256
            # for building pyrex extensions
2814.4.1 by Lukáš Lalinský
Don't abort ``python setup.py install`` if building of a C extension is not possible.
257
            'cmdclass': {'build_ext': build_ext_if_possible},
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
258
           }
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
259
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
260
    ARGS.update(META_INFO)
261
    ARGS.update(BZRLIB)
1911.1.1 by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data
262
    ARGS.update(PKG_DATA)
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
263
    
264
    setup(**ARGS)
265
1860.1.2 by Alexander Belchenko
setup.py:
266
elif 'py2exe' in sys.argv:
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
267
    # py2exe setup
268
    import py2exe
269
270
    # pick real bzr version
271
    import bzrlib
272
273
    version_number = []
274
    for i in bzrlib.version_info[:4]:
275
        try:
276
            i = int(i)
277
        except ValueError:
278
            i = 0
279
        version_number.append(str(i))
280
    version_str = '.'.join(version_number)
281
282
    target = py2exe.build_exe.Target(script = "bzr",
283
                                     dest_base = "bzr",
284
                                     icon_resources = [(0,'bzr.ico')],
285
                                     name = META_INFO['name'],
286
                                     version = version_str,
287
                                     description = META_INFO['description'],
288
                                     author = META_INFO['author'],
2232.1.1 by mbp at sourcefrog
update global copyright to 2007
289
                                     copyright = "(c) Canonical Ltd, 2005-2007",
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
290
                                     company_name = "Canonical Ltd.",
291
                                     comments = META_INFO['description'],
292
                                    )
2231.1.1 by Alexander Belchenko
Python 2.5 fixes for win32 installer
293
294
    additional_packages =  []
295
    if sys.version.startswith('2.4'):
296
        # adding elementtree package
297
        additional_packages.append('elementtree')
2234.5.2 by Wouter van Heyst
(Alexander Belchenko) add windows installer check for python2.5
298
    elif sys.version.startswith('2.5'):
299
        additional_packages.append('xml.etree')
300
    else:
301
        import warnings
302
        warnings.warn('Unknown Python version.\n'
303
                      'Please check setup.py script for compatibility.')
2571.3.2 by Alexander Belchenko
Build pyrex/C extensions for bzr.exe
304
    # email package from std python library use lazy import,
305
    # so we need to explicitly add all package
306
    additional_packages.append('email')
2231.1.1 by Alexander Belchenko
Python 2.5 fixes for win32 installer
307
3087.2.4 by Alexander Belchenko
Help topics can now be loaded from files (based on Ian's patch, adapted to proper support various windows installers).
308
    # text files for help topis
309
    import glob
3089.3.6 by Ian Clatworthy
make help topics more discoverable
310
    text_topics = glob.glob('bzrlib/help_topics/en/*.txt')
3087.2.4 by Alexander Belchenko
Help topics can now be loaded from files (based on Ian's patch, adapted to proper support various windows installers).
311
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
312
    options_list = {"py2exe": {"packages": BZRLIB['packages'] +
2231.1.1 by Alexander Belchenko
Python 2.5 fixes for win32 installer
313
                                           additional_packages,
2481.2.1 by Alexander Belchenko
don't bundle into standalone bzr.exe site.py (with their depends), and tools/doc_generate
314
                               "excludes": ["Tkinter", "medusa", "tools"],
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
315
                               "dist_dir": "win32_bzr.exe",
316
                              },
317
                   }
318
    setup(options=options_list,
319
          console=[target,
320
                   'tools/win32/bzr_postinstall.py',
321
                  ],
3087.2.4 by Alexander Belchenko
Help topics can now be loaded from files (based on Ian's patch, adapted to proper support various windows installers).
322
          zipfile='lib/library.zip',
3089.3.6 by Ian Clatworthy
make help topics more discoverable
323
          data_files=[('lib/help_topics/en', text_topics)],
3087.2.4 by Alexander Belchenko
Help topics can now be loaded from files (based on Ian's patch, adapted to proper support various windows installers).
324
          )
1860.1.2 by Alexander Belchenko
setup.py:
325
326
else:
2662.1.1 by Alexander Belchenko
allow ``easy_install bzr`` runs without fatal errors. (Alexander Belchenko, #125521)
327
    # ad-hoc for easy_install
328
    DATA_FILES = []
329
    if not 'bdist_egg' in sys.argv:
330
        # generate and install bzr.1 only with plain install, not easy_install one
331
        DATA_FILES = [('man/man1', ['bzr.1'])]
332
1860.1.2 by Alexander Belchenko
setup.py:
333
    # std setup
334
    ARGS = {'scripts': ['bzr'],
2662.1.1 by Alexander Belchenko
allow ``easy_install bzr`` runs without fatal errors. (Alexander Belchenko, #125521)
335
            'data_files': DATA_FILES,
1739.1.3 by Robert Collins
Merge bzr.dev.
336
            'cmdclass': command_classes,
337
            'ext_modules': ext_modules,
1860.1.2 by Alexander Belchenko
setup.py:
338
           }
2666.2.1 by Alexander Belchenko
change generated documentation extension from htm to html
339
1860.1.2 by Alexander Belchenko
setup.py:
340
    ARGS.update(META_INFO)
341
    ARGS.update(BZRLIB)
1911.1.1 by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data
342
    ARGS.update(PKG_DATA)
1860.1.2 by Alexander Belchenko
setup.py:
343
344
    setup(**ARGS)