~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-10-24 12:49:17 UTC
  • mfrom: (2935.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20071024124917-xb75eckyxx6vkrlg
Makefile fixes - hooks.html generation & allow python to be overridden (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 './setup.py --help' for more options
7
7
"""
8
8
 
 
9
import os
 
10
import sys
 
11
 
9
12
import bzrlib
10
13
 
11
14
##
14
17
META_INFO = {'name':         'bzr',
15
18
             'version':      bzrlib.__version__,
16
19
             'author':       'Canonical Ltd',
17
 
             'author_email': 'bazaar-ng@lists.ubuntu.com',
 
20
             'author_email': 'bazaar@lists.canonical.com',
18
21
             'url':          'http://www.bazaar-vcs.org/',
19
22
             'description':  'Friendly distributed version control system',
20
23
             'license':      'GNU GPL v2',
21
24
            }
22
25
 
23
 
BZRLIB = {'packages': ['bzrlib',
24
 
                       'bzrlib.benchmarks',
25
 
                       'bzrlib.benchmarks.tree_creator',
26
 
                       'bzrlib.bundle',
27
 
                       'bzrlib.bundle.serializer',
28
 
                       'bzrlib.doc',
29
 
                       'bzrlib.doc.api',
30
 
                       'bzrlib.export',
31
 
                       'bzrlib.plugins',
32
 
                       'bzrlib.plugins.launchpad',
33
 
                       'bzrlib.store',
34
 
                       'bzrlib.store.revision',
35
 
                       'bzrlib.store.versioned',
36
 
                       'bzrlib.tests',
37
 
                       'bzrlib.tests.blackbox',
38
 
                       'bzrlib.tests.branch_implementations',
39
 
                       'bzrlib.tests.bzrdir_implementations',
40
 
                       'bzrlib.tests.interrepository_implementations',
41
 
                       'bzrlib.tests.intertree_implementations',
42
 
                       'bzrlib.tests.interversionedfile_implementations',
43
 
                       'bzrlib.tests.repository_implementations',
44
 
                       'bzrlib.tests.revisionstore_implementations',
45
 
                       'bzrlib.tests.tree_implementations',
46
 
                       'bzrlib.tests.workingtree_implementations',
47
 
                       'bzrlib.transport',
48
 
                       'bzrlib.transport.http',
49
 
                       'bzrlib.ui',
50
 
                       'bzrlib.util',
51
 
                       'bzrlib.util.configobj',
52
 
                       'bzrlib.util.effbot.org',
53
 
                       'bzrlib.util.elementtree',
54
 
                      ],
55
 
         }
 
26
# The list of packages is automatically generated later. Add other things
 
27
# that are part of BZRLIB here.
 
28
BZRLIB = {}
56
29
 
57
30
PKG_DATA = {# install files from selftest suite
58
31
            'package_data': {'bzrlib': ['doc/api/*.txt',
64
37
# Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
65
38
# including bzrlib.help
66
39
 
67
 
import os
68
 
import sys
69
 
 
70
40
try:
71
41
    version_info = sys.version_info
72
42
except AttributeError:
85
55
                os.execvp(python, [python] + sys.argv)
86
56
            except OSError:
87
57
                pass
88
 
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
89
 
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
 
58
    sys.stderr.write("bzr: error: cannot find a suitable python interpreter\n")
 
59
    sys.stderr.write("  (need %d.%d or later)" % NEED_VERS)
 
60
    sys.stderr.write('\n')
90
61
    sys.exit(1)
91
 
if hasattr(os, "unsetenv"):
 
62
if getattr(os, "unsetenv", None) is not None:
92
63
    os.unsetenv(REINVOKE)
93
64
 
94
65
 
 
66
def get_bzrlib_packages():
 
67
    """Recurse through the bzrlib directory, and extract the package names"""
 
68
 
 
69
    packages = []
 
70
    base_path = os.path.dirname(os.path.abspath(bzrlib.__file__))
 
71
    for root, dirs, files in os.walk(base_path):
 
72
        if '__init__.py' in files:
 
73
            assert root.startswith(base_path)
 
74
            # Get just the path below bzrlib
 
75
            package_path = root[len(base_path):]
 
76
            # Remove leading and trailing slashes
 
77
            package_path = package_path.strip('\\/')
 
78
            if not package_path:
 
79
                package_name = 'bzrlib'
 
80
            else:
 
81
                package_name = ('bzrlib.' +
 
82
                            package_path.replace('/', '.').replace('\\', '.'))
 
83
            packages.append(package_name)
 
84
    return sorted(packages)
 
85
 
 
86
 
 
87
BZRLIB['packages'] = get_bzrlib_packages()
 
88
 
 
89
 
95
90
from distutils.core import setup
96
91
from distutils.command.install_scripts import install_scripts
97
92
from distutils.command.build import build
105
100
    Create bzr.bat for win32.
106
101
    """
107
102
    def run(self):
108
 
        import os
109
 
        import sys
110
 
 
111
103
        install_scripts.run(self)   # standard action
112
104
 
113
105
        if sys.platform == "win32":
114
106
            try:
115
 
                scripts_dir = self.install_dir
 
107
                scripts_dir = os.path.join(sys.prefix, 'Scripts')
116
108
                script_path = self._quoted_path(os.path.join(scripts_dir,
117
109
                                                             "bzr"))
118
110
                python_exe = self._quoted_path(sys.executable)
119
111
                args = self._win_batch_args()
120
112
                batch_str = "@%s %s %s" % (python_exe, script_path, args)
121
 
                batch_path = script_path + ".bat"
 
113
                batch_path = os.path.join(self.install_dir, "bzr.bat")
122
114
                f = file(batch_path, "w")
123
115
                f.write(batch_str)
124
116
                f.close()
133
125
            return path
134
126
 
135
127
    def _win_batch_args(self):
136
 
        if os.name == 'nt':
 
128
        from bzrlib.win32utils import winver
 
129
        if winver == 'Windows NT':
137
130
            return '%*'
138
131
        else:
139
132
            return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
155
148
## Setup
156
149
########################
157
150
 
 
151
command_classes = {'install_scripts': my_install_scripts,
 
152
                   'build': bzr_build}
 
153
from distutils import log
 
154
from distutils.errors import CCompilerError, DistutilsPlatformError
 
155
from distutils.extension import Extension
 
156
ext_modules = []
 
157
try:
 
158
    from Pyrex.Distutils import build_ext
 
159
except ImportError:
 
160
    have_pyrex = False
 
161
    # try to build the extension from the prior generated source.
 
162
    print
 
163
    print ("The python package 'Pyrex' is not available."
 
164
           " If the .c files are available,")
 
165
    print ("they will be built,"
 
166
           " but modifying the .pyx files will not rebuild them.")
 
167
    print
 
168
    from distutils.command.build_ext import build_ext
 
169
else:
 
170
    have_pyrex = True
 
171
 
 
172
 
 
173
class build_ext_if_possible(build_ext):
 
174
 
 
175
    def run(self):
 
176
        try:
 
177
            build_ext.run(self)
 
178
        except DistutilsPlatformError, e:
 
179
            log.warn(str(e))
 
180
            log.warn('Extensions cannot be built, '
 
181
                     'will use the Python versions instead')
 
182
 
 
183
    def build_extension(self, ext):
 
184
        try:
 
185
            build_ext.build_extension(self, ext)
 
186
        except CCompilerError:
 
187
            log.warn('Building of "%s" extension failed, '
 
188
                     'will use the Python version instead' % (ext.name,))
 
189
 
 
190
 
 
191
# Override the build_ext if we have Pyrex available
 
192
command_classes['build_ext'] = build_ext_if_possible
 
193
unavailable_files = []
 
194
 
 
195
 
 
196
def add_pyrex_extension(module_name, **kwargs):
 
197
    """Add a pyrex module to build.
 
198
 
 
199
    This will use Pyrex to auto-generate the .c file if it is available.
 
200
    Otherwise it will fall back on the .c file. If the .c file is not
 
201
    available, it will warn, and not add anything.
 
202
 
 
203
    You can pass any extra options to Extension through kwargs. One example is
 
204
    'libraries = []'.
 
205
 
 
206
    :param module_name: The python path to the module. This will be used to
 
207
        determine the .pyx and .c files to use.
 
208
    """
 
209
    path = module_name.replace('.', '/')
 
210
    pyrex_name = path + '.pyx'
 
211
    c_name = path + '.c'
 
212
    if have_pyrex:
 
213
        ext_modules.append(Extension(module_name, [pyrex_name]))
 
214
    else:
 
215
        if not os.path.isfile(c_name):
 
216
            unavailable_files.append(c_name)
 
217
        else:
 
218
            ext_modules.append(Extension(module_name, [c_name]))
 
219
 
 
220
 
 
221
add_pyrex_extension('bzrlib._dirstate_helpers_c')
 
222
add_pyrex_extension('bzrlib._knit_load_data_c')
 
223
ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
 
224
 
 
225
 
 
226
if unavailable_files:
 
227
    print 'C extension(s) not found:'
 
228
    print '   %s' % ('\n  '.join(unavailable_files),)
 
229
    print 'The python versions will be used instead.'
 
230
    print
 
231
 
 
232
 
158
233
if 'bdist_wininst' in sys.argv:
159
 
    import glob
160
 
    # doc files
161
 
    docs = glob.glob('doc/*.htm') + ['doc/default.css']
 
234
    def find_docs():
 
235
        docs = []
 
236
        for root, dirs, files in os.walk('doc'):
 
237
            r = []
 
238
            for f in files:
 
239
                if os.path.splitext(f)[1] in ('.html', '.css'):
 
240
                    r.append(os.path.join(root, f))
 
241
            if r:
 
242
                relative = root[4:]
 
243
                if relative:
 
244
                    target = os.path.join('Doc\\Bazaar', relative)
 
245
                else:
 
246
                    target = 'Doc\\Bazaar'
 
247
                docs.append((target, r))
 
248
        return docs
 
249
 
162
250
    # python's distutils-based win32 installer
163
251
    ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
 
252
            'ext_modules': ext_modules,
164
253
            # help pages
165
 
            'data_files': [('Doc/Bazaar', docs)],
 
254
            'data_files': find_docs(),
 
255
            # for building pyrex extensions
 
256
            'cmdclass': {'build_ext': build_ext_if_possible},
166
257
           }
167
258
 
168
259
    ARGS.update(META_INFO)
194
285
                                     version = version_str,
195
286
                                     description = META_INFO['description'],
196
287
                                     author = META_INFO['author'],
197
 
                                     copyright = "(c) Canonical Ltd, 2005-2006",
 
288
                                     copyright = "(c) Canonical Ltd, 2005-2007",
198
289
                                     company_name = "Canonical Ltd.",
199
290
                                     comments = META_INFO['description'],
200
291
                                    )
 
292
 
 
293
    additional_packages =  []
 
294
    if sys.version.startswith('2.4'):
 
295
        # adding elementtree package
 
296
        additional_packages.append('elementtree')
 
297
    elif sys.version.startswith('2.5'):
 
298
        additional_packages.append('xml.etree')
 
299
    else:
 
300
        import warnings
 
301
        warnings.warn('Unknown Python version.\n'
 
302
                      'Please check setup.py script for compatibility.')
 
303
    # email package from std python library use lazy import,
 
304
    # so we need to explicitly add all package
 
305
    additional_packages.append('email')
 
306
 
201
307
    options_list = {"py2exe": {"packages": BZRLIB['packages'] +
202
 
                                           ['elementtree'],
203
 
                               "excludes": ["Tkinter", "medusa"],
 
308
                                           additional_packages,
 
309
                               "excludes": ["Tkinter", "medusa", "tools"],
204
310
                               "dist_dir": "win32_bzr.exe",
205
311
                              },
206
312
                   }
211
317
          zipfile='lib/library.zip')
212
318
 
213
319
else:
 
320
    # ad-hoc for easy_install
 
321
    DATA_FILES = []
 
322
    if not 'bdist_egg' in sys.argv:
 
323
        # generate and install bzr.1 only with plain install, not easy_install one
 
324
        DATA_FILES = [('man/man1', ['bzr.1'])]
 
325
 
214
326
    # std setup
215
327
    ARGS = {'scripts': ['bzr'],
216
 
            'data_files': [('man/man1', ['bzr.1'])],
217
 
            'cmdclass': {'build': bzr_build,
218
 
                         'install_scripts': my_install_scripts,
219
 
                        },
 
328
            'data_files': DATA_FILES,
 
329
            'cmdclass': command_classes,
 
330
            'ext_modules': ext_modules,
220
331
           }
221
 
    
 
332
 
222
333
    ARGS.update(META_INFO)
223
334
    ARGS.update(BZRLIB)
224
335
    ARGS.update(PKG_DATA)