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