~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-09-20 02:40:52 UTC
  • mfrom: (2835.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070920024052-y2l7r5o00zrpnr73
No longer propagate index differences automatically (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
6
 
 
 
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
######################################################################
7
37
# Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
8
38
# including bzrlib.help
9
39
 
10
 
import os, sys
11
 
 
12
40
try:
13
41
    version_info = sys.version_info
14
42
except AttributeError:
30
58
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
31
59
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
32
60
    sys.exit(1)
33
 
if hasattr(os, "unsetenv"):
 
61
if getattr(os, "unsetenv", None) is not None:
34
62
    os.unsetenv(REINVOKE)
35
63
 
36
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
 
 
88
 
37
89
from distutils.core import setup
38
90
from distutils.command.install_scripts import install_scripts
39
91
from distutils.command.build import build
47
99
    Create bzr.bat for win32.
48
100
    """
49
101
    def run(self):
50
 
        import os
51
 
        import sys
52
 
 
53
102
        install_scripts.run(self)   # standard action
54
103
 
55
104
        if sys.platform == "win32":
56
105
            try:
57
 
                scripts_dir = self.install_dir
58
 
                script_path = os.path.join(scripts_dir, "bzr")
59
 
                batch_str = "@%s %s %%*\n" % (sys.executable, script_path)
60
 
                batch_path = script_path + ".bat"
 
106
                scripts_dir = os.path.join(sys.prefix, 'Scripts')
 
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 = os.path.join(self.install_dir, "bzr.bat")
61
113
                f = file(batch_path, "w")
62
114
                f.write(batch_str)
63
115
                f.close()
65
117
            except Exception, e:
66
118
                print "ERROR: Unable to create %s: %s" % (batch_path, e)
67
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
 
68
134
 
69
135
class bzr_build(build):
70
136
    """Customized build distutils action.
76
142
        import generate_docs
77
143
        generate_docs.main(argv=["bzr", "man"])
78
144
 
 
145
 
79
146
########################
80
147
## Setup
81
148
########################
82
149
 
83
 
setup(name='bzr',
84
 
      version='0.8pre',
85
 
      author='Martin Pool',
86
 
      author_email='mbp@sourcefrog.net',
87
 
      url='http://www.bazaar-ng.org/',
88
 
      description='Friendly distributed version control system',
89
 
      license='GNU GPL v2',
90
 
      packages=['bzrlib',
91
 
                'bzrlib.doc',
92
 
                'bzrlib.doc.api',
93
 
                'bzrlib.export',
94
 
                'bzrlib.plugins',
95
 
                'bzrlib.plugins.launchpad',
96
 
                'bzrlib.store',
97
 
                'bzrlib.store.revision',
98
 
                'bzrlib.store.versioned',
99
 
                'bzrlib.tests',
100
 
                'bzrlib.tests.blackbox',
101
 
                'bzrlib.tests.branch_implementations',
102
 
                'bzrlib.tests.bzrdir_implementations',
103
 
                'bzrlib.tests.interrepository_implementations',
104
 
                'bzrlib.tests.interversionedfile_implementations',
105
 
                'bzrlib.tests.repository_implementations',
106
 
                'bzrlib.tests.revisionstore_implementations',
107
 
                'bzrlib.tests.workingtree_implementations',
108
 
                'bzrlib.transport',
109
 
                'bzrlib.transport.http',
110
 
                'bzrlib.ui',
111
 
                'bzrlib.util',
112
 
                'bzrlib.util.elementtree',
113
 
                'bzrlib.util.effbot.org',
114
 
                'bzrlib.util.configobj',
115
 
                ],
116
 
      scripts=['bzr'],
117
 
      cmdclass={'install_scripts': my_install_scripts, 'build': bzr_build},
118
 
      data_files=[('man/man1', ['bzr.1'])],
119
 
    #   todo: install the txt files from bzrlib.doc.api.
120
 
     )
 
150
command_classes = {'install_scripts': my_install_scripts,
 
151
                   'build': bzr_build}
 
152
from distutils.extension import Extension
 
153
ext_modules = []
 
154
try:
 
155
    from Pyrex.Distutils import build_ext
 
156
except ImportError:
 
157
    have_pyrex = False
 
158
    # try to build the extension from the prior generated source.
 
159
    print
 
160
    print ("The python package 'Pyrex' is not available."
 
161
           " If the .c files are available,")
 
162
    print ("they will be built,"
 
163
           " but modifying the .pyx files will not rebuild them.")
 
164
    print
 
165
    from distutils.command.build_ext import build_ext
 
166
else:
 
167
    have_pyrex = True
 
168
# Override the build_ext if we have Pyrex available
 
169
command_classes['build_ext'] = build_ext
 
170
unavailable_files = []
 
171
 
 
172
 
 
173
def add_pyrex_extension(module_name, **kwargs):
 
174
    """Add a pyrex module to build.
 
175
 
 
176
    This will use Pyrex to auto-generate the .c file if it is available.
 
177
    Otherwise it will fall back on the .c file. If the .c file is not
 
178
    available, it will warn, and not add anything.
 
179
 
 
180
    You can pass any extra options to Extension through kwargs. One example is
 
181
    'libraries = []'.
 
182
 
 
183
    :param module_name: The python path to the module. This will be used to
 
184
        determine the .pyx and .c files to use.
 
185
    """
 
186
    path = module_name.replace('.', '/')
 
187
    pyrex_name = path + '.pyx'
 
188
    c_name = path + '.c'
 
189
    if have_pyrex:
 
190
        ext_modules.append(Extension(module_name, [pyrex_name]))
 
191
    else:
 
192
        if not os.path.isfile(c_name):
 
193
            unavailable_files.append(c_name)
 
194
        else:
 
195
            ext_modules.append(Extension(module_name, [c_name]))
 
196
 
 
197
 
 
198
add_pyrex_extension('bzrlib._dirstate_helpers_c')
 
199
add_pyrex_extension('bzrlib._knit_load_data_c')
 
200
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
 
201
 
 
202
 
 
203
if unavailable_files:
 
204
    print 'C extension(s) not found:'
 
205
    print '   %s' % ('\n  '.join(unavailable_files),)
 
206
    print 'The python versions will be used instead.'
 
207
    print
 
208
 
 
209
 
 
210
if 'bdist_wininst' in sys.argv:
 
211
    def find_docs():
 
212
        docs = []
 
213
        for root, dirs, files in os.walk('doc'):
 
214
            r = []
 
215
            for f in files:
 
216
                if os.path.splitext(f)[1] in ('.html', '.css'):
 
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},
 
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
    # py2exe setup
 
244
    import py2exe
 
245
 
 
246
    # pick real bzr version
 
247
    import bzrlib
 
248
 
 
249
    version_number = []
 
250
    for i in bzrlib.version_info[:4]:
 
251
        try:
 
252
            i = int(i)
 
253
        except ValueError:
 
254
            i = 0
 
255
        version_number.append(str(i))
 
256
    version_str = '.'.join(version_number)
 
257
 
 
258
    target = py2exe.build_exe.Target(script = "bzr",
 
259
                                     dest_base = "bzr",
 
260
                                     icon_resources = [(0,'bzr.ico')],
 
261
                                     name = META_INFO['name'],
 
262
                                     version = version_str,
 
263
                                     description = META_INFO['description'],
 
264
                                     author = META_INFO['author'],
 
265
                                     copyright = "(c) Canonical Ltd, 2005-2007",
 
266
                                     company_name = "Canonical Ltd.",
 
267
                                     comments = META_INFO['description'],
 
268
                                    )
 
269
 
 
270
    additional_packages =  []
 
271
    if sys.version.startswith('2.4'):
 
272
        # adding elementtree package
 
273
        additional_packages.append('elementtree')
 
274
    elif sys.version.startswith('2.5'):
 
275
        additional_packages.append('xml.etree')
 
276
    else:
 
277
        import warnings
 
278
        warnings.warn('Unknown Python version.\n'
 
279
                      'Please check setup.py script for compatibility.')
 
280
    # email package from std python library use lazy import,
 
281
    # so we need to explicitly add all package
 
282
    additional_packages.append('email')
 
283
 
 
284
    options_list = {"py2exe": {"packages": BZRLIB['packages'] +
 
285
                                           additional_packages,
 
286
                               "excludes": ["Tkinter", "medusa", "tools"],
 
287
                               "dist_dir": "win32_bzr.exe",
 
288
                              },
 
289
                   }
 
290
    setup(options=options_list,
 
291
          console=[target,
 
292
                   'tools/win32/bzr_postinstall.py',
 
293
                  ],
 
294
          zipfile='lib/library.zip')
 
295
 
 
296
else:
 
297
    # ad-hoc for easy_install
 
298
    DATA_FILES = []
 
299
    if not 'bdist_egg' in sys.argv:
 
300
        # generate and install bzr.1 only with plain install, not easy_install one
 
301
        DATA_FILES = [('man/man1', ['bzr.1'])]
 
302
 
 
303
    # std setup
 
304
    ARGS = {'scripts': ['bzr'],
 
305
            'data_files': DATA_FILES,
 
306
            'cmdclass': command_classes,
 
307
            'ext_modules': ext_modules,
 
308
           }
 
309
 
 
310
    ARGS.update(META_INFO)
 
311
    ARGS.update(BZRLIB)
 
312
    ARGS.update(PKG_DATA)
 
313
 
 
314
    setup(**ARGS)