~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-01-03 18:09:01 UTC
  • mfrom: (3159.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20080103180901-w987y1ftqoh02qbm
(vila) Fix #179368 by keeping the current range hint on
        ShortReadvErrors

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
PKG_DATA = {# install files from selftest suite
31
31
            'package_data': {'bzrlib': ['doc/api/*.txt',
32
32
                                        'tests/test_patches_data/*',
 
33
                                        'help_topics/en/*.txt',
33
34
                                       ]},
34
35
           }
35
36
 
55
56
                os.execvp(python, [python] + sys.argv)
56
57
            except OSError:
57
58
                pass
58
 
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
59
 
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
 
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')
60
62
    sys.exit(1)
61
63
if getattr(os, "unsetenv", None) is not None:
62
64
    os.unsetenv(REINVOKE)
103
105
 
104
106
        if sys.platform == "win32":
105
107
            try:
106
 
                scripts_dir = self.install_dir
 
108
                scripts_dir = os.path.join(sys.prefix, 'Scripts')
107
109
                script_path = self._quoted_path(os.path.join(scripts_dir,
108
110
                                                             "bzr"))
109
111
                python_exe = self._quoted_path(sys.executable)
110
112
                args = self._win_batch_args()
111
113
                batch_str = "@%s %s %s" % (python_exe, script_path, args)
112
 
                batch_path = script_path + ".bat"
 
114
                batch_path = os.path.join(self.install_dir, "bzr.bat")
113
115
                f = file(batch_path, "w")
114
116
                f.write(batch_str)
115
117
                f.close()
148
150
########################
149
151
 
150
152
command_classes = {'install_scripts': my_install_scripts,
151
 
                  'build': bzr_build}
 
153
                   'build': bzr_build}
 
154
from distutils import log
 
155
from distutils.errors import CCompilerError, DistutilsPlatformError
 
156
from distutils.extension import Extension
152
157
ext_modules = []
153
158
try:
154
159
    from Pyrex.Distutils import build_ext
155
160
except ImportError:
 
161
    have_pyrex = False
156
162
    # 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.")
 
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
159
169
    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
170
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
 
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
 
168
233
 
169
234
if 'bdist_wininst' in sys.argv:
170
 
    import glob
171
 
    # doc files
172
 
    docs = glob.glob('doc/*.htm') + ['doc/default.css']
173
 
    dev_docs = glob.glob('doc/developers/*.htm')
 
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
                    r.append(os.path.join(root, f))
 
242
            if r:
 
243
                relative = root[4:]
 
244
                if relative:
 
245
                    target = os.path.join('Doc\\Bazaar', relative)
 
246
                else:
 
247
                    target = 'Doc\\Bazaar'
 
248
                docs.append((target, r))
 
249
        return docs
 
250
 
174
251
    # python's distutils-based win32 installer
175
252
    ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
 
253
            'ext_modules': ext_modules,
176
254
            # help pages
177
 
            'data_files': [('Doc/Bazaar', docs),
178
 
                           ('Doc/Bazaar/developers', dev_docs),
179
 
                          ],
 
255
            'data_files': find_docs(),
 
256
            # for building pyrex extensions
 
257
            'cmdclass': {'build_ext': build_ext_if_possible},
180
258
           }
181
259
 
182
260
    ARGS.update(META_INFO)
223
301
        import warnings
224
302
        warnings.warn('Unknown Python version.\n'
225
303
                      'Please check setup.py script for compatibility.')
 
304
    # email package from std python library use lazy import,
 
305
    # so we need to explicitly add all package
 
306
    additional_packages.append('email')
 
307
 
 
308
    # text files for help topis
 
309
    import glob
 
310
    text_topics = glob.glob('bzrlib/help_topics/en/*.txt')
226
311
 
227
312
    options_list = {"py2exe": {"packages": BZRLIB['packages'] +
228
313
                                           additional_packages,
234
319
          console=[target,
235
320
                   'tools/win32/bzr_postinstall.py',
236
321
                  ],
237
 
          zipfile='lib/library.zip')
 
322
          zipfile='lib/library.zip',
 
323
          data_files=[('lib/help_topics/en', text_topics)],
 
324
          )
238
325
 
239
326
else:
 
327
    # ad-hoc for easy_install
 
328
    DATA_FILES = []
 
329
    if not 'bdist_egg' in sys.argv:
 
330
        # generate and install bzr.1 only with plain install, not easy_install one
 
331
        DATA_FILES = [('man/man1', ['bzr.1'])]
 
332
 
240
333
    # std setup
241
334
    ARGS = {'scripts': ['bzr'],
242
 
            'data_files': [('man/man1', ['bzr.1'])],
 
335
            'data_files': DATA_FILES,
243
336
            'cmdclass': command_classes,
244
337
            'ext_modules': ext_modules,
245
338
           }
246
 
    
 
339
 
247
340
    ARGS.update(META_INFO)
248
341
    ARGS.update(BZRLIB)
249
342
    ARGS.update(PKG_DATA)