/brz/remove-bazaar

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