def _get_pkg_resource(filename, package, prefix):
"""Query pkg_resources for the location of the filename."""
requirement = pkg_resources.Requirement.parse(package)
target = os.path.join(prefix, filename)
try:
return pkg_resources.resource_filename(requirement, target)
except pkg_resources.DistributionNotFound:
# It may be that the working set is not in sync (e.g. if sys.path was
# manipulated). Try to reload it just in case.
pkg_resources.working_set = pkg_resources.WorkingSet()
try:
return pkg_resources.resource_filename(requirement, target)
except pkg_resources.DistributionNotFound:
return None
评论列表
文章目录