annotate paint/info.py @ 87:5a624b3c1007 default tip

py35
author Jeff Hammel <k0scist@gmail.com>
date Sun, 19 Feb 2017 17:50:00 -0800
parents 00c0f668f332
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 interfaces to get information from a package
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4
73
5b10f2c03cb9 more stubbing of something really stupid that is really hard
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
5
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
6 import imp
77
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
7 import pkginfo
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import os
58
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
9 import subprocess
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 import sys
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11
73
5b10f2c03cb9 more stubbing of something really stupid that is really hard
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
12 from distutils.dist import Distribution
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
13 from subprocess import check_call as call
73
5b10f2c03cb9 more stubbing of something really stupid that is really hard
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
14 from StringIO import StringIO
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
15
61
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
16 # TODO:
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
17 # Reconcile the difference between the keys (and values) between the different
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
18 # implementations. Pick a canon and stick with it.
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
19
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
20 # SetupOverridePackageInfo:
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
21 # {'entry_points': '\n', 'description': 'a dummy package', 'license': '', 'author': 'Jeff Hammel', 'install_requires': [], 'include_package_data': True, 'classifiers': [], 'url': 'http://example.com/', 'author_email': 'jhammel@mozilla.com', 'version': '0.1', 'zip_safe': False, 'packages': ['dummy'], 'long_description': 'dummy\n===========\n\na dummy package\n\n----\n\nJeff Hammel\n\nhttp://example.com/\n\n', 'name': 'dummy'}
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
22
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
23 # EggInfo:
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
24 # {'Name': 'dummy', 'License': 'UNKNOWN', 'Author': 'Jeff Hammel', 'Metadata-Version': '1.0', 'Home-page': 'http://example.com/', 'Summary': 'a dummy package', 'Platform': 'UNKNOWN', 'Version': '0.1', 'Author-email': 'jhammel@mozilla.com', 'Description': 'dummy'}
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
25
67
8f39ba642531 random stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
26 # see http://www.python.org/dev/peps/pep-0314/ :
8f39ba642531 random stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
27 # Metadata for Python Software Packages
61
1234bfb1f1f0 we really need to pick a canon
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
28
69
fea269259222 move comment to more appropriate place
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
29
fea269259222 move comment to more appropriate place
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
30 # TODO: consider using pkginfo
fea269259222 move comment to more appropriate place
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
31
73
5b10f2c03cb9 more stubbing of something really stupid that is really hard
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
32 def setup2metadata(**attrs):
71
da69d58f960d stub method of conversion, PackageSet, and some cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
33 """
da69d58f960d stub method of conversion, PackageSet, and some cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
34 convert setup arguments to standard python metadata:
da69d58f960d stub method of conversion, PackageSet, and some cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
35 http://www.python.org/dev/peps/pep-0314/
da69d58f960d stub method of conversion, PackageSet, and some cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
36 """
74
84890934af1f start tests for third-party sanity check; first up setup() -> metadata conversion
Jeff Hammel <jhammel@mozilla.com>
parents: 73
diff changeset
37 distribution = Distribution(attrs)
73
5b10f2c03cb9 more stubbing of something really stupid that is really hard
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
38 buffer = StringIO()
5b10f2c03cb9 more stubbing of something really stupid that is really hard
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
39 distribution.metadata.write_pkg_file(buffer)
77
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
40 pkginfo_dist = pkginfo.Distribution()
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
41 pkinfo_dist.parse(buffer.getvalue())
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
42 newattrs = dict((i, getattr(pkginfo_dist, i)) for i in pkginfo_dist)
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
43 header_dict = dict((attr_name, header_name)
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
44 for header_name, attr_name, multiple in pkginfo_dist._getHeaderAttrs())
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
45 info = dict((header_dict[key], value) for key, value in newattrs.items())
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
46
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
47 # XXX pkginfo says 'Home-Page' though the spec says Home-page
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
48 info.setdefault('Home-page', info['Home-Page'])
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
49
00c0f668f332 implementation of setup2metadata
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
50 return info
71
da69d58f960d stub method of conversion, PackageSet, and some cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
51
da69d58f960d stub method of conversion, PackageSet, and some cleanup
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
52
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53 class PackageInfo(object):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
54 """abstract base class of package info"""
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55 def __init__(self, path):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57 - path : path to setup.py or its directory
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59 if os.path.isdir(path):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
60 path = os.path.join(path, 'setup.py')
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61 assert os.path.exists(path), "'%s' not found" % path
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
62 self.setup_py = os.path.abspath(path)
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
63
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
64 def __call__(self):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
65 """returns dictionary of package info"""
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
66 raise NotImplementedError("abstract base class")
68
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
67 def dependencies(self):
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
68 raise NotImplementedError("abstract base class")
67
8f39ba642531 random stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
69
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
70 class SetupOverridePackageInfo(PackageInfo):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
71 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
72 gather setup.py information by overriding the function
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
73 """
67
8f39ba642531 random stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
74 # TODO: override distutils.core.setup as well
8f39ba642531 random stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
75 # http://docs.python.org/2/distutils/index.html#distutils-index
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
76
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
77 def __call__(self):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
78 setuptools = sys.modules.get('setuptools')
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
79 sys.modules['setuptools'] = sys.modules[__name__]
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
80 globals()['setup'] = self._setup
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
81 try:
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
82 module = imp.load_source('setup', self.setup_py)
56
042a1b2a3e8a start flushing out tests
Jeff Hammel <jhammel@mozilla.com>
parents: 54
diff changeset
83 finally:
042a1b2a3e8a start flushing out tests
Jeff Hammel <jhammel@mozilla.com>
parents: 54
diff changeset
84 sys.modules.pop('setuptools')
042a1b2a3e8a start flushing out tests
Jeff Hammel <jhammel@mozilla.com>
parents: 54
diff changeset
85 if setuptools:
042a1b2a3e8a start flushing out tests
Jeff Hammel <jhammel@mozilla.com>
parents: 54
diff changeset
86 sys.modules['setuptools'] = setuptools
042a1b2a3e8a start flushing out tests
Jeff Hammel <jhammel@mozilla.com>
parents: 54
diff changeset
87 globals().pop('setup')
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
88 return self.__dict__.pop('_info')
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
89
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
90 def _setup(self, **kwargs):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
91 self._info = kwargs
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
92
67
8f39ba642531 random stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
93
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
94 class EggInfo(PackageInfo):
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
95 """
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
96 use `python setup.py egg_info` to gather package information
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
97 """
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
98
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
99 def __call__(self):
58
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
100
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
101 info = self.read_pkg_info(self._pkg_info())
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
102 # TODO: install_requires
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
103 return info
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
104
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
105 @classmethod
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
106 def read_pkg_info(cls, path):
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
107 """reads PKG-INFO and returns a dict"""
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
108
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
109 # read the package information
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
110 info_dict = {}
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
111 for line in file(path).readlines():
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
112 if not line or line[0].isspace():
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
113 continue # XXX neglects description
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
114 assert ':' in line
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
115 key, value = [i.strip() for i in line.split(':', 1)]
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
116 info_dict[key] = value
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
117
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
118 # return the information
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
119 return info_dict
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
120
68
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
121 def dependencies(self):
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
122 """return the dependencies of the package"""
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
123
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
124 # TODO: should probably have a more detailed dict:
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
125 # {'mozinfo': {'version': '>= 0.2',
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
126 # 'url': 'http://something.com/'}}
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
127
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
128 # get the egg_info directory
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
129 egg_info = self._egg_info()
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
130
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
131 # read the dependencies
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
132 requires = os.path.join(egg_info, 'requires.txt')
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
133 if os.path.exists(requires):
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
134 dependencies = [i.strip() for i in file(requires).readlines() if i.strip()]
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
135 else:
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
136 dependencies = []
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
137 dependencies = dict([(i, None) for i in dependencies])
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
138
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
139 # read the dependency links
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
140 dependency_links = os.path.join(egg_info, 'dependency_links.txt')
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
141 if os.path.exists(dependency_links):
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
142 links = [i.strip() for i in file(dependency_links).readlines() if i.strip()]
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
143 for link in links:
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
144 # XXX pretty ghetto
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
145 assert '#egg=' in link
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
146 url, dep = link.split('#egg=', 1)
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
147 if dep in dependencies:
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
148 dependencies[dep] = link
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
149
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
150 return dependencies
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
151
d001017d5870 migrate this code to the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
152
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
153 def _egg_info(self):
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
154 """build the egg_info directory"""
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
155
60
aa3c90255db6 fix minor errors
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
156 # cached result
aa3c90255db6 fix minor errors
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
157 if getattr(self, '_egg_info_path', None):
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
158 return self._egg_info_path
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
159
58
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
160 directory = os.path.dirname(self.setup_py)
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
161
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
162 # setup the egg info
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
163 try:
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
164 call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=subprocess.PIPE)
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
165 except Exception:
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
166 print "Failure to generate egg_info: %s" % self.setup_py
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
167 raise
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
168
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
169 # get the .egg-info directory
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
170 egg_info = [i for i in os.listdir(directory)
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
171 if i.endswith('.egg-info')]
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
172 assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info)
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
173 egg_info = os.path.join(directory, egg_info[0])
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
174 assert os.path.isdir(egg_info), "%s is not a directory" % egg_info
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
175
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
176 # cache it
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
177 self._egg_info_path = egg_info
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
178 return self._egg_info_path
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
179
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
180 def _pkg_info(self):
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
181 """returns path to PKG-INFO file"""
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
182
59
acee5e882768 the egg-info tests fail. yay!
Jeff Hammel <jhammel@mozilla.com>
parents: 58
diff changeset
183 if getattr(self, '_pkg_info_path', None):
58
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
184 # return cached value
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
185 return self._pkg_info_path
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
186
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
187 try:
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
188 egg_info = self._egg_info()
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
189 except Exception, exception:
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
190 # try to get the package info from a file
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
191 path = os.path.dirname(self.setup_py)
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
192 pkg_info = os.path.join(path, 'PKG-INFO')
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
193 if os.path.exists(pkg_info):
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
194 self._pkg_info_path = pkg_info
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
195 return self._pkg_info_path
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
196 raise Exception("Cannot find or generate PKG-INFO")
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
197
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
198 pkg_info = os.path.join(egg_info, 'PKG-INFO')
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
199 assert os.path.exists(pkg_info)
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
200 self._pkg_info_path = pkg_info
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
201 return self._pkg_info_path
13767ee2ddf4 start adding an egg_info based information thingy
Jeff Hammel <jhammel@mozilla.com>
parents: 57
diff changeset
202