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 |
install_scripts.run(self) # standard action |
103 |
||
1185.1.40
by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch. |
104 |
if sys.platform == "win32": |
1185.23.1
by Aaron Bentley
win32 setup fixes from Belchenko |
105 |
try: |
2662.1.1
by Alexander Belchenko
allow ``easy_install bzr`` runs without fatal errors. (Alexander Belchenko, #125521) |
106 |
scripts_dir = os.path.join(sys.prefix, 'Scripts') |
1861.2.10
by Alexander Belchenko
setup.py: improved bzr.bat creation |
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) |
|
2662.1.1
by Alexander Belchenko
allow ``easy_install bzr`` runs without fatal errors. (Alexander Belchenko, #125521) |
112 |
batch_path = os.path.join(self.install_dir, "bzr.bat") |
1185.23.1
by Aaron Bentley
win32 setup fixes from Belchenko |
113 |
f = file(batch_path, "w") |
114 |
f.write(batch_str) |
|
115 |
f.close() |
|
116 |
print "Created:", batch_path |
|
117 |
except Exception, e: |
|
118 |
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. |
119 |
|
1861.2.10
by Alexander Belchenko
setup.py: improved bzr.bat creation |
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): |
|
2245.4.4
by Alexander Belchenko
setup.py: fix plain 'python setup.py install' for win98 |
127 |
from bzrlib.win32utils import winver |
128 |
if winver == 'Windows NT': |
|
1861.2.10
by Alexander Belchenko
setup.py: improved bzr.bat creation |
129 |
return '%*' |
130 |
else: |
|
131 |
return '%1 %2 %3 %4 %5 %6 %7 %8 %9' |
|
132 |
#/class my_install_scripts
|
|
133 |
||
1185.1.40
by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch. |
134 |
|
1185.29.3
by Wouter van Heyst
Create bzr.1 manpage from setup.py |
135 |
class bzr_build(build): |
136 |
"""Customized build distutils action.
|
|
137 |
Generate bzr.1.
|
|
138 |
"""
|
|
139 |
def run(self): |
|
140 |
build.run(self) |
|
141 |
||
1551.3.11
by Aaron Bentley
Merge from Robert |
142 |
import generate_docs |
143 |
generate_docs.main(argv=["bzr", "man"]) |
|
1185.29.3
by Wouter van Heyst
Create bzr.1 manpage from setup.py |
144 |
|
1821.1.1
by Alexander Belchenko
win32 installer for bzr.dev.0.9 |
145 |
|
1185.1.40
by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch. |
146 |
########################
|
147 |
## Setup
|
|
148 |
########################
|
|
149 |
||
1739.1.1
by Robert Collins
First cut at adding pyrex facilities. |
150 |
command_classes = {'install_scripts': my_install_scripts, |
2571.3.1
by Alexander Belchenko
Building Python-based installer for bot Python 2.4 and 2.5 |
151 |
'build': bzr_build} |
2617.1.1
by John Arbash Meinel
Update setup.py to just skip extensions that are not available. |
152 |
from distutils.extension import Extension |
1739.1.1
by Robert Collins
First cut at adding pyrex facilities. |
153 |
ext_modules = [] |
154 |
try: |
|
155 |
from Pyrex.Distutils import build_ext |
|
156 |
except ImportError: |
|
2617.1.1
by John Arbash Meinel
Update setup.py to just skip extensions that are not available. |
157 |
have_pyrex = False |
1739.1.1
by Robert Collins
First cut at adding pyrex facilities. |
158 |
# try to build the extension from the prior generated source.
|
2617.1.1
by John Arbash Meinel
Update setup.py to just skip extensions that are not available. |
159 |
print
|
2617.1.2
by John Arbash Meinel
Try another form of comment |
160 |
print ("The python package 'Pyrex' is not available." |
161 |
" If the .c files are available,") |
|
162 |
print ("they will be built," |
|
163 |
" but modifying the .pyx files will not rebuild them.") |
|
2617.1.3
by John Arbash Meinel
Add another blank line to make it show up better |
164 |
print
|
1739.1.4
by Robert Collins
Fix building of C modules without pyrex installed. |
165 |
from distutils.command.build_ext import build_ext |
1739.1.1
by Robert Collins
First cut at adding pyrex facilities. |
166 |
else: |
2617.1.1
by John Arbash Meinel
Update setup.py to just skip extensions that are not available. |
167 |
have_pyrex = True |
168 |
# Override the build_ext if we have Pyrex available
|
|
1739.1.1
by Robert Collins
First cut at adding pyrex facilities. |
169 |
command_classes['build_ext'] = build_ext |
2617.1.1
by John Arbash Meinel
Update setup.py to just skip extensions that are not available. |
170 |
unavailable_files = [] |
171 |
||
2617.1.2
by John Arbash Meinel
Try another form of comment |
172 |
|
2617.1.1
by John Arbash Meinel
Update setup.py to just skip extensions that are not available. |
173 |
def add_pyrex_extension(module_name, **kwargs): |
174 |
"""Add a pyrex module to build.
|
|
175 |
||
176 |
This will use Pyrex to auto-generate the .c file if it is available.
|
|
177 |
Otherwise it will fall back on the .c file. If the .c file is not
|
|
178 |
available, it will warn, and not add anything.
|
|
179 |
||
180 |
You can pass any extra options to Extension through kwargs. One example is
|
|
181 |
'libraries = []'.
|
|
182 |
||
183 |
:param module_name: The python path to the module. This will be used to
|
|
184 |
determine the .pyx and .c files to use.
|
|
185 |
"""
|
|
186 |
path = module_name.replace('.', '/') |
|
187 |
pyrex_name = path + '.pyx' |
|
188 |
c_name = path + '.c' |
|
189 |
if have_pyrex: |
|
190 |
ext_modules.append(Extension(module_name, [pyrex_name])) |
|
191 |
else: |
|
192 |
if not os.path.isfile(c_name): |
|
193 |
unavailable_files.append(c_name) |
|
194 |
else: |
|
195 |
ext_modules.append(Extension(module_name, [c_name])) |
|
196 |
||
197 |
||
2474.1.71
by John Arbash Meinel
[merge] bzr.dev 2625 |
198 |
add_pyrex_extension('bzrlib._dirstate_helpers_c') |
2617.1.1
by John Arbash Meinel
Update setup.py to just skip extensions that are not available. |
199 |
add_pyrex_extension('bzrlib._knit_load_data_c') |
200 |
||
201 |
||
202 |
if unavailable_files: |
|
203 |
print 'C extension(s) not found:' |
|
204 |
print ' %s' % ('\n '.join(unavailable_files),) |
|
205 |
print 'The python versions will be used instead.' |
|
206 |
print
|
|
207 |
||
1739.1.1
by Robert Collins
First cut at adding pyrex facilities. |
208 |
|
1860.1.2
by Alexander Belchenko
setup.py: |
209 |
if 'bdist_wininst' in sys.argv: |
1860.1.3
by Alexander Belchenko
python-installer: |
210 |
import glob |
211 |
# doc files
|
|
2666.2.1
by Alexander Belchenko
change generated documentation extension from htm to html |
212 |
docs = glob.glob('doc/*.html') + ['doc/default.css'] |
213 |
dev_docs = glob.glob('doc/developers/*.html') |
|
1860.1.2
by Alexander Belchenko
setup.py: |
214 |
# python's distutils-based win32 installer
|
215 |
ARGS = {'scripts': ['bzr', 'tools/win32/bzr-win32-bdist-postinstall.py'], |
|
2571.3.1
by Alexander Belchenko
Building Python-based installer for bot Python 2.4 and 2.5 |
216 |
'ext_modules': ext_modules, |
1860.1.3
by Alexander Belchenko
python-installer: |
217 |
# help pages
|
2506.1.4
by Alexander Belchenko
pack developers docs to windows installers |
218 |
'data_files': [('Doc/Bazaar', docs), |
219 |
('Doc/Bazaar/developers', dev_docs), |
|
220 |
],
|
|
2571.3.1
by Alexander Belchenko
Building Python-based installer for bot Python 2.4 and 2.5 |
221 |
# for building pyrex extensions
|
222 |
'cmdclass': {'build_ext': build_ext}, |
|
1821.1.1
by Alexander Belchenko
win32 installer for bzr.dev.0.9 |
223 |
}
|
1821.1.2
by Alexander Belchenko
resurrected python's distutils based installer for win32 |
224 |
|
1821.1.1
by Alexander Belchenko
win32 installer for bzr.dev.0.9 |
225 |
ARGS.update(META_INFO) |
226 |
ARGS.update(BZRLIB) |
|
1911.1.1
by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data |
227 |
ARGS.update(PKG_DATA) |
1821.1.1
by Alexander Belchenko
win32 installer for bzr.dev.0.9 |
228 |
|
229 |
setup(**ARGS) |
|
230 |
||
1860.1.2
by Alexander Belchenko
setup.py: |
231 |
elif 'py2exe' in sys.argv: |
1821.1.1
by Alexander Belchenko
win32 installer for bzr.dev.0.9 |
232 |
# py2exe setup
|
233 |
import py2exe |
|
234 |
||
235 |
# pick real bzr version
|
|
236 |
import bzrlib |
|
237 |
||
238 |
version_number = [] |
|
239 |
for i in bzrlib.version_info[:4]: |
|
240 |
try: |
|
241 |
i = int(i) |
|
242 |
except ValueError: |
|
243 |
i = 0 |
|
244 |
version_number.append(str(i)) |
|
245 |
version_str = '.'.join(version_number) |
|
246 |
||
247 |
target = py2exe.build_exe.Target(script = "bzr", |
|
248 |
dest_base = "bzr", |
|
249 |
icon_resources = [(0,'bzr.ico')], |
|
250 |
name = META_INFO['name'], |
|
251 |
version = version_str, |
|
252 |
description = META_INFO['description'], |
|
253 |
author = META_INFO['author'], |
|
2232.1.1
by mbp at sourcefrog
update global copyright to 2007 |
254 |
copyright = "(c) Canonical Ltd, 2005-2007", |
1821.1.1
by Alexander Belchenko
win32 installer for bzr.dev.0.9 |
255 |
company_name = "Canonical Ltd.", |
256 |
comments = META_INFO['description'], |
|
257 |
)
|
|
2231.1.1
by Alexander Belchenko
Python 2.5 fixes for win32 installer |
258 |
|
259 |
additional_packages = [] |
|
260 |
if sys.version.startswith('2.4'): |
|
261 |
# adding elementtree package
|
|
262 |
additional_packages.append('elementtree') |
|
2234.5.2
by Wouter van Heyst
(Alexander Belchenko) add windows installer check for python2.5 |
263 |
elif sys.version.startswith('2.5'): |
264 |
additional_packages.append('xml.etree') |
|
265 |
else: |
|
266 |
import warnings |
|
267 |
warnings.warn('Unknown Python version.\n' |
|
268 |
'Please check setup.py script for compatibility.') |
|
2571.3.2
by Alexander Belchenko
Build pyrex/C extensions for bzr.exe |
269 |
# email package from std python library use lazy import,
|
270 |
# so we need to explicitly add all package
|
|
271 |
additional_packages.append('email') |
|
2231.1.1
by Alexander Belchenko
Python 2.5 fixes for win32 installer |
272 |
|
1821.1.1
by Alexander Belchenko
win32 installer for bzr.dev.0.9 |
273 |
options_list = {"py2exe": {"packages": BZRLIB['packages'] + |
2231.1.1
by Alexander Belchenko
Python 2.5 fixes for win32 installer |
274 |
additional_packages, |
2481.2.1
by Alexander Belchenko
don't bundle into standalone bzr.exe site.py (with their depends), and tools/doc_generate |
275 |
"excludes": ["Tkinter", "medusa", "tools"], |
1821.1.1
by Alexander Belchenko
win32 installer for bzr.dev.0.9 |
276 |
"dist_dir": "win32_bzr.exe", |
277 |
},
|
|
278 |
}
|
|
279 |
setup(options=options_list, |
|
280 |
console=[target, |
|
281 |
'tools/win32/bzr_postinstall.py', |
|
282 |
],
|
|
283 |
zipfile='lib/library.zip') |
|
1860.1.2
by Alexander Belchenko
setup.py: |
284 |
|
285 |
else: |
|
2662.1.1
by Alexander Belchenko
allow ``easy_install bzr`` runs without fatal errors. (Alexander Belchenko, #125521) |
286 |
# ad-hoc for easy_install
|
287 |
DATA_FILES = [] |
|
288 |
if not 'bdist_egg' in sys.argv: |
|
289 |
# generate and install bzr.1 only with plain install, not easy_install one
|
|
290 |
DATA_FILES = [('man/man1', ['bzr.1'])] |
|
291 |
||
1860.1.2
by Alexander Belchenko
setup.py: |
292 |
# std setup
|
293 |
ARGS = {'scripts': ['bzr'], |
|
2662.1.1
by Alexander Belchenko
allow ``easy_install bzr`` runs without fatal errors. (Alexander Belchenko, #125521) |
294 |
'data_files': DATA_FILES, |
1739.1.3
by Robert Collins
Merge bzr.dev. |
295 |
'cmdclass': command_classes, |
296 |
'ext_modules': ext_modules, |
|
1860.1.2
by Alexander Belchenko
setup.py: |
297 |
}
|
2666.2.1
by Alexander Belchenko
change generated documentation extension from htm to html |
298 |
|
1860.1.2
by Alexander Belchenko
setup.py: |
299 |
ARGS.update(META_INFO) |
300 |
ARGS.update(BZRLIB) |
|
1911.1.1
by Alexander Belchenko
setup.py: need to install data files for selftest from bzrlib/tests/test_patched_data |
301 |
ARGS.update(PKG_DATA) |
1860.1.2
by Alexander Belchenko
setup.py: |
302 |
|
303 |
setup(**ARGS) |