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