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