~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
1930.3.1 by John Arbash Meinel
Change setup.py to auto-generate the list of packages to install
9
import os
10
import sys
11
1861.2.21 by Alexander Belchenko
setup.py: automatically grab version info from bzrlib
12
import bzrlib
13
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
14
##
15
# META INFORMATION FOR SETUP
16
17
META_INFO = {'name':         'bzr',
1861.2.21 by Alexander Belchenko
setup.py: automatically grab version info from bzrlib
18
             'version':      bzrlib.__version__,
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
19
             'author':       'Canonical Ltd',
2234.5.1 by Wouter van Heyst
Update the mailing list address.
20
             'author_email': 'bazaar@lists.canonical.com',
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
21
             'url':          'http://www.bazaar-vcs.org/',
22
             'description':  'Friendly distributed version control system',
23
             'license':      'GNU GPL v2',
24
            }
25
1930.3.3 by John Arbash Meinel
Fix a stupid error in code declaration order
26
# The list of packages is automatically generated later. Add other things
27
# that are part of BZRLIB here.
28
BZRLIB = {}
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
29
1911.1.1 by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data
30
PKG_DATA = {# install files from selftest suite
31
            'package_data': {'bzrlib': ['doc/api/*.txt',
32
                                        'tests/test_patches_data/*',
33
                                       ]},
34
           }
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
35
1861.2.12 by Alexander Belchenko
setup.py: get version info from bzrlib
36
######################################################################
1185.29.5 by Wouter van Heyst
Add reinvocation code to ensure setup.py is run by python2.4
37
# Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
38
# including bzrlib.help
39
40
try:
41
    version_info = sys.version_info
42
except AttributeError:
43
    version_info = 1, 5 # 1.5 or older
44
45
REINVOKE = "__BZR_REINVOKE"
46
NEED_VERS = (2, 4)
47
KNOWN_PYTHONS = ('python2.4',)
48
49
if version_info < NEED_VERS:
50
    if not os.environ.has_key(REINVOKE):
51
        # mutating os.environ doesn't work in old Pythons
52
        os.putenv(REINVOKE, "1")
53
        for python in KNOWN_PYTHONS:
54
            try:
55
                os.execvp(python, [python] + sys.argv)
56
            except OSError:
57
                pass
58
    print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter"
59
    print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
60
    sys.exit(1)
1963.2.6 by Robey Pointer
pychecker is on crack; go back to using 'is None'.
61
if getattr(os, "unsetenv", None) is not None:
1185.29.5 by Wouter van Heyst
Add reinvocation code to ensure setup.py is run by python2.4
62
    os.unsetenv(REINVOKE)
63
64
1930.3.1 by John Arbash Meinel
Change setup.py to auto-generate the list of packages to install
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
1930.3.3 by John Arbash Meinel
Fix a stupid error in code declaration order
86
BZRLIB['packages'] = get_bzrlib_packages()
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'],
1860.1.3 by Alexander Belchenko
python-installer:
158
            # help pages
1861.2.6 by Alexander Belchenko
branding: change Bazaar-NG to Bazaar
159
            'data_files': [('Doc/Bazaar', docs)],
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
160
           }
1821.1.2 by Alexander Belchenko
resurrected python's distutils based installer for win32
161
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
162
    ARGS.update(META_INFO)
163
    ARGS.update(BZRLIB)
1911.1.1 by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data
164
    ARGS.update(PKG_DATA)
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
165
    
166
    setup(**ARGS)
167
1860.1.2 by Alexander Belchenko
setup.py:
168
elif 'py2exe' in sys.argv:
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
169
    # py2exe setup
170
    import py2exe
171
172
    # pick real bzr version
173
    import bzrlib
174
175
    version_number = []
176
    for i in bzrlib.version_info[:4]:
177
        try:
178
            i = int(i)
179
        except ValueError:
180
            i = 0
181
        version_number.append(str(i))
182
    version_str = '.'.join(version_number)
183
184
    target = py2exe.build_exe.Target(script = "bzr",
185
                                     dest_base = "bzr",
186
                                     icon_resources = [(0,'bzr.ico')],
187
                                     name = META_INFO['name'],
188
                                     version = version_str,
189
                                     description = META_INFO['description'],
190
                                     author = META_INFO['author'],
2232.1.1 by mbp at sourcefrog
update global copyright to 2007
191
                                     copyright = "(c) Canonical Ltd, 2005-2007",
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
192
                                     company_name = "Canonical Ltd.",
193
                                     comments = META_INFO['description'],
194
                                    )
2231.1.1 by Alexander Belchenko
Python 2.5 fixes for win32 installer
195
196
    additional_packages =  []
197
    if sys.version.startswith('2.4'):
198
        # adding elementtree package
199
        additional_packages.append('elementtree')
2234.5.2 by Wouter van Heyst
(Alexander Belchenko) add windows installer check for python2.5
200
    elif sys.version.startswith('2.5'):
201
        additional_packages.append('xml.etree')
202
    else:
203
        import warnings
204
        warnings.warn('Unknown Python version.\n'
205
                      'Please check setup.py script for compatibility.')
2231.1.1 by Alexander Belchenko
Python 2.5 fixes for win32 installer
206
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
207
    options_list = {"py2exe": {"packages": BZRLIB['packages'] +
2231.1.1 by Alexander Belchenko
Python 2.5 fixes for win32 installer
208
                                           additional_packages,
1860.1.2 by Alexander Belchenko
setup.py:
209
                               "excludes": ["Tkinter", "medusa"],
1821.1.1 by Alexander Belchenko
win32 installer for bzr.dev.0.9
210
                               "dist_dir": "win32_bzr.exe",
211
                              },
212
                   }
213
    setup(options=options_list,
214
          console=[target,
215
                   'tools/win32/bzr_postinstall.py',
216
                  ],
217
          zipfile='lib/library.zip')
1860.1.2 by Alexander Belchenko
setup.py:
218
219
else:
220
    # std setup
221
    ARGS = {'scripts': ['bzr'],
222
            'data_files': [('man/man1', ['bzr.1'])],
223
            'cmdclass': {'build': bzr_build,
224
                         'install_scripts': my_install_scripts,
225
                        },
226
           }
227
    
228
    ARGS.update(META_INFO)
229
    ARGS.update(BZRLIB)
1911.1.1 by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data
230
    ARGS.update(PKG_DATA)
1860.1.2 by Alexander Belchenko
setup.py:
231
232
    setup(**ARGS)