/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: James Westby
  • Date: 2008-02-25 23:41:06 UTC
  • mto: This revision was merged to the branch mainline in revision 3246.
  • Revision ID: jw+debian@jameswestby.net-20080225234106-9b4ql42w13ijewp3
Make version-info --custom imply --all.

When using a custom template you can use variables like {clean} which
are not enabled by default. This causes an ugly traceback.

This fixes the issue by implying --all when --custom (or more exactly
--template) is used, so that all variables are available in templates.

This was the easier fix than having the template code report that the
user should pass --check-clean to have {clean} available, but will
have a performance impact on all users of version-info --custom,
regardless of whether they use {clean}.

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
                                        'help_topics/en/*.txt',
 
34
                                       ]},
 
35
           }
 
36
 
 
37
######################################################################
 
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
 
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')
 
62
    sys.exit(1)
 
63
if getattr(os, "unsetenv", None) is not None:
 
64
    os.unsetenv(REINVOKE)
 
65
 
 
66
 
 
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
 
 
88
BZRLIB['packages'] = get_bzrlib_packages()
 
89
 
6
90
 
7
91
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'])
 
92
from distutils.command.install_scripts import install_scripts
 
93
from distutils.command.build import build
 
94
 
 
95
###############################
 
96
# Overridden distutils actions
 
97
###############################
 
98
 
 
99
class my_install_scripts(install_scripts):
 
100
    """ Customized install_scripts distutils action.
 
101
    Create bzr.bat for win32.
 
102
    """
 
103
    def run(self):
 
104
        install_scripts.run(self)   # standard action
 
105
 
 
106
        if sys.platform == "win32":
 
107
            try:
 
108
                scripts_dir = os.path.join(sys.prefix, 'Scripts')
 
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)
 
114
                batch_path = os.path.join(self.install_dir, "bzr.bat")
 
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)
 
121
 
 
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):
 
129
        from bzrlib.win32utils import winver
 
130
        if winver == 'Windows NT':
 
131
            return '%*'
 
132
        else:
 
133
            return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
 
134
#/class my_install_scripts
 
135
 
 
136
 
 
137
class bzr_build(build):
 
138
    """Customized build distutils action.
 
139
    Generate bzr.1.
 
140
    """
 
141
    def run(self):
 
142
        build.run(self)
 
143
 
 
144
        import generate_docs
 
145
        generate_docs.main(argv=["bzr", "man"])
 
146
 
 
147
 
 
148
########################
 
149
## Setup
 
150
########################
 
151
 
 
152
command_classes = {'install_scripts': my_install_scripts,
 
153
                   'build': bzr_build}
 
154
from distutils import log
 
155
from distutils.errors import CCompilerError, DistutilsPlatformError
 
156
from distutils.extension import Extension
 
157
ext_modules = []
 
158
try:
 
159
    from Pyrex.Distutils import build_ext
 
160
except ImportError:
 
161
    have_pyrex = False
 
162
    # try to build the extension from the prior generated source.
 
163
    print
 
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.")
 
168
    print
 
169
    from distutils.command.build_ext import build_ext
 
170
else:
 
171
    have_pyrex = True
 
172
 
 
173
 
 
174
class build_ext_if_possible(build_ext):
 
175
 
 
176
    def run(self):
 
177
        try:
 
178
            build_ext.run(self)
 
179
        except DistutilsPlatformError, e:
 
180
            log.warn(str(e))
 
181
            log.warn('Extensions cannot be built, '
 
182
                     'will use the Python versions instead')
 
183
 
 
184
    def build_extension(self, ext):
 
185
        try:
 
186
            build_ext.build_extension(self, ext)
 
187
        except CCompilerError:
 
188
            log.warn('Building of "%s" extension failed, '
 
189
                     'will use the Python version instead' % (ext.name,))
 
190
 
 
191
 
 
192
# Override the build_ext if we have Pyrex available
 
193
command_classes['build_ext'] = build_ext_if_possible
 
194
unavailable_files = []
 
195
 
 
196
 
 
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
 
 
222
add_pyrex_extension('bzrlib._dirstate_helpers_c')
 
223
add_pyrex_extension('bzrlib._knit_load_data_c')
 
224
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
 
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
 
 
233
 
 
234
if 'bdist_wininst' in sys.argv:
 
235
    def find_docs():
 
236
        docs = []
 
237
        for root, dirs, files in os.walk('doc'):
 
238
            r = []
 
239
            for f in files:
 
240
                if (os.path.splitext(f)[1] in ('.html','.css','.png','.pdf')
 
241
                    or f == 'quick-start-summary.svg'):
 
242
                    r.append(os.path.join(root, f))
 
243
            if r:
 
244
                relative = root[4:]
 
245
                if relative:
 
246
                    target = os.path.join('Doc\\Bazaar', relative)
 
247
                else:
 
248
                    target = 'Doc\\Bazaar'
 
249
                docs.append((target, r))
 
250
        return docs
 
251
 
 
252
    # python's distutils-based win32 installer
 
253
    ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
 
254
            'ext_modules': ext_modules,
 
255
            # help pages
 
256
            'data_files': find_docs(),
 
257
            # for building pyrex extensions
 
258
            'cmdclass': {'build_ext': build_ext_if_possible},
 
259
           }
 
260
 
 
261
    ARGS.update(META_INFO)
 
262
    ARGS.update(BZRLIB)
 
263
    ARGS.update(PKG_DATA)
 
264
    
 
265
    setup(**ARGS)
 
266
 
 
267
elif 'py2exe' in sys.argv:
 
268
    import glob
 
269
    # py2exe setup
 
270
    import py2exe
 
271
 
 
272
    # pick real bzr version
 
273
    import bzrlib
 
274
 
 
275
    version_number = []
 
276
    for i in bzrlib.version_info[:4]:
 
277
        try:
 
278
            i = int(i)
 
279
        except ValueError:
 
280
            i = 0
 
281
        version_number.append(str(i))
 
282
    version_str = '.'.join(version_number)
 
283
 
 
284
    target = py2exe.build_exe.Target(script = "bzr",
 
285
                                     dest_base = "bzr",
 
286
                                     icon_resources = [(0,'bzr.ico')],
 
287
                                     name = META_INFO['name'],
 
288
                                     version = version_str,
 
289
                                     description = META_INFO['description'],
 
290
                                     author = META_INFO['author'],
 
291
                                     copyright = "(c) Canonical Ltd, 2005-2007",
 
292
                                     company_name = "Canonical Ltd.",
 
293
                                     comments = META_INFO['description'],
 
294
                                    )
 
295
 
 
296
    packages = BZRLIB['packages']
 
297
    packages.remove('bzrlib')
 
298
    packages = [i for i in packages if not i.startswith('bzrlib.plugins')]
 
299
    includes = []
 
300
    for i in glob.glob('bzrlib\\*.py'):
 
301
        module = i[:-3].replace('\\', '.')
 
302
        if module.endswith('__init__'):
 
303
            module = module[:-len('__init__')]
 
304
        includes.append(module)
 
305
 
 
306
    additional_packages = set()
 
307
    if sys.version.startswith('2.4'):
 
308
        # adding elementtree package
 
309
        additional_packages.add('elementtree')
 
310
    elif sys.version.startswith('2.5'):
 
311
        additional_packages.add('xml.etree')
 
312
    else:
 
313
        import warnings
 
314
        warnings.warn('Unknown Python version.\n'
 
315
                      'Please check setup.py script for compatibility.')
 
316
    # email package from std python library use lazy import,
 
317
    # so we need to explicitly add all package
 
318
    additional_packages.add('email')
 
319
 
 
320
    # text files for help topis
 
321
    text_topics = glob.glob('bzrlib/help_topics/en/*.txt')
 
322
    topics_files = [('lib/help_topics/en', text_topics)]
 
323
 
 
324
    # built-in plugins
 
325
    plugins_files = []
 
326
    for root, dirs, files in os.walk('bzrlib/plugins'):
 
327
        x = []
 
328
        for i in files:
 
329
            if not i.endswith('.py'):
 
330
                continue
 
331
            if i == '__init__.py' and root == 'bzrlib/plugins':
 
332
                continue
 
333
            x.append(os.path.join(root, i))
 
334
        if x:
 
335
            target_dir = root[len('bzrlib/'):]  # install to 'plugins/...'
 
336
            plugins_files.append((target_dir, x))
 
337
    # find modules for built-in plugins
 
338
    import tools.package_mf
 
339
    mf = tools.package_mf.CustomModuleFinder()
 
340
    mf.run_package('bzrlib/plugins')
 
341
    packs, mods = mf.get_result()
 
342
    additional_packages.update(packs)
 
343
 
 
344
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
 
345
                               "includes": includes + mods,
 
346
                               "excludes": ["Tkinter", "medusa", "tools"],
 
347
                               "dist_dir": "win32_bzr.exe",
 
348
                              },
 
349
                   }
 
350
    setup(options=options_list,
 
351
          console=[target,
 
352
                   'tools/win32/bzr_postinstall.py',
 
353
                  ],
 
354
          zipfile='lib/library.zip',
 
355
          data_files=topics_files + plugins_files,
 
356
          )
 
357
 
 
358
else:
 
359
    # ad-hoc for easy_install
 
360
    DATA_FILES = []
 
361
    if not 'bdist_egg' in sys.argv:
 
362
        # generate and install bzr.1 only with plain install, not easy_install one
 
363
        DATA_FILES = [('man/man1', ['bzr.1'])]
 
364
 
 
365
    # std setup
 
366
    ARGS = {'scripts': ['bzr'],
 
367
            'data_files': DATA_FILES,
 
368
            'cmdclass': command_classes,
 
369
            'ext_modules': ext_modules,
 
370
           }
 
371
 
 
372
    ARGS.update(META_INFO)
 
373
    ARGS.update(BZRLIB)
 
374
    ARGS.update(PKG_DATA)
 
375
 
 
376
    setup(**ARGS)