~bzr-pqm/bzr/bzr.dev

45 by Martin Pool
- add setup.py and install instructions
1
#! /usr/bin/env python
2
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
3
"""Installation script for bzr.
4
Run it with
5
 './setup.py install', or
6
 './setup.py --help' for more options
7
"""
8
1861.2.21 by Alexander Belchenko
setup.py: automatically grab version info from bzrlib
9
import bzrlib
10
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
11
##
12
# META INFORMATION FOR SETUP
13
14
META_INFO = {'name':         'bzr',
1861.2.21 by Alexander Belchenko
setup.py: automatically grab version info from bzrlib
15
             'version':      bzrlib.__version__,
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
16
             'author':       'Canonical Ltd',
17
             'author_email': 'bazaar-ng@lists.ubuntu.com',
18
             'url':          'http://www.bazaar-vcs.org/',
19
             'description':  'Friendly distributed version control system',
20
             'license':      'GNU GPL v2',
21
            }
22
23
BZRLIB = {'packages': ['bzrlib',
24
                       'bzrlib.benchmarks',
1711.2.127 by John Arbash Meinel
(jelmer): fix setup.py
25
                       'bzrlib.benchmarks.tree_creator',
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
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',
1861.2.23 by Alexander Belchenko
merge bzr.dev.revno.1905
41
                       'bzrlib.tests.intertree_implementations',
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
42
                       'bzrlib.tests.interversionedfile_implementations',
43
                       'bzrlib.tests.repository_implementations',
44
                       'bzrlib.tests.revisionstore_implementations',
1861.2.23 by Alexander Belchenko
merge bzr.dev.revno.1905
45
                       'bzrlib.tests.tree_implementations',
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
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
         }
56
1911.1.1 by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data
57
PKG_DATA = {# install files from selftest suite
58
            'package_data': {'bzrlib': ['doc/api/*.txt',
59
                                        'tests/test_patches_data/*',
60
                                       ]},
61
           }
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
62
1861.2.12 by Alexander Belchenko
setup.py: get version info from bzrlib
63
######################################################################
1185.29.5 by Wouter van Heyst
Add reinvocation code to ensure setup.py is run by python2.4
64
# Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
65
# including bzrlib.help
66
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
67
import os
68
import sys
1185.29.5 by Wouter van Heyst
Add reinvocation code to ensure setup.py is run by python2.4
69
70
try:
71
    version_info = sys.version_info
72
except AttributeError:
73
    version_info = 1, 5 # 1.5 or older
74
75
REINVOKE = "__BZR_REINVOKE"
76
NEED_VERS = (2, 4)
77
KNOWN_PYTHONS = ('python2.4',)
78
79
if version_info < NEED_VERS:
80
    if not os.environ.has_key(REINVOKE):
81
        # mutating os.environ doesn't work in old Pythons
82
        os.putenv(REINVOKE, "1")
83
        for python in KNOWN_PYTHONS:
84
            try:
85
                os.execvp(python, [python] + sys.argv)
86
            except OSError:
87
                pass
88
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
89
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
90
    sys.exit(1)
91
if hasattr(os, "unsetenv"):
92
    os.unsetenv(REINVOKE)
93
94
45 by Martin Pool
- add setup.py and install instructions
95
from distutils.core import setup
1185.23.1 by Aaron Bentley
win32 setup fixes from Belchenko
96
from distutils.command.install_scripts import install_scripts
1185.29.3 by Wouter van Heyst
Create bzr.1 manpage from setup.py
97
from distutils.command.build import build
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
98
99
###############################
100
# Overridden distutils actions
101
###############################
102
1185.23.1 by Aaron Bentley
win32 setup fixes from Belchenko
103
class my_install_scripts(install_scripts):
104
    """ Customized install_scripts distutils action.
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
105
    Create bzr.bat for win32.
106
    """
107
    def run(self):
1185.23.1 by Aaron Bentley
win32 setup fixes from Belchenko
108
        import os
109
        import sys
110
111
        install_scripts.run(self)   # standard action
112
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
113
        if sys.platform == "win32":
1185.23.1 by Aaron Bentley
win32 setup fixes from Belchenko
114
            try:
115
                scripts_dir = self.install_dir
1861.2.10 by Alexander Belchenko
setup.py: improved bzr.bat creation
116
                script_path = self._quoted_path(os.path.join(scripts_dir,
117
                                                             "bzr"))
118
                python_exe = self._quoted_path(sys.executable)
119
                args = self._win_batch_args()
120
                batch_str = "@%s %s %s" % (python_exe, script_path, args)
1185.23.1 by Aaron Bentley
win32 setup fixes from Belchenko
121
                batch_path = script_path + ".bat"
122
                f = file(batch_path, "w")
123
                f.write(batch_str)
124
                f.close()
125
                print "Created:", batch_path
126
            except Exception, e:
127
                print "ERROR: Unable to create %s: %s" % (batch_path, e)
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
128
1861.2.10 by Alexander Belchenko
setup.py: improved bzr.bat creation
129
    def _quoted_path(self, path):
130
        if ' ' in path:
131
            return '"' + path + '"'
132
        else:
133
            return path
134
135
    def _win_batch_args(self):
136
        if os.name == 'nt':
137
            return '%*'
138
        else:
139
            return '%1 %2 %3 %4 %5 %6 %7 %8 %9'
140
#/class my_install_scripts
141
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
142
1185.29.3 by Wouter van Heyst
Create bzr.1 manpage from setup.py
143
class bzr_build(build):
144
    """Customized build distutils action.
145
    Generate bzr.1.
146
    """
147
    def run(self):
148
        build.run(self)
149
1551.3.11 by Aaron Bentley
Merge from Robert
150
        import generate_docs
151
        generate_docs.main(argv=["bzr", "man"])
1185.29.3 by Wouter van Heyst
Create bzr.1 manpage from setup.py
152
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
153
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
154
########################
155
## Setup
156
########################
157
1860.1.2 by Alexander Belchenko
setup.py:
158
if 'bdist_wininst' in sys.argv:
1860.1.3 by Alexander Belchenko
python-installer:
159
    import glob
160
    # doc files
161
    docs = glob.glob('doc/*.htm') + ['doc/default.css']
1860.1.2 by Alexander Belchenko
setup.py:
162
    # python's distutils-based win32 installer
163
    ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'],
1860.1.3 by Alexander Belchenko
python-installer:
164
            # help pages
1861.2.6 by Alexander Belchenko
branding: change Bazaar-NG to Bazaar
165
            'data_files': [('Doc/Bazaar', docs)],
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
166
           }
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
167
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
168
    ARGS.update(META_INFO)
169
    ARGS.update(BZRLIB)
1911.1.1 by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data
170
    ARGS.update(PKG_DATA)
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
171
    
172
    setup(**ARGS)
173
1860.1.2 by Alexander Belchenko
setup.py:
174
elif 'py2exe' in sys.argv:
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
175
    # py2exe setup
176
    import py2exe
177
178
    # pick real bzr version
179
    import bzrlib
180
181
    version_number = []
182
    for i in bzrlib.version_info[:4]:
183
        try:
184
            i = int(i)
185
        except ValueError:
186
            i = 0
187
        version_number.append(str(i))
188
    version_str = '.'.join(version_number)
189
190
    target = py2exe.build_exe.Target(script = "bzr",
191
                                     dest_base = "bzr",
192
                                     icon_resources = [(0,'bzr.ico')],
193
                                     name = META_INFO['name'],
194
                                     version = version_str,
195
                                     description = META_INFO['description'],
196
                                     author = META_INFO['author'],
197
                                     copyright = "(c) Canonical Ltd, 2005-2006",
198
                                     company_name = "Canonical Ltd.",
199
                                     comments = META_INFO['description'],
200
                                    )
201
    options_list = {"py2exe": {"packages": BZRLIB['packages'] +
202
                                           ['elementtree'],
1860.1.2 by Alexander Belchenko
setup.py:
203
                               "excludes": ["Tkinter", "medusa"],
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
204
                               "dist_dir": "win32_bzr.exe",
205
                              },
206
                   }
207
    setup(options=options_list,
208
          console=[target,
209
                   'tools/win32/bzr_postinstall.py',
210
                  ],
211
          zipfile='lib/library.zip')
1860.1.2 by Alexander Belchenko
setup.py:
212
213
else:
214
    # std setup
215
    ARGS = {'scripts': ['bzr'],
216
            'data_files': [('man/man1', ['bzr.1'])],
217
            'cmdclass': {'build': bzr_build,
218
                         'install_scripts': my_install_scripts,
219
                        },
220
           }
221
    
222
    ARGS.update(META_INFO)
223
    ARGS.update(BZRLIB)
1911.1.1 by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data
224
    ARGS.update(PKG_DATA)
1860.1.2 by Alexander Belchenko
setup.py:
225
226
    setup(**ARGS)