~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-13 18:38:58 UTC
  • mfrom: (1863 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1869.
  • Revision ID: john@arbash-meinel.com-20060713183858-ebf4aa1f9ef8bb6e
[merge] bzr.dev 1863

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 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
 
######################################################################
 
3
# This is an installation script for bzr.  Run it with
 
4
# './setup.py install', or
 
5
# './setup.py --help' for more options
 
6
 
37
7
# Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
38
8
# including bzrlib.help
39
9
 
 
10
import os, sys
 
11
 
40
12
try:
41
13
    version_info = sys.version_info
42
14
except AttributeError:
58
30
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
59
31
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
60
32
    sys.exit(1)
61
 
if getattr(os, "unsetenv", None) is not None:
 
33
if hasattr(os, "unsetenv"):
62
34
    os.unsetenv(REINVOKE)
63
35
 
64
36
 
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
 
 
89
37
from distutils.core import setup
90
38
from distutils.command.install_scripts import install_scripts
91
39
from distutils.command.build import build
99
47
    Create bzr.bat for win32.
100
48
    """
101
49
    def run(self):
 
50
        import os
 
51
        import sys
 
52
 
102
53
        install_scripts.run(self)   # standard action
103
54
 
104
55
        if sys.platform == "win32":
105
56
            try:
106
57
                scripts_dir = self.install_dir
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)
 
58
                script_path = os.path.join(scripts_dir, "bzr")
 
59
                batch_str = "@%s %s %%*\n" % (sys.executable, script_path)
112
60
                batch_path = script_path + ".bat"
113
61
                f = file(batch_path, "w")
114
62
                f.write(batch_str)
117
65
            except Exception, e:
118
66
                print "ERROR: Unable to create %s: %s" % (batch_path, e)
119
67
 
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
 
 
134
68
 
135
69
class bzr_build(build):
136
70
    """Customized build distutils action.
142
76
        import generate_docs
143
77
        generate_docs.main(argv=["bzr", "man"])
144
78
 
145
 
 
146
79
########################
147
80
## Setup
148
81
########################
149
82
 
150
 
command_classes = {'install_scripts': my_install_scripts,
151
 
                   'build': bzr_build}
152
 
ext_modules = []
153
 
try:
154
 
    from Pyrex.Distutils import build_ext
155
 
except ImportError:
156
 
    # 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.")
159
 
    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
 
    ext_modules.append(
164
 
        Extension("bzrlib._knit_load_data_c", ["bzrlib/_knit_load_data_c.c"]))
165
 
else:
166
 
    from distutils.extension import Extension
167
 
    #ext_modules.append(
168
 
    #    Extension("bzrlib.modulename", ["bzrlib/foo.pyx"], libraries = []))
169
 
    ext_modules.append(
170
 
        Extension("bzrlib._knit_load_data_c", ["bzrlib/_knit_load_data_c.pyx"]))
171
 
command_classes['build_ext'] = build_ext
172
 
 
173
 
if 'bdist_wininst' in sys.argv:
174
 
    import glob
175
 
    # doc files
176
 
    docs = glob.glob('doc/*.htm') + ['doc/default.css']
177
 
    dev_docs = glob.glob('doc/developers/*.htm')
178
 
    # python's distutils-based win32 installer
179
 
    ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
180
 
            'ext_modules': ext_modules,
181
 
            # help pages
182
 
            'data_files': [('Doc/Bazaar', docs),
183
 
                           ('Doc/Bazaar/developers', dev_docs),
184
 
                          ],
185
 
            # for building pyrex extensions
186
 
            'cmdclass': {'build_ext': build_ext},
187
 
           }
188
 
 
189
 
    ARGS.update(META_INFO)
190
 
    ARGS.update(BZRLIB)
191
 
    ARGS.update(PKG_DATA)
192
 
    
193
 
    setup(**ARGS)
194
 
 
195
 
elif 'py2exe' in sys.argv:
196
 
    # py2exe setup
197
 
    import py2exe
198
 
 
199
 
    # pick real bzr version
200
 
    import bzrlib
201
 
 
202
 
    version_number = []
203
 
    for i in bzrlib.version_info[:4]:
204
 
        try:
205
 
            i = int(i)
206
 
        except ValueError:
207
 
            i = 0
208
 
        version_number.append(str(i))
209
 
    version_str = '.'.join(version_number)
210
 
 
211
 
    target = py2exe.build_exe.Target(script = "bzr",
212
 
                                     dest_base = "bzr",
213
 
                                     icon_resources = [(0,'bzr.ico')],
214
 
                                     name = META_INFO['name'],
215
 
                                     version = version_str,
216
 
                                     description = META_INFO['description'],
217
 
                                     author = META_INFO['author'],
218
 
                                     copyright = "(c) Canonical Ltd, 2005-2007",
219
 
                                     company_name = "Canonical Ltd.",
220
 
                                     comments = META_INFO['description'],
221
 
                                    )
222
 
 
223
 
    additional_packages =  []
224
 
    if sys.version.startswith('2.4'):
225
 
        # adding elementtree package
226
 
        additional_packages.append('elementtree')
227
 
    elif sys.version.startswith('2.5'):
228
 
        additional_packages.append('xml.etree')
229
 
    else:
230
 
        import warnings
231
 
        warnings.warn('Unknown Python version.\n'
232
 
                      'Please check setup.py script for compatibility.')
233
 
    # email package from std python library use lazy import,
234
 
    # so we need to explicitly add all package
235
 
    additional_packages.append('email')
236
 
 
237
 
    options_list = {"py2exe": {"packages": BZRLIB['packages'] +
238
 
                                           additional_packages,
239
 
                               "excludes": ["Tkinter", "medusa", "tools"],
240
 
                               "dist_dir": "win32_bzr.exe",
241
 
                              },
242
 
                   }
243
 
    setup(options=options_list,
244
 
          console=[target,
245
 
                   'tools/win32/bzr_postinstall.py',
246
 
                  ],
247
 
          zipfile='lib/library.zip')
248
 
 
249
 
else:
250
 
    # std setup
251
 
    ARGS = {'scripts': ['bzr'],
252
 
            'data_files': [('man/man1', ['bzr.1'])],
253
 
            'cmdclass': command_classes,
254
 
            'ext_modules': ext_modules,
255
 
           }
256
 
    
257
 
    ARGS.update(META_INFO)
258
 
    ARGS.update(BZRLIB)
259
 
    ARGS.update(PKG_DATA)
260
 
 
261
 
    setup(**ARGS)
 
83
setup(name='bzr',
 
84
      version='0.9pre',
 
85
      author='Canonical Ltd',
 
86
      author_email='bazaar-ng@lists.ubuntu.com',
 
87
      url='http://bazaar-vcs.org/',
 
88
      description='Friendly distributed version control system',
 
89
      license='GNU GPL v2',
 
90
      packages=['bzrlib',
 
91
                'bzrlib.benchmarks',
 
92
                'bzrlib.doc',
 
93
                'bzrlib.doc.api',
 
94
                'bzrlib.export',
 
95
                'bzrlib.plugins',
 
96
                'bzrlib.plugins.launchpad',
 
97
                'bzrlib.store',
 
98
                'bzrlib.store.revision',
 
99
                'bzrlib.store.versioned',
 
100
                'bzrlib.tests',
 
101
                'bzrlib.tests.blackbox',
 
102
                'bzrlib.tests.branch_implementations',
 
103
                'bzrlib.tests.bzrdir_implementations',
 
104
                'bzrlib.tests.interrepository_implementations',
 
105
                'bzrlib.tests.interversionedfile_implementations',
 
106
                'bzrlib.tests.repository_implementations',
 
107
                'bzrlib.tests.revisionstore_implementations',
 
108
                'bzrlib.tests.workingtree_implementations',
 
109
                'bzrlib.transport',
 
110
                'bzrlib.transport.http',
 
111
                'bzrlib.ui',
 
112
                'bzrlib.util',
 
113
                'bzrlib.util.elementtree',
 
114
                'bzrlib.util.effbot.org',
 
115
                'bzrlib.util.configobj',
 
116
                'bzrlib.bundle',
 
117
                'bzrlib.bundle.serializer'
 
118
                ],
 
119
      scripts=['bzr'],
 
120
      cmdclass={'install_scripts': my_install_scripts, 'build': bzr_build},
 
121
      data_files=[('man/man1', ['bzr.1'])],
 
122
    #   todo: install the txt files from bzrlib.doc.api.
 
123
     )