Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 249 lines (199 sloc) 8.382 kB
e9a479a @k0s [Bug 754338] put setup_development.py shebang back in;r=wlach
k0s authored
1 #!/usr/bin/env python
2
e816caa @wlach Update licensing headers for new MPL 2.0 boilerplate
wlach authored
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 # You can obtain one at http://mozilla.org/MPL/2.0/.
32e90d9 @k0s add a script to setup for development
k0s authored
6
7 """
8 Setup mozbase packages for development.
9
10 Packages may be specified as command line arguments.
11 If no arguments are given, install all packages.
12
13 See https://wiki.mozilla.org/Auto-tools/Projects/MozBase
14 """
15
16 import pkg_resources
17 import os
15fa18a @k0s Bug 815832 - remove README.md files and point setup.py long_descripti…
k0s authored
18 import subprocess
32e90d9 @k0s add a script to setup for development
k0s authored
19 import sys
20 from optparse import OptionParser
21 from subprocess import PIPE
22 try:
23 from subprocess import check_call as call
24 except ImportError:
25 from subprocess import call
26
27
28 # directory containing this file
29 here = os.path.dirname(os.path.abspath(__file__))
30
31 # all python packages
8e26c4e @wlach Bug 806117 - Add support for installing sphinx as an extra package;r=…
wlach authored
32 mozbase_packages = [i for i in os.listdir(here)
33 if os.path.exists(os.path.join(here, i, 'setup.py'))]
34 extra_packages = ["sphinx"]
32e90d9 @k0s add a script to setup for development
k0s authored
35
36 def cycle_check(order, dependencies):
37 """ensure no cyclic dependencies"""
38 order_dict = dict([(j, i) for i, j in enumerate(order)])
39 for package, deps in dependencies.items():
40 index = order_dict[package]
41 for d in deps:
42 assert index > order_dict[d], "Cyclic dependencies detected"
43
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
44 def info(directory):
45 "get the package setup.py information"
46
32e90d9 @k0s add a script to setup for development
k0s authored
47 assert os.path.exists(os.path.join(directory, 'setup.py'))
48
49 # setup the egg info
15fa18a @k0s Bug 815832 - remove README.md files and point setup.py long_descripti…
k0s authored
50 try:
51 call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=PIPE)
52 except subprocess.CalledProcessError:
53 print "Error running setup.py in %s" % directory
54 raise
32e90d9 @k0s add a script to setup for development
k0s authored
55
56 # get the .egg-info directory
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
57 egg_info = [entry for entry in os.listdir(directory)
58 if entry.endswith('.egg-info')]
32e90d9 @k0s add a script to setup for development
k0s authored
59 assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info)
60 egg_info = os.path.join(directory, egg_info[0])
61 assert os.path.isdir(egg_info), "%s is not a directory" % egg_info
62
63 # read the package information
64 pkg_info = os.path.join(egg_info, 'PKG-INFO')
65 info_dict = {}
66 for line in file(pkg_info).readlines():
67 if not line or line[0].isspace():
68 continue # XXX neglects description
69 assert ':' in line
70 key, value = [i.strip() for i in line.split(':', 1)]
71 info_dict[key] = value
72
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
73 return info_dict
74
75 def get_dependencies(directory):
76 "returns the package name and dependencies given a package directory"
77
78 # get the package metadata
79 info_dict = info(directory)
80
81 # get the .egg-info directory
82 egg_info = [entry for entry in os.listdir(directory)
83 if entry.endswith('.egg-info')][0]
84
85 # read the dependencies
86 requires = os.path.join(directory, egg_info, 'requires.txt')
87 if os.path.exists(requires):
88 dependencies = [line.strip()
89 for line in file(requires).readlines()
90 if line.strip()]
91 else:
92 dependencies = []
32e90d9 @k0s add a script to setup for development
k0s authored
93
94 # return the information
95 return info_dict['Name'], dependencies
96
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
97 def dependency_info(dep):
98 "return dictionary of dependency information from a dependency string"
99 retval = dict(Name=None, Type=None, Version=None)
32e90d9 @k0s add a script to setup for development
k0s authored
100 for joiner in ('==', '<=', '>='):
101 if joiner in dep:
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
102 retval['Type'] = joiner
103 name, version = [i.strip() for i in dep.split(joiner, 1)]
104 retval['Name'] = name
105 retval['Version'] = version
106 break
107 else:
aa50f7c @jonallengriffin Bug 801973 - Fix setup_development.py for versionless deps, r=jhammel
jonallengriffin authored
108 retval['Name'] = dep.strip()
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
109 return retval
32e90d9 @k0s add a script to setup for development
k0s authored
110
111 def unroll_dependencies(dependencies):
112 """
113 unroll a set of dependencies to a flat list
114
115 dependencies = {'packageA': set(['packageB', 'packageC', 'packageF']),
116 'packageB': set(['packageC', 'packageD', 'packageE', 'packageG']),
117 'packageC': set(['packageE']),
118 'packageE': set(['packageF', 'packageG']),
119 'packageF': set(['packageG']),
120 'packageX': set(['packageA', 'packageG'])}
121 """
122
123 order = []
124
125 # flatten all
126 packages = set(dependencies.keys())
127 for deps in dependencies.values():
128 packages.update(deps)
129
130 while len(order) != len(packages):
131
132 for package in packages.difference(order):
133 if set(dependencies.get(package, set())).issubset(order):
134 order.append(package)
135 break
136 else:
137 raise AssertionError("Cyclic dependencies detected")
138
139 cycle_check(order, dependencies) # sanity check
fef85bb @ahal Bug 703278 - Fix licenses and remove trailing whitespace (aka fix and
ahal authored
140
32e90d9 @k0s add a script to setup for development
k0s authored
141 return order
fef85bb @ahal Bug 703278 - Fix licenses and remove trailing whitespace (aka fix and
ahal authored
142
32e90d9 @k0s add a script to setup for development
k0s authored
143
144 def main(args=sys.argv[1:]):
145
146 # parse command line options
147 usage = '%prog [options] [package] [package] [...]'
148 parser = OptionParser(usage=usage, description=__doc__)
149 parser.add_option('-d', '--dependencies', dest='list_dependencies',
150 action='store_true', default=False,
151 help="list dependencies for the packages")
152 parser.add_option('--list', action='store_true', default=False,
153 help="list what will be installed")
154 options, packages = parser.parse_args(args)
155
8e26c4e @wlach Bug 806117 - Add support for installing sphinx as an extra package;r=…
wlach authored
156 install_extra_packages = False
157
32e90d9 @k0s add a script to setup for development
k0s authored
158 if not packages:
159 # install all packages
8e26c4e @wlach Bug 806117 - Add support for installing sphinx as an extra package;r=…
wlach authored
160 packages = sorted(mozbase_packages)
161 install_extra_packages = True
32e90d9 @k0s add a script to setup for development
k0s authored
162
163 # ensure specified packages are in the list
8e26c4e @wlach Bug 806117 - Add support for installing sphinx as an extra package;r=…
wlach authored
164 assert set(packages).issubset(mozbase_packages), "Packages should be in %s (You gave: %s)" % (mozbase_packages, packages)
32e90d9 @k0s add a script to setup for development
k0s authored
165
166 if options.list_dependencies:
167 # list the package dependencies
168 for package in packages:
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
169 print '%s: %s' % get_dependencies(os.path.join(here, package))
32e90d9 @k0s add a script to setup for development
k0s authored
170 parser.exit()
171
172 # gather dependencies
b7ed866 @k0s Bug 759836 - setup_development.py doesnt always actually setup for de…
k0s authored
173 # TODO: version conflict checking
32e90d9 @k0s add a script to setup for development
k0s authored
174 deps = {}
b7ed866 @k0s Bug 759836 - setup_development.py doesnt always actually setup for de…
k0s authored
175 alldeps = {}
2cd1d4e rework script following Bug 695866 - move ManifestDestiny to mozbase …
Jeff Hammel authored
176 mapping = {} # mapping from subdir name to package name
32e90d9 @k0s add a script to setup for development
k0s authored
177 # core dependencies
178 for package in packages:
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
179 key, value = get_dependencies(os.path.join(here, package))
180 deps[key] = [dependency_info(dep)['Name'] for dep in value]
2cd1d4e rework script following Bug 695866 - move ManifestDestiny to mozbase …
Jeff Hammel authored
181 mapping[package] = key
b7ed866 @k0s Bug 759836 - setup_development.py doesnt always actually setup for de…
k0s authored
182
183 # keep track of all dependencies for non-mozbase packages
184 for dep in value:
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
185 alldeps[dependency_info(dep)['Name']] = ''.join(dep.split())
b7ed866 @k0s Bug 759836 - setup_development.py doesnt always actually setup for de…
k0s authored
186
32e90d9 @k0s add a script to setup for development
k0s authored
187 # indirect dependencies
188 flag = True
189 while flag:
190 flag = False
191 for value in deps.values():
192 for dep in value:
8e26c4e @wlach Bug 806117 - Add support for installing sphinx as an extra package;r=…
wlach authored
193 if dep in mozbase_packages and dep not in deps:
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
194 key, value = get_dependencies(os.path.join(here, dep))
32e90d9 @k0s add a script to setup for development
k0s authored
195 deps[key] = [sanitize_dependency(dep) for dep in value]
b7ed866 @k0s Bug 759836 - setup_development.py doesnt always actually setup for de…
k0s authored
196
197 for dep in value:
198 alldeps[sanitize_dependency(dep)] = ''.join(dep.split())
2cd1d4e rework script following Bug 695866 - move ManifestDestiny to mozbase …
Jeff Hammel authored
199 mapping[package] = key
32e90d9 @k0s add a script to setup for development
k0s authored
200 flag = True
201 break
202 if flag:
203 break
204
2cd1d4e rework script following Bug 695866 - move ManifestDestiny to mozbase …
Jeff Hammel authored
205 # get the remaining names for the mapping
8e26c4e @wlach Bug 806117 - Add support for installing sphinx as an extra package;r=…
wlach authored
206 for package in mozbase_packages:
2cd1d4e rework script following Bug 695866 - move ManifestDestiny to mozbase …
Jeff Hammel authored
207 if package in mapping:
208 continue
82f13ef @k0s Bug 760722 - automatic version bumping for mozbase;r=whimboo
k0s authored
209 key, value = get_dependencies(os.path.join(here, package))
2cd1d4e rework script following Bug 695866 - move ManifestDestiny to mozbase …
Jeff Hammel authored
210 mapping[package] = key
211
32e90d9 @k0s add a script to setup for development
k0s authored
212 # unroll dependencies
213 unrolled = unroll_dependencies(deps)
214
2cd1d4e rework script following Bug 695866 - move ManifestDestiny to mozbase …
Jeff Hammel authored
215 # make a reverse mapping: package name -> subdirectory
216 reverse_mapping = dict([(j,i) for i, j in mapping.items()])
32e90d9 @k0s add a script to setup for development
k0s authored
217
2cd1d4e rework script following Bug 695866 - move ManifestDestiny to mozbase …
Jeff Hammel authored
218 # we only care about dependencies in mozbase
219 unrolled = [package for package in unrolled if package in reverse_mapping]
fef85bb @ahal Bug 703278 - Fix licenses and remove trailing whitespace (aka fix and
ahal authored
220
32e90d9 @k0s add a script to setup for development
k0s authored
221 if options.list:
222 # list what will be installed
223 for package in unrolled:
224 print package
225 parser.exit()
226
1f679a8 @k0s Bug 805440 - Mozrunner installed from pypi when running setup_develop…
k0s authored
227 # set up the packages for development
228 for package in unrolled:
229 call([sys.executable, 'setup.py', 'develop', '--no-deps'],
230 cwd=os.path.join(here, reverse_mapping[package]))
231
b7ed866 @k0s Bug 759836 - setup_development.py doesnt always actually setup for de…
k0s authored
232 # install non-mozbase dependencies
233 # these need to be installed separately and the --no-deps flag
234 # subsequently used due to a bug in setuptools; see
235 # https://bugzilla.mozilla.org/show_bug.cgi?id=759836
236 pypi_deps = dict([(i, j) for i,j in alldeps.items()
237 if i not in unrolled])
238 for package, version in pypi_deps.items():
239 # easy_install should be available since we rely on setuptools
240 call(['easy_install', version])
241
8e26c4e @wlach Bug 806117 - Add support for installing sphinx as an extra package;r=…
wlach authored
242 # install extra non-mozbase packages if desired
243 if install_extra_packages:
244 for package in extra_packages:
245 call(['easy_install', package])
32e90d9 @k0s add a script to setup for development
k0s authored
246
247 if __name__ == '__main__':
248 main()
Something went wrong with that request. Please try again.