/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Robert Collins
  • Date: 2007-04-26 01:48:29 UTC
  • mto: This revision was merged to the branch mainline in revision 2457.
  • Revision ID: robertc@robertcollins.net-20070426014829-znbzqzsk1gq68xqh
Fix the 'Unprintable error' message display to use the repr of the
exception that prevented printing the error because the str value for it
is often not useful in debugging (e.g.  KeyError('foo') has a str() of
'foo' but a repr of 'KeyError('foo')' which is much more useful.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/env python
2
2
 
3
 
# This is an installation script for bzr.  Run it with
4
 
# './setup.py install', or
5
 
# './setup.py --help' for more options
 
3
"""Installation script for bzr.
 
4
Run it with
 
5
 './setup.py install', or
 
6
 './setup.py --help' for more options
 
7
"""
 
8
 
 
9
import os
 
10
import sys
 
11
 
 
12
import bzrlib
 
13
 
 
14
##
 
15
# META INFORMATION FOR SETUP
 
16
 
 
17
META_INFO = {'name':         'bzr',
 
18
             'version':      bzrlib.__version__,
 
19
             'author':       'Canonical Ltd',
 
20
             'author_email': 'bazaar@lists.canonical.com',
 
21
             'url':          'http://www.bazaar-vcs.org/',
 
22
             'description':  'Friendly distributed version control system',
 
23
             'license':      'GNU GPL v2',
 
24
            }
 
25
 
 
26
# The list of packages is automatically generated later. Add other things
 
27
# that are part of BZRLIB here.
 
28
BZRLIB = {}
 
29
 
 
30
PKG_DATA = {# install files from selftest suite
 
31
            'package_data': {'bzrlib': ['doc/api/*.txt',
 
32
                                        'tests/test_patches_data/*',
 
33
                                       ]},
 
34
           }
 
35
 
 
36
######################################################################
 
37
# Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
 
38
# including bzrlib.help
 
39
 
 
40
try:
 
41
    version_info = sys.version_info
 
42
except AttributeError:
 
43
    version_info = 1, 5 # 1.5 or older
 
44
 
 
45
REINVOKE = "__BZR_REINVOKE"
 
46
NEED_VERS = (2, 4)
 
47
KNOWN_PYTHONS = ('python2.4',)
 
48
 
 
49
if version_info < NEED_VERS:
 
50
    if not os.environ.has_key(REINVOKE):
 
51
        # mutating os.environ doesn't work in old Pythons
 
52
        os.putenv(REINVOKE, "1")
 
53
        for python in KNOWN_PYTHONS:
 
54
            try:
 
55
                os.execvp(python, [python] + sys.argv)
 
56
            except OSError:
 
57
                pass
 
58
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
 
59
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
 
60
    sys.exit(1)
 
61
if getattr(os, "unsetenv", None) is not None:
 
62
    os.unsetenv(REINVOKE)
 
63
 
 
64
 
 
65
def get_bzrlib_packages():
 
66
    """Recurse through the bzrlib directory, and extract the package names"""
 
67
 
 
68
    packages = []
 
69
    base_path = os.path.dirname(os.path.abspath(bzrlib.__file__))
 
70
    for root, dirs, files in os.walk(base_path):
 
71
        if '__init__.py' in files:
 
72
            assert root.startswith(base_path)
 
73
            # Get just the path below bzrlib
 
74
            package_path = root[len(base_path):]
 
75
            # Remove leading and trailing slashes
 
76
            package_path = package_path.strip('\\/')
 
77
            if not package_path:
 
78
                package_name = 'bzrlib'
 
79
            else:
 
80
                package_name = ('bzrlib.' +
 
81
                            package_path.replace('/', '.').replace('\\', '.'))
 
82
            packages.append(package_name)
 
83
    return sorted(packages)
 
84
 
 
85
 
 
86
BZRLIB['packages'] = get_bzrlib_packages()
 
87
 
6
88
 
7
89
from distutils.core import setup
8
 
 
9
 
setup(name='bzr',
10
 
      version='0.0.0',
11
 
      author='Martin Pool',
12
 
      author_email='mbp@sourcefrog.net',
13
 
      url='http://www.bazaar-ng.org/',
14
 
      description='Friendly distributed version control system',
15
 
      license='GNU GPL v2',
16
 
      packages=['bzrlib'],
17
 
      scripts=['bzr'])
 
90
from distutils.command.install_scripts import install_scripts
 
91
from distutils.command.build import build
 
92
 
 
93
###############################
 
94
# Overridden distutils actions
 
95
###############################
 
96
 
 
97
class my_install_scripts(install_scripts):
 
98
    """ Customized install_scripts distutils action.
 
99
    Create bzr.bat for win32.
 
100
    """
 
101
    def run(self):
 
102
        install_scripts.run(self)   # standard action
 
103
 
 
104
        if sys.platform == "win32":
 
105
            try:
 
106
                scripts_dir = self.install_dir
 
107
                script_path = self._quoted_path(os.path.join(scripts_dir,
 
108
                                                             "bzr"))
 
109
                python_exe = self._quoted_path(sys.executable)
 
110
                args = self._win_batch_args()
 
111
                batch_str = "@%s %s %s" % (python_exe, script_path, args)
 
112
                batch_path = script_path + ".bat"
 
113
                f = file(batch_path, "w")
 
114
                f.write(batch_str)
 
115
                f.close()
 
116
                print "Created:", batch_path
 
117
            except Exception, e:
 
118
                print "ERROR: Unable to create %s: %s" % (batch_path, e)
 
119
 
 
120
    def _quoted_path(self, path):
 
121
        if ' ' in path:
 
122
            return '"' + path + '"'
 
123
        else:
 
124
            return path
 
125
 
 
126
    def _win_batch_args(self):
 
127
        from bzrlib.win32utils import winver
 
128
        if winver == 'Windows NT':
 
129
            return '%*'
 
130
        else:
 
131
            return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
 
132
#/class my_install_scripts
 
133
 
 
134
 
 
135
class bzr_build(build):
 
136
    """Customized build distutils action.
 
137
    Generate bzr.1.
 
138
    """
 
139
    def run(self):
 
140
        build.run(self)
 
141
 
 
142
        import generate_docs
 
143
        generate_docs.main(argv=["bzr", "man"])
 
144
 
 
145
 
 
146
########################
 
147
## Setup
 
148
########################
 
149
 
 
150
command_classes = {'install_scripts': my_install_scripts,
 
151
                  'build': bzr_build}
 
152
ext_modules = []
 
153
try:
 
154
    from Pyrex.Distutils import build_ext
 
155
except ImportError:
 
156
    # try to build the extension from the prior generated source.
 
157
    print ("Pyrex not available, while bzr will build, "
 
158
           "you cannot modify the C extensions.")
 
159
    from distutils.command.build_ext import build_ext
 
160
    from distutils.extension import Extension
 
161
    #ext_modules.append(
 
162
    #    Extension("bzrlib.modulename", ["bzrlib/foo.c"], libraries = []))
 
163
else:
 
164
    from distutils.extension import Extension
 
165
    #ext_modules.append(
 
166
    #    Extension("bzrlib.modulename", ["bzrlib/foo.pyx"], libraries = []))
 
167
command_classes['build_ext'] = build_ext
 
168
 
 
169
if 'bdist_wininst' in sys.argv:
 
170
    import glob
 
171
    # doc files
 
172
    docs = glob.glob('doc/*.htm') + ['doc/default.css']
 
173
    # python's distutils-based win32 installer
 
174
    ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
 
175
            # help pages
 
176
            'data_files': [('Doc/Bazaar', docs)],
 
177
           }
 
178
 
 
179
    ARGS.update(META_INFO)
 
180
    ARGS.update(BZRLIB)
 
181
    ARGS.update(PKG_DATA)
 
182
    
 
183
    setup(**ARGS)
 
184
 
 
185
elif 'py2exe' in sys.argv:
 
186
    # py2exe setup
 
187
    import py2exe
 
188
 
 
189
    # pick real bzr version
 
190
    import bzrlib
 
191
 
 
192
    version_number = []
 
193
    for i in bzrlib.version_info[:4]:
 
194
        try:
 
195
            i = int(i)
 
196
        except ValueError:
 
197
            i = 0
 
198
        version_number.append(str(i))
 
199
    version_str = '.'.join(version_number)
 
200
 
 
201
    target = py2exe.build_exe.Target(script = "bzr",
 
202
                                     dest_base = "bzr",
 
203
                                     icon_resources = [(0,'bzr.ico')],
 
204
                                     name = META_INFO['name'],
 
205
                                     version = version_str,
 
206
                                     description = META_INFO['description'],
 
207
                                     author = META_INFO['author'],
 
208
                                     copyright = "(c) Canonical Ltd, 2005-2007",
 
209
                                     company_name = "Canonical Ltd.",
 
210
                                     comments = META_INFO['description'],
 
211
                                    )
 
212
 
 
213
    additional_packages =  []
 
214
    if sys.version.startswith('2.4'):
 
215
        # adding elementtree package
 
216
        additional_packages.append('elementtree')
 
217
    elif sys.version.startswith('2.5'):
 
218
        additional_packages.append('xml.etree')
 
219
    else:
 
220
        import warnings
 
221
        warnings.warn('Unknown Python version.\n'
 
222
                      'Please check setup.py script for compatibility.')
 
223
 
 
224
    options_list = {"py2exe": {"packages": BZRLIB['packages'] +
 
225
                                           additional_packages,
 
226
                               "excludes": ["Tkinter", "medusa"],
 
227
                               "dist_dir": "win32_bzr.exe",
 
228
                              },
 
229
                   }
 
230
    setup(options=options_list,
 
231
          console=[target,
 
232
                   'tools/win32/bzr_postinstall.py',
 
233
                  ],
 
234
          zipfile='lib/library.zip')
 
235
 
 
236
else:
 
237
    # std setup
 
238
    ARGS = {'scripts': ['bzr'],
 
239
            'data_files': [('man/man1', ['bzr.1'])],
 
240
            'cmdclass': command_classes,
 
241
            'ext_modules': ext_modules,
 
242
           }
 
243
    
 
244
    ARGS.update(META_INFO)
 
245
    ARGS.update(BZRLIB)
 
246
    ARGS.update(PKG_DATA)
 
247
 
 
248
    setup(**ARGS)