本文整理汇总了Python中pip._vendor.pkg_resources.safe_name方法的典型用法代码示例。如果您正苦于以下问题:Python pkg_resources.safe_name方法的具体用法?Python pkg_resources.safe_name怎么用?Python pkg_resources.safe_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip._vendor.pkg_resources
的用法示例。
在下文中一共展示了pkg_resources.safe_name方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_locked_candidates
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
def get_locked_candidates(
self, section: Optional[str] = None
) -> Dict[str, Candidate]:
if not self.lockfile_file.is_file():
return {}
section = section or "default"
result = {}
for package in [dict(p) for p in self.lockfile.get("package", [])]:
if section != "__all__" and section not in package["sections"]:
continue
version = package.get("version")
if version:
package["version"] = f"=={version}"
package_name = package.pop("name")
req = Requirement.from_req_dict(package_name, dict(package))
can = Candidate(req, self.environment, name=package_name, version=version)
can.marker = req.marker
can.hashes = {
item["file"]: item["hash"]
for item in self.lockfile["metadata"].get(f"{req.key} {version}", [])
} or None
result[req.identify()] = can
if section in ("default", "__all__") and self.meta.name and self.meta.version:
result[safe_name(self.meta.name).lower()] = self.make_self_candidate(True)
return result
示例2: working_set
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
def working_set(mocker, repository):
from pip._internal.utils import logging
rv = MockWorkingSet()
mocker.patch.object(Environment, "get_working_set", return_value=rv)
def install(candidate):
logging._log_state.indentation = 0
dependencies = repository.get_dependencies(candidate)[0]
key = safe_name(candidate.name).lower()
dist = Distribution(key, candidate.version)
dist.dependencies = dependencies
rv.add_distribution(dist)
def uninstall(dist):
del rv[dist.key]
installer = mocker.MagicMock()
installer.install.side_effect = install
installer.uninstall.side_effect = uninstall
mocker.patch("pdm.installers.synchronizers.Installer", return_value=installer)
mocker.patch("pdm.installers.Installer", return_value=installer)
yield rv
示例3: fmt_ctl_handle_mutual_exclude
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
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)
示例4: name
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
def name(self):
if self.req is None:
return None
return native_str(pkg_resources.safe_name(self.req.name))
示例5: add_dependencies
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
def add_dependencies(
self, requirements: Dict[str, Requirement], show_message: bool = True
) -> None:
for name, dep in requirements.items():
if dep.from_section == "default":
deps = self.tool_settings["dependencies"]
elif dep.from_section == "dev":
deps = self.tool_settings["dev-dependencies"]
else:
section = f"{dep.from_section}-dependencies"
if section not in self.tool_settings:
self.tool_settings[section] = tomlkit.table()
deps = self.tool_settings[section]
matched_name = next(
filter(
lambda k: strip_extras(name)[0] == safe_name(k).lower(), deps.keys()
),
None,
)
name_to_save = dep.name if matched_name is None else matched_name
_, req_dict = dep.as_req_dict()
if isinstance(req_dict, dict):
req = tomlkit.inline_table()
req.update(req_dict)
req_dict = req
deps[name_to_save] = req_dict
self.write_pyproject(show_message)
示例6: __init__
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
def __init__(self, **kwargs):
self._marker = None
self.from_section = "default"
self.marker_no_python = None # type: Optional[Marker]
self.requires_python = PySpecSet() # type: PySpecSet
for k, v in kwargs.items():
if k == "specifier":
v = get_specifier(v)
setattr(self, k, v)
if self.name and not self.project_name:
self.project_name = safe_name(self.name)
self.key = self.project_name.lower()
示例7: project_name
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
def project_name(self) -> Optional[str]:
return safe_name(self.name) if self.name else None
示例8: update_candidate
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
def update_candidate(self, key: str) -> Tuple[Distribution, Candidate]:
"""Update candidate"""
can = self.candidates[key]
dist = self.working_set[safe_name(can.name).lower()]
installer = self.get_installer()
installer.uninstall(dist)
installer.install(can)
return dist, can
示例9: add_dependencies
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
def add_dependencies(self, name, version, requirements):
pypi_data = self._pypi_data[safe_name(name)][version]
pypi_data.setdefault("dependencies", []).extend(requirements)
示例10: name
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
def name(self):
# type: () -> Optional[str]
if self.req is None:
return None
return native_str(pkg_resources.safe_name(self.req.name))
示例11: name
# 需要导入模块: from pip._vendor import pkg_resources [as 别名]
# 或者: from pip._vendor.pkg_resources import safe_name [as 别名]
def name(self):
# type: () -> Optional[str]
if self.req is None:
return None
return six.ensure_str(pkg_resources.safe_name(self.req.name))