~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Martin Pool
  • Date: 2005-11-04 01:46:31 UTC
  • mto: (1185.33.49 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 1512.
  • Revision ID: mbp@sourcefrog.net-20051104014631-750e0ad4172c952c
Make biobench directly executable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/env python
2
2
 
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 os.path
11
 
import sys
12
 
 
13
 
if sys.version_info < (2, 4):
14
 
    sys.stderr.write("[ERROR] Not a supported Python version. Need 2.4+\n")
 
3
# This is an installation script for bzr.  Run it with
 
4
# './setup.py install', or
 
5
# './setup.py --help' for more options
 
6
 
 
7
# Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
 
8
# including bzrlib.help
 
9
 
 
10
import os, sys
 
11
 
 
12
try:
 
13
    version_info = sys.version_info
 
14
except AttributeError:
 
15
    version_info = 1, 5 # 1.5 or older
 
16
 
 
17
REINVOKE = "__BZR_REINVOKE"
 
18
NEED_VERS = (2, 4)
 
19
KNOWN_PYTHONS = ('python2.4',)
 
20
 
 
21
if version_info < NEED_VERS:
 
22
    if not os.environ.has_key(REINVOKE):
 
23
        # mutating os.environ doesn't work in old Pythons
 
24
        os.putenv(REINVOKE, "1")
 
25
        for python in KNOWN_PYTHONS:
 
26
            try:
 
27
                os.execvp(python, [python] + sys.argv)
 
28
            except OSError:
 
29
                pass
 
30
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
 
31
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
15
32
    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
 
import bzrlib
21
 
 
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
 
##
33
 
# 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
 
    }
59
 
 
60
 
# The list of packages is automatically generated later. Add other things
61
 
# that are part of BZRLIB here.
62
 
BZRLIB = {}
63
 
 
64
 
PKG_DATA = {# install files from selftest suite
65
 
            'package_data': {'bzrlib': ['doc/api/*.txt',
66
 
                                        'tests/test_patches_data/*',
67
 
                                        'help_topics/en/*.txt',
68
 
                                       ]},
69
 
           }
70
 
 
71
 
 
72
 
def get_bzrlib_packages():
73
 
    """Recurse through the bzrlib directory, and extract the package names"""
74
 
 
75
 
    packages = []
76
 
    base_path = os.path.dirname(os.path.abspath(bzrlib.__file__))
77
 
    for root, dirs, files in os.walk(base_path):
78
 
        if '__init__.py' in files:
79
 
            assert root.startswith(base_path)
80
 
            # Get just the path below bzrlib
81
 
            package_path = root[len(base_path):]
82
 
            # Remove leading and trailing slashes
83
 
            package_path = package_path.strip('\\/')
84
 
            if not package_path:
85
 
                package_name = 'bzrlib'
86
 
            else:
87
 
                package_name = ('bzrlib.' +
88
 
                            package_path.replace('/', '.').replace('\\', '.'))
89
 
            packages.append(package_name)
90
 
    return sorted(packages)
91
 
 
92
 
 
93
 
BZRLIB['packages'] = get_bzrlib_packages()
 
33
if hasattr(os, "unsetenv"):
 
34
    os.unsetenv(REINVOKE)
94
35
 
95
36
 
96
37
from distutils.core import setup
106
47
    Create bzr.bat for win32.
107
48
    """
108
49
    def run(self):
 
50
        import os
 
51
        import sys
 
52
 
109
53
        install_scripts.run(self)   # standard action
110
54
 
111
55
        if sys.platform == "win32":
112
56
            try:
113
 
                scripts_dir = os.path.join(sys.prefix, 'Scripts')
114
 
                script_path = self._quoted_path(os.path.join(scripts_dir,
115
 
                                                             "bzr"))
116
 
                python_exe = self._quoted_path(sys.executable)
117
 
                args = self._win_batch_args()
118
 
                batch_str = "@%s %s %s" % (python_exe, script_path, args)
119
 
                batch_path = os.path.join(self.install_dir, "bzr.bat")
 
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"
120
61
                f = file(batch_path, "w")
121
62
                f.write(batch_str)
122
63
                f.close()
124
65
            except Exception, e:
125
66
                print "ERROR: Unable to create %s: %s" % (batch_path, e)
126
67
 
127
 
    def _quoted_path(self, path):
128
 
        if ' ' in path:
129
 
            return '"' + path + '"'
130
 
        else:
131
 
            return path
132
 
 
133
 
    def _win_batch_args(self):
134
 
        from bzrlib.win32utils import winver
135
 
        if winver == 'Windows NT':
136
 
            return '%*'
137
 
        else:
138
 
            return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
139
 
#/class my_install_scripts
140
 
 
141
68
 
142
69
class bzr_build(build):
143
70
    """Customized build distutils action.
146
73
    def run(self):
147
74
        build.run(self)
148
75
 
149
 
        import generate_docs
150
 
        generate_docs.main(argv=["bzr", "man"])
151
 
 
 
76
        import bzr_man
 
77
        bzr_man.main()
152
78
 
153
79
########################
154
80
## Setup
155
81
########################
156
82
 
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]))
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]))
225
 
 
226
 
 
227
 
add_pyrex_extension('bzrlib._dirstate_helpers_c')
228
 
add_pyrex_extension('bzrlib._knit_load_data_c')
229
 
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
230
 
 
231
 
 
232
 
if unavailable_files:
233
 
    print 'C extension(s) not found:'
234
 
    print '   %s' % ('\n  '.join(unavailable_files),)
235
 
    print 'The python versions will be used instead.'
236
 
    print
237
 
 
238
 
 
239
 
if 'bdist_wininst' in sys.argv:
240
 
    def find_docs():
241
 
        docs = []
242
 
        for root, dirs, files in os.walk('doc'):
243
 
            r = []
244
 
            for f in files:
245
 
                if (os.path.splitext(f)[1] in ('.html','.css','.png','.pdf')
246
 
                    or f == 'quick-start-summary.svg'):
247
 
                    r.append(os.path.join(root, f))
248
 
            if r:
249
 
                relative = root[4:]
250
 
                if relative:
251
 
                    target = os.path.join('Doc\\Bazaar', relative)
252
 
                else:
253
 
                    target = 'Doc\\Bazaar'
254
 
                docs.append((target, r))
255
 
        return docs
256
 
 
257
 
    # python's distutils-based win32 installer
258
 
    ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
259
 
            'ext_modules': ext_modules,
260
 
            # help pages
261
 
            'data_files': find_docs(),
262
 
            # for building pyrex extensions
263
 
            'cmdclass': {'build_ext': build_ext_if_possible},
264
 
           }
265
 
 
266
 
    ARGS.update(META_INFO)
267
 
    ARGS.update(BZRLIB)
268
 
    ARGS.update(PKG_DATA)
269
 
    
270
 
    setup(**ARGS)
271
 
 
272
 
elif 'py2exe' in sys.argv:
273
 
    import glob
274
 
    # py2exe setup
275
 
    import py2exe
276
 
 
277
 
    # pick real bzr version
278
 
    import bzrlib
279
 
 
280
 
    version_number = []
281
 
    for i in bzrlib.version_info[:4]:
282
 
        try:
283
 
            i = int(i)
284
 
        except ValueError:
285
 
            i = 0
286
 
        version_number.append(str(i))
287
 
    version_str = '.'.join(version_number)
288
 
 
289
 
    target = py2exe.build_exe.Target(script = "bzr",
290
 
                                     dest_base = "bzr",
291
 
                                     icon_resources = [(0,'bzr.ico')],
292
 
                                     name = META_INFO['name'],
293
 
                                     version = version_str,
294
 
                                     description = META_INFO['description'],
295
 
                                     author = META_INFO['author'],
296
 
                                     copyright = "(c) Canonical Ltd, 2005-2007",
297
 
                                     company_name = "Canonical Ltd.",
298
 
                                     comments = META_INFO['description'],
299
 
                                    )
300
 
 
301
 
    packages = BZRLIB['packages']
302
 
    packages.remove('bzrlib')
303
 
    packages = [i for i in packages if not i.startswith('bzrlib.plugins')]
304
 
    includes = []
305
 
    for i in glob.glob('bzrlib\\*.py'):
306
 
        module = i[:-3].replace('\\', '.')
307
 
        if module.endswith('__init__'):
308
 
            module = module[:-len('__init__')]
309
 
        includes.append(module)
310
 
 
311
 
    additional_packages = set()
312
 
    if sys.version.startswith('2.4'):
313
 
        # adding elementtree package
314
 
        additional_packages.add('elementtree')
315
 
    elif sys.version.startswith('2.5'):
316
 
        additional_packages.add('xml.etree')
317
 
    else:
318
 
        import warnings
319
 
        warnings.warn('Unknown Python version.\n'
320
 
                      'Please check setup.py script for compatibility.')
321
 
    # email package from std python library use lazy import,
322
 
    # so we need to explicitly add all package
323
 
    additional_packages.add('email')
324
 
 
325
 
    # text files for help topis
326
 
    text_topics = glob.glob('bzrlib/help_topics/en/*.txt')
327
 
    topics_files = [('lib/help_topics/en', text_topics)]
328
 
 
329
 
    # built-in plugins
330
 
    plugins_files = []
331
 
    for root, dirs, files in os.walk('bzrlib/plugins'):
332
 
        x = []
333
 
        for i in files:
334
 
            if not i.endswith('.py'):
335
 
                continue
336
 
            if i == '__init__.py' and root == 'bzrlib/plugins':
337
 
                continue
338
 
            x.append(os.path.join(root, i))
339
 
        if x:
340
 
            target_dir = root[len('bzrlib/'):]  # install to 'plugins/...'
341
 
            plugins_files.append((target_dir, x))
342
 
    # find modules for built-in plugins
343
 
    import tools.package_mf
344
 
    mf = tools.package_mf.CustomModuleFinder()
345
 
    mf.run_package('bzrlib/plugins')
346
 
    packs, mods = mf.get_result()
347
 
    additional_packages.update(packs)
348
 
 
349
 
    options_list = {"py2exe": {"packages": packages + list(additional_packages),
350
 
                               "includes": includes + mods,
351
 
                               "excludes": ["Tkinter", "medusa", "tools"],
352
 
                               "dist_dir": "win32_bzr.exe",
353
 
                              },
354
 
                   }
355
 
    setup(options=options_list,
356
 
          console=[target,
357
 
                   'tools/win32/bzr_postinstall.py',
358
 
                  ],
359
 
          zipfile='lib/library.zip',
360
 
          data_files=topics_files + plugins_files,
361
 
          )
362
 
 
363
 
else:
364
 
    # ad-hoc for easy_install
365
 
    DATA_FILES = []
366
 
    if not 'bdist_egg' in sys.argv:
367
 
        # generate and install bzr.1 only with plain install, not easy_install one
368
 
        DATA_FILES = [('man/man1', ['bzr.1'])]
369
 
 
370
 
    # std setup
371
 
    ARGS = {'scripts': ['bzr'],
372
 
            'data_files': DATA_FILES,
373
 
            'cmdclass': command_classes,
374
 
            'ext_modules': ext_modules,
375
 
           }
376
 
 
377
 
    ARGS.update(META_INFO)
378
 
    ARGS.update(BZRLIB)
379
 
    ARGS.update(PKG_DATA)
380
 
 
381
 
    setup(**ARGS)
 
83
setup(name='bzr',
 
84
      version='0.7pre',
 
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.plugins',
 
92
                'bzrlib.selftest',
 
93
                'bzrlib.util',
 
94
                'bzrlib.transport',
 
95
                'bzrlib.store',
 
96
                'bzrlib.util.elementtree',
 
97
                'bzrlib.util.effbot.org',
 
98
                'bzrlib.util.configobj',
 
99
                ],
 
100
      scripts=['bzr'],
 
101
      cmdclass={'install_scripts': my_install_scripts, 'build': bzr_build},
 
102
      data_files=[('man/man1', ['bzr.1'])],
 
103
     )