2
2
"""
3
3
import os
4
4
import sys
5
- from distutils import sysconfig
6
5
6
+ import importlib_metadata as metadata
7
7
from pytest import yield_fixture
8
- from pkg_resources import working_set
9
8
try :
10
9
from path import Path
11
10
except ImportError :
@@ -178,8 +177,12 @@ def install_package(self, pkg_name, installer='easy_install', build_egg=None):
178
177
False: Runs 'python setup.py develop'
179
178
None (default): installs the egg if available in dist/, otherwise develops it
180
179
"""
181
- installed = [p for p in working_set if p .project_name == pkg_name ]
182
- if not installed or installed [0 ].location .endswith ('.egg' ):
180
+ def location (dist ):
181
+ return dist .locate_file ('' )
182
+
183
+ installed = [
184
+ dist for dist in metadata .distributions () if dist .name == pkg_name ]
185
+ if not installed or location (installed [0 ]).endswith ('.egg' ):
183
186
if sys .platform == 'win32' :
184
187
# In virtualenv on windows "Scripts" folder is used instead of "bin".
185
188
installer = str (self .virtualenv / 'Scripts' / installer + '.exe' )
@@ -191,16 +194,17 @@ def install_package(self, pkg_name, installer='easy_install', build_egg=None):
191
194
# This is to circumvent #! line length limits :(
192
195
cmd = '%s %s %s' % (self .python , installer , pkg_name )
193
196
else :
194
- pkg = installed [0 ]
197
+ dist = installed [0 ]
195
198
d = {'python' : self .python ,
196
199
'easy_install' : self .easy_install ,
197
- 'src_dir' : pkg .location ,
198
- 'name' : pkg .project_name ,
199
- 'version' : pkg .version ,
200
- 'pyversion' : sysconfig .get_python_version (),
200
+ 'src_dir' : location (dist ),
201
+ 'name' : dist .name ,
202
+ 'version' : dist .version ,
203
+ 'pyversion' : '{sys.version_info[0]}.{sys.version_info[1]}'
204
+ .format (** globals ()),
201
205
}
202
206
203
- d ['egg_file' ] = Path (pkg . location ) / 'dist' / ('%(name)s-%(version)s-py%(pyversion)s.egg' % d )
207
+ d ['egg_file' ] = Path (location ( dist ) ) / 'dist' / ('%(name)s-%(version)s-py%(pyversion)s.egg' % d )
204
208
if build_egg and not d ['egg_file' ].isfile ():
205
209
self .run ('cd %(src_dir)s; %(python)s setup.py -q bdist_egg' % d , capture = True )
206
210
@@ -222,8 +226,8 @@ def installed_packages(self, package_type=None):
222
226
raise ValueError ('invalid package_type parameter (%s)' % str (package_type ))
223
227
224
228
res = {}
225
- code = "from pkg_resources import working_set \n " \
226
- "for i in working_set : print(i.project_name + ' ' + i.version + ' ' + i.location )"
229
+ code = "import importlib_metadata as metadata \n " \
230
+ "for i in metadata.distributions() : print(i.name + ' ' + i.version + ' ' + i.locate_file('') )"
227
231
lines = self .run ([self .python , "-c" , code ], capture = True ).split ('\n ' )
228
232
for line in [i .strip () for i in lines if i .strip ()]:
229
233
name , version , location = line .split ()
0 commit comments