~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-26 06:24:01 UTC
  • mto: This revision was merged to the branch mainline in revision 2376.
  • Revision ID: andrew.bennetts@canonical.com-20070326062401-k3nbefzje5332jaf
Deal with review comments from Robert:

  * Add my name to the NEWS file
  * Move the test case to a new module in branch_implementations
  * Remove revision_history cruft from identitymap and test_identitymap
  * Improve some docstrings

Also, this fixes a bug where revision_history was not returning a copy of the
cached data, allowing the cache to be corrupted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
"""
8
8
 
9
9
import os
10
 
import os.path
11
10
import sys
12
11
 
13
 
if sys.version_info < (2, 4):
14
 
    sys.stderr.write("[ERROR] Not a supported Python version. Need 2.4+\n")
15
 
    sys.exit(1)
16
 
 
17
 
# NOTE: The directory containing setup.py, whether run by 'python setup.py' or
18
 
# './setup.py' or the equivalent with another path, should always be at the
19
 
# start of the path, so this should find the right one...
20
12
import bzrlib
21
13
 
22
 
def get_long_description():
23
 
    dirname = os.path.dirname(__file__)
24
 
    readme = os.path.join(dirname, 'README')
25
 
    f = open(readme, 'rb')
26
 
    try:
27
 
        return f.read()
28
 
    finally:
29
 
        f.close()
30
 
 
31
 
 
32
14
##
33
15
# META INFORMATION FOR SETUP
34
 
# see http://docs.python.org/dist/meta-data.html
35
 
META_INFO = {
36
 
    'name':         'bzr',
37
 
    'version':      bzrlib.__version__,
38
 
    'author':       'Canonical Ltd',
39
 
    'author_email': 'bazaar@lists.canonical.com',
40
 
    'url':          'http://www.bazaar-vcs.org/',
41
 
    'description':  'Friendly distributed version control system',
42
 
    'license':      'GNU GPL v2',
43
 
    'download_url': 'http://bazaar-vcs.org/Download',
44
 
    'long_description': get_long_description(),
45
 
    'classifiers': [
46
 
        'Development Status :: 6 - Mature',
47
 
        'Environment :: Console',
48
 
        'Intended Audience :: Developers',
49
 
        'Intended Audience :: System Administrators',
50
 
        'License :: OSI Approved :: GNU General Public License (GPL)',
51
 
        'Operating System :: Microsoft :: Windows',
52
 
        'Operating System :: OS Independent',
53
 
        'Operating System :: POSIX',
54
 
        'Programming Language :: Python',
55
 
        'Programming Language :: C',
56
 
        'Topic :: Software Development :: Version Control',
57
 
        ],
58
 
    }
 
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
            }
59
25
 
60
26
# The list of packages is automatically generated later. Add other things
61
27
# that are part of BZRLIB here.
64
30
PKG_DATA = {# install files from selftest suite
65
31
            'package_data': {'bzrlib': ['doc/api/*.txt',
66
32
                                        'tests/test_patches_data/*',
67
 
                                        'help_topics/en/*.txt',
68
33
                                       ]},
69
34
           }
70
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
 
71
64
 
72
65
def get_bzrlib_packages():
73
66
    """Recurse through the bzrlib directory, and extract the package names"""
110
103
 
111
104
        if sys.platform == "win32":
112
105
            try:
113
 
                scripts_dir = os.path.join(sys.prefix, 'Scripts')
 
106
                scripts_dir = self.install_dir
114
107
                script_path = self._quoted_path(os.path.join(scripts_dir,
115
108
                                                             "bzr"))
116
109
                python_exe = self._quoted_path(sys.executable)
117
110
                args = self._win_batch_args()
118
111
                batch_str = "@%s %s %s" % (python_exe, script_path, args)
119
 
                batch_path = os.path.join(self.install_dir, "bzr.bat")
 
112
                batch_path = script_path + ".bat"
120
113
                f = file(batch_path, "w")
121
114
                f.write(batch_str)
122
115
                f.close()
154
147
## Setup
155
148
########################
156
149
 
157
 
command_classes = {'install_scripts': my_install_scripts,
158
 
                   'build': bzr_build}
159
 
from distutils import log
160
 
from distutils.errors import CCompilerError, DistutilsPlatformError
161
 
from distutils.extension import Extension
162
 
ext_modules = []
163
 
try:
164
 
    from Pyrex.Distutils import build_ext
165
 
except ImportError:
166
 
    have_pyrex = False
167
 
    # try to build the extension from the prior generated source.
168
 
    print
169
 
    print ("The python package 'Pyrex' is not available."
170
 
           " If the .c files are available,")
171
 
    print ("they will be built,"
172
 
           " but modifying the .pyx files will not rebuild them.")
173
 
    print
174
 
    from distutils.command.build_ext import build_ext
175
 
else:
176
 
    have_pyrex = True
177
 
 
178
 
 
179
 
class build_ext_if_possible(build_ext):
180
 
 
181
 
    def run(self):
182
 
        try:
183
 
            build_ext.run(self)
184
 
        except DistutilsPlatformError, e:
185
 
            log.warn(str(e))
186
 
            log.warn('Extensions cannot be built, '
187
 
                     'will use the Python versions instead')
188
 
 
189
 
    def build_extension(self, ext):
190
 
        try:
191
 
            build_ext.build_extension(self, ext)
192
 
        except CCompilerError:
193
 
            log.warn('Building of "%s" extension failed, '
194
 
                     'will use the Python version instead' % (ext.name,))
195
 
 
196
 
 
197
 
# Override the build_ext if we have Pyrex available
198
 
command_classes['build_ext'] = build_ext_if_possible
199
 
unavailable_files = []
200
 
 
201
 
 
202
 
def add_pyrex_extension(module_name, **kwargs):
203
 
    """Add a pyrex module to build.
204
 
 
205
 
    This will use Pyrex to auto-generate the .c file if it is available.
206
 
    Otherwise it will fall back on the .c file. If the .c file is not
207
 
    available, it will warn, and not add anything.
208
 
 
209
 
    You can pass any extra options to Extension through kwargs. One example is
210
 
    'libraries = []'.
211
 
 
212
 
    :param module_name: The python path to the module. This will be used to
213
 
        determine the .pyx and .c files to use.
214
 
    """
215
 
    path = module_name.replace('.', '/')
216
 
    pyrex_name = path + '.pyx'
217
 
    c_name = path + '.c'
218
 
    if have_pyrex:
219
 
        ext_modules.append(Extension(module_name, [pyrex_name], **kwargs))
220
 
    else:
221
 
        if not os.path.isfile(c_name):
222
 
            unavailable_files.append(c_name)
223
 
        else:
224
 
            ext_modules.append(Extension(module_name, [c_name], **kwargs))
225
 
 
226
 
 
227
 
add_pyrex_extension('bzrlib._dirstate_helpers_c')
228
 
add_pyrex_extension('bzrlib._knit_load_data_c')
229
 
if sys.platform == 'win32':
230
 
    # pyrex uses the macro WIN32 to detect the platform, even though it should
231
 
    # be using something like _WIN32 or MS_WINDOWS, oh well, we can give it the
232
 
    # right value.
233
 
    add_pyrex_extension('bzrlib._walkdirs_win32',
234
 
                        define_macros=[('WIN32', None)])
235
 
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
236
 
 
237
 
 
238
 
if unavailable_files:
239
 
    print 'C extension(s) not found:'
240
 
    print '   %s' % ('\n  '.join(unavailable_files),)
241
 
    print 'The python versions will be used instead.'
242
 
    print
243
 
 
244
 
 
245
150
if 'bdist_wininst' in sys.argv:
246
 
    def find_docs():
247
 
        docs = []
248
 
        for root, dirs, files in os.walk('doc'):
249
 
            r = []
250
 
            for f in files:
251
 
                if (os.path.splitext(f)[1] in ('.html','.css','.png','.pdf')
252
 
                    or f == 'quick-start-summary.svg'):
253
 
                    r.append(os.path.join(root, f))
254
 
            if r:
255
 
                relative = root[4:]
256
 
                if relative:
257
 
                    target = os.path.join('Doc\\Bazaar', relative)
258
 
                else:
259
 
                    target = 'Doc\\Bazaar'
260
 
                docs.append((target, r))
261
 
        return docs
262
 
 
 
151
    import glob
 
152
    # doc files
 
153
    docs = glob.glob('doc/*.htm') + ['doc/default.css']
263
154
    # python's distutils-based win32 installer
264
155
    ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
265
 
            'ext_modules': ext_modules,
266
156
            # help pages
267
 
            'data_files': find_docs(),
268
 
            # for building pyrex extensions
269
 
            'cmdclass': {'build_ext': build_ext_if_possible},
 
157
            'data_files': [('Doc/Bazaar', docs)],
270
158
           }
271
159
 
272
160
    ARGS.update(META_INFO)
276
164
    setup(**ARGS)
277
165
 
278
166
elif 'py2exe' in sys.argv:
279
 
    import glob
280
167
    # py2exe setup
281
168
    import py2exe
282
169
 
304
191
                                     comments = META_INFO['description'],
305
192
                                    )
306
193
 
307
 
    packages = BZRLIB['packages']
308
 
    packages.remove('bzrlib')
309
 
    packages = [i for i in packages if not i.startswith('bzrlib.plugins')]
310
 
    includes = []
311
 
    for i in glob.glob('bzrlib\\*.py'):
312
 
        module = i[:-3].replace('\\', '.')
313
 
        if module.endswith('__init__'):
314
 
            module = module[:-len('__init__')]
315
 
        includes.append(module)
316
 
 
317
 
    additional_packages = set()
 
194
    additional_packages =  []
318
195
    if sys.version.startswith('2.4'):
319
196
        # adding elementtree package
320
 
        additional_packages.add('elementtree')
 
197
        additional_packages.append('elementtree')
321
198
    elif sys.version.startswith('2.5'):
322
 
        additional_packages.add('xml.etree')
 
199
        additional_packages.append('xml.etree')
323
200
    else:
324
201
        import warnings
325
202
        warnings.warn('Unknown Python version.\n'
326
203
                      'Please check setup.py script for compatibility.')
327
 
    # email package from std python library use lazy import,
328
 
    # so we need to explicitly add all package
329
 
    additional_packages.add('email')
330
 
 
331
 
    # text files for help topis
332
 
    text_topics = glob.glob('bzrlib/help_topics/en/*.txt')
333
 
    topics_files = [('lib/help_topics/en', text_topics)]
334
 
 
335
 
    # built-in plugins
336
 
    plugins_files = []
337
 
    for root, dirs, files in os.walk('bzrlib/plugins'):
338
 
        x = []
339
 
        for i in files:
340
 
            if not i.endswith('.py'):
341
 
                continue
342
 
            if i == '__init__.py' and root == 'bzrlib/plugins':
343
 
                continue
344
 
            x.append(os.path.join(root, i))
345
 
        if x:
346
 
            target_dir = root[len('bzrlib/'):]  # install to 'plugins/...'
347
 
            plugins_files.append((target_dir, x))
348
 
    # find modules for built-in plugins
349
 
    import tools.package_mf
350
 
    mf = tools.package_mf.CustomModuleFinder()
351
 
    mf.run_package('bzrlib/plugins')
352
 
    packs, mods = mf.get_result()
353
 
    additional_packages.update(packs)
354
 
 
355
 
    # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls
356
 
    # in on Vista.
357
 
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
358
 
                               "includes": includes + mods,
359
 
                               "excludes": ["Tkinter", "medusa", "tools"],
360
 
                               "dll_excludes": ["MSWSOCK.dll"],
 
204
 
 
205
    options_list = {"py2exe": {"packages": BZRLIB['packages'] +
 
206
                                           additional_packages,
 
207
                               "excludes": ["Tkinter", "medusa"],
361
208
                               "dist_dir": "win32_bzr.exe",
362
209
                              },
363
210
                   }
365
212
          console=[target,
366
213
                   'tools/win32/bzr_postinstall.py',
367
214
                  ],
368
 
          zipfile='lib/library.zip',
369
 
          data_files=topics_files + plugins_files,
370
 
          )
 
215
          zipfile='lib/library.zip')
371
216
 
372
217
else:
373
 
    # ad-hoc for easy_install
374
 
    DATA_FILES = []
375
 
    if not 'bdist_egg' in sys.argv:
376
 
        # generate and install bzr.1 only with plain install, not easy_install one
377
 
        DATA_FILES = [('man/man1', ['bzr.1'])]
378
 
 
379
218
    # std setup
380
219
    ARGS = {'scripts': ['bzr'],
381
 
            'data_files': DATA_FILES,
382
 
            'cmdclass': command_classes,
383
 
            'ext_modules': ext_modules,
 
220
            'data_files': [('man/man1', ['bzr.1'])],
 
221
            'cmdclass': {'build': bzr_build,
 
222
                         'install_scripts': my_install_scripts,
 
223
                        },
384
224
           }
385
 
 
 
225
    
386
226
    ARGS.update(META_INFO)
387
227
    ARGS.update(BZRLIB)
388
228
    ARGS.update(PKG_DATA)