當前位置: 首頁>>代碼示例>>Python>>正文


Python pkg_resources.safe_name方法代碼示例

本文整理匯總了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 
開發者ID:frostming,項目名稱:pdm,代碼行數:27,代碼來源:core.py

示例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 
開發者ID:frostming,項目名稱:pdm,代碼行數:26,代碼來源:conftest.py

示例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) 
開發者ID:chalasr,項目名稱:Flask-P2P,代碼行數:19,代碼來源:index.py

示例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)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:6,代碼來源:req_install.py

示例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) 
開發者ID:frostming,項目名稱:pdm,代碼行數:30,代碼來源:core.py

示例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() 
開發者ID:frostming,項目名稱:pdm,代碼行數:14,代碼來源:requirements.py

示例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 
開發者ID:frostming,項目名稱:pdm,代碼行數:4,代碼來源:requirements.py

示例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 
開發者ID:frostming,項目名稱:pdm,代碼行數:10,代碼來源:synchronizers.py

示例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) 
開發者ID:frostming,項目名稱:pdm,代碼行數:5,代碼來源:conftest.py

示例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)) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:7,代碼來源:req_install.py

示例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)) 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:7,代碼來源:req_install.py


注:本文中的pip._vendor.pkg_resources.safe_name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。