comparison paint/package.py @ 14:6d27c2136163

a decent structure; need to reuse more
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 24 Feb 2012 15:50:31 -0800
parents 0dd1f8f83be2
children 8c8b7482772f
comparison
equal deleted inserted replaced
13:0dd1f8f83be2 14:6d27c2136163
82 82
83 if self._egg_info: 83 if self._egg_info:
84 # return cached copy 84 # return cached copy
85 return self._egg_info 85 return self._egg_info
86 86
87 directory = self.path
88
89 def info(self):
90 """return info dictionary for package"""
91 directory = self.path() 87 directory = self.path()
92 assert os.path.exists(os.path.join(path, 'setup.py')) 88 assert os.path.exists(os.path.join(path, 'setup.py'))
93 89
94 # setup the egg info 90 # setup the egg info
95 call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=PIPE) 91 call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=PIPE)
99 if i.endswith('.egg-info')] 95 if i.endswith('.egg-info')]
100 assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info) 96 assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info)
101 egg_info = os.path.join(directory, egg_info[0]) 97 egg_info = os.path.join(directory, egg_info[0])
102 assert os.path.isdir(egg_info), "%s is not a directory" % egg_info 98 assert os.path.isdir(egg_info), "%s is not a directory" % egg_info
103 99
104 # read the dependencies 100 # cache it
105 requires = os.path.join(egg_info, 'requires.txt') 101 self._egg_info = egg_info
106 if os.path.exists(requires): 102 return self._egg_info
107 dependencies = [i.strip() for i in file(requires).readlines() if i.strip()] 103
108 else: 104 def info(self):
109 dependencies = [] 105 """return info dictionary for package"""
106 # could use pkginfo
107
108 egg_info = self.egg_info()
110 109
111 # read the package information 110 # read the package information
112 pkg_info = os.path.join(egg_info, 'PKG-INFO') 111 pkg_info = os.path.join(egg_info, 'PKG-INFO')
113 info_dict = {} 112 info_dict = {}
114 for line in file(pkg_info).readlines(): 113 for line in file(pkg_info).readlines():
120 119
121 # return the information 120 # return the information
122 return info_dict['Name'], dependencies 121 return info_dict['Name'], dependencies
123 122
124 def dependencies(self): 123 def dependencies(self):
125 info = self.info() 124 """return the dependencies"""
125
126 egg_info = self.egg_info()
127
128 # read the dependencies
129 requires = os.path.join(egg_info, 'requires.txt')
130 if os.path.exists(requires):
131 dependencies = [i.strip() for i in file(requires).readlines() if i.strip()]
132 else:
133 dependencies = []
134