我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pip._vendor.pkg_resources.safe_name()。
def fmt_ctl_handle_mutual_exclude(value, target, other): new = value.split(',') while ':all:' in new: other.clear() target.clear() target.add(':all:') del new[:new.index(':all:') + 1] if ':none:' not in new: # Without a none, we want to discard everything as :all: covers it return for name in new: if name == ':none:': target.clear() continue name = pkg_resources.safe_name(name).lower() other.discard(name) target.add(name)
def name(self): if self.req is None: return None return native_str(pkg_resources.safe_name(self.req.name))
def canonicalize_name(name): """Convert an arbitrary string to a canonical name used for comparison""" return pkg_resources.safe_name(name).lower()
def cached_wheel(cache_dir, link, format_control, package_name): if not cache_dir: return link if not link: return link if link.is_wheel: return link if not link.is_artifact: return link if not package_name: return link canonical_name = pkg_resources.safe_name(package_name).lower() formats = pip.index.fmt_ctl_formats(format_control, canonical_name) if "binary" not in formats: return link root = _cache_for_link(cache_dir, link) try: wheel_names = os.listdir(root) except OSError as e: if e.errno == errno.ENOENT: return link raise candidates = [] for wheel_name in wheel_names: try: wheel = Wheel(wheel_name) except InvalidWheelFilename: continue if not wheel.supported(): # Built for a different python/arch/etc continue candidates.append((wheel.support_index_min(), wheel_name)) if not candidates: return link candidates.sort() path = os.path.join(root, candidates[0][1]) return pip.index.Link(path_to_url(path), trusted=True)