/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: John Arbash Meinel
  • Date: 2008-03-15 13:51:09 UTC
  • mfrom: (3280 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3281.
  • Revision ID: john@arbash-meinel.com-20080315135109-7v9gimdidd1s7llr
[merge] bzr.dev 3280

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
if sys.version_info < (2, 4):
 
13
    sys.stderr.write("[ERROR] Not a supported Python version. Need 2.4+\n")
 
14
    sys.exit(1)
 
15
 
 
16
import bzrlib
 
17
 
 
18
##
 
19
# META INFORMATION FOR SETUP
 
20
 
 
21
META_INFO = {'name':         'bzr',
 
22
             'version':      bzrlib.__version__,
 
23
             'author':       'Canonical Ltd',
 
24
             'author_email': 'bazaar@lists.canonical.com',
 
25
             'url':          'http://www.bazaar-vcs.org/',
 
26
             'description':  'Friendly distributed version control system',
 
27
             'license':      'GNU GPL v2',
 
28
            }
 
29
 
 
30
# The list of packages is automatically generated later. Add other things
 
31
# that are part of BZRLIB here.
 
32
BZRLIB = {}
 
33
 
 
34
PKG_DATA = {# install files from selftest suite
 
35
            'package_data': {'bzrlib': ['doc/api/*.txt',
 
36
                                        'tests/test_patches_data/*',
 
37
                                        'help_topics/en/*.txt',
 
38
                                       ]},
 
39
           }
 
40
 
 
41
 
 
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
 
 
63
BZRLIB['packages'] = get_bzrlib_packages()
 
64
 
6
65
 
7
66
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'])
 
67
from distutils.command.install_scripts import install_scripts
 
68
from distutils.command.build import build
 
69
 
 
70
###############################
 
71
# Overridden distutils actions
 
72
###############################
 
73
 
 
74
class my_install_scripts(install_scripts):
 
75
    """ Customized install_scripts distutils action.
 
76
    Create bzr.bat for win32.
 
77
    """
 
78
    def run(self):
 
79
        install_scripts.run(self)   # standard action
 
80
 
 
81
        if sys.platform == "win32":
 
82
            try:
 
83
                scripts_dir = os.path.join(sys.prefix, 'Scripts')
 
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)
 
89
                batch_path = os.path.join(self.install_dir, "bzr.bat")
 
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)
 
96
 
 
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):
 
104
        from bzrlib.win32utils import winver
 
105
        if winver == 'Windows NT':
 
106
            return '%*'
 
107
        else:
 
108
            return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
 
109
#/class my_install_scripts
 
110
 
 
111
 
 
112
class bzr_build(build):
 
113
    """Customized build distutils action.
 
114
    Generate bzr.1.
 
115
    """
 
116
    def run(self):
 
117
        build.run(self)
 
118
 
 
119
        import generate_docs
 
120
        generate_docs.main(argv=["bzr", "man"])
 
121
 
 
122
 
 
123
########################
 
124
## Setup
 
125
########################
 
126
 
 
127
command_classes = {'install_scripts': my_install_scripts,
 
128
                   'build': bzr_build}
 
129
from distutils import log
 
130
from distutils.errors import CCompilerError, DistutilsPlatformError
 
131
from distutils.extension import Extension
 
132
ext_modules = []
 
133
try:
 
134
    from Pyrex.Distutils import build_ext
 
135
except ImportError:
 
136
    have_pyrex = False
 
137
    # try to build the extension from the prior generated source.
 
138
    print
 
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.")
 
143
    print
 
144
    from distutils.command.build_ext import build_ext
 
145
else:
 
146
    have_pyrex = True
 
147
 
 
148
 
 
149
class build_ext_if_possible(build_ext):
 
150
 
 
151
    def run(self):
 
152
        try:
 
153
            build_ext.run(self)
 
154
        except DistutilsPlatformError, e:
 
155
            log.warn(str(e))
 
156
            log.warn('Extensions cannot be built, '
 
157
                     'will use the Python versions instead')
 
158
 
 
159
    def build_extension(self, ext):
 
160
        try:
 
161
            build_ext.build_extension(self, ext)
 
162
        except CCompilerError:
 
163
            log.warn('Building of "%s" extension failed, '
 
164
                     'will use the Python version instead' % (ext.name,))
 
165
 
 
166
 
 
167
# Override the build_ext if we have Pyrex available
 
168
command_classes['build_ext'] = build_ext_if_possible
 
169
unavailable_files = []
 
170
 
 
171
 
 
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
 
 
197
add_pyrex_extension('bzrlib._dirstate_helpers_c')
 
198
add_pyrex_extension('bzrlib._knit_load_data_c')
 
199
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
 
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
 
 
208
 
 
209
if 'bdist_wininst' in sys.argv:
 
210
    def find_docs():
 
211
        docs = []
 
212
        for root, dirs, files in os.walk('doc'):
 
213
            r = []
 
214
            for f in files:
 
215
                if (os.path.splitext(f)[1] in ('.html','.css','.png','.pdf')
 
216
                    or f == 'quick-start-summary.svg'):
 
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
 
 
227
    # python's distutils-based win32 installer
 
228
    ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
 
229
            'ext_modules': ext_modules,
 
230
            # help pages
 
231
            'data_files': find_docs(),
 
232
            # for building pyrex extensions
 
233
            'cmdclass': {'build_ext': build_ext_if_possible},
 
234
           }
 
235
 
 
236
    ARGS.update(META_INFO)
 
237
    ARGS.update(BZRLIB)
 
238
    ARGS.update(PKG_DATA)
 
239
    
 
240
    setup(**ARGS)
 
241
 
 
242
elif 'py2exe' in sys.argv:
 
243
    import glob
 
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'],
 
266
                                     copyright = "(c) Canonical Ltd, 2005-2007",
 
267
                                     company_name = "Canonical Ltd.",
 
268
                                     comments = META_INFO['description'],
 
269
                                    )
 
270
 
 
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('\\', '.')
 
277
        if module.endswith('__init__'):
 
278
            module = module[:-len('__init__')]
 
279
        includes.append(module)
 
280
 
 
281
    additional_packages = set()
 
282
    if sys.version.startswith('2.4'):
 
283
        # adding elementtree package
 
284
        additional_packages.add('elementtree')
 
285
    elif sys.version.startswith('2.5'):
 
286
        additional_packages.add('xml.etree')
 
287
    else:
 
288
        import warnings
 
289
        warnings.warn('Unknown Python version.\n'
 
290
                      'Please check setup.py script for compatibility.')
 
291
    # email package from std python library use lazy import,
 
292
    # so we need to explicitly add all package
 
293
    additional_packages.add('email')
 
294
 
 
295
    # text files for help topis
 
296
    text_topics = glob.glob('bzrlib/help_topics/en/*.txt')
 
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:
 
310
            target_dir = root[len('bzrlib/'):]  # install to 'plugins/...'
 
311
            plugins_files.append((target_dir, x))
 
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)
 
318
 
 
319
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
 
320
                               "includes": includes + mods,
 
321
                               "excludes": ["Tkinter", "medusa", "tools"],
 
322
                               "dist_dir": "win32_bzr.exe",
 
323
                              },
 
324
                   }
 
325
    setup(options=options_list,
 
326
          console=[target,
 
327
                   'tools/win32/bzr_postinstall.py',
 
328
                  ],
 
329
          zipfile='lib/library.zip',
 
330
          data_files=topics_files + plugins_files,
 
331
          )
 
332
 
 
333
else:
 
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
 
 
340
    # std setup
 
341
    ARGS = {'scripts': ['bzr'],
 
342
            'data_files': DATA_FILES,
 
343
            'cmdclass': command_classes,
 
344
            'ext_modules': ext_modules,
 
345
           }
 
346
 
 
347
    ARGS.update(META_INFO)
 
348
    ARGS.update(BZRLIB)
 
349
    ARGS.update(PKG_DATA)
 
350
 
 
351
    setup(**ARGS)