当前位置: 首页>>代码示例>>Python>>正文


Python utils.canonicalize_name方法代码示例

本文整理汇总了Python中packaging.utils.canonicalize_name方法的典型用法代码示例。如果您正苦于以下问题:Python utils.canonicalize_name方法的具体用法?Python utils.canonicalize_name怎么用?Python utils.canonicalize_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在packaging.utils的用法示例。


在下文中一共展示了utils.canonicalize_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: version_info

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def version_info(parser):
    versions = OrderedDict()
    to_visit = {"tox"}
    while to_visit:
        current = to_visit.pop()
        current_dist = importlib_metadata.distribution(current)
        current_name = canonicalize_name(current_dist.metadata["name"])
        versions[current_name] = current_dist.version
        if current_dist.requires is not None:
            for require in current_dist.requires:
                pkg = Requirement(require)
                pkg_name = canonicalize_name(pkg.name)
                if (
                    pkg.marker is None or pkg.marker.evaluate({"extra": ""})
                ) and pkg_name not in versions:
                    to_visit.add(pkg_name)
    set_section(parser, "tox:versions", versions) 
开发者ID:tox-dev,项目名称:tox,代码行数:19,代码来源:show_config.py

示例2: __call__

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def __call__(self) -> bool:
        venvs = VEnvs(path=self.config['venv'])
        for name in self.args.name:
            name = canonicalize_name(name)
            venv = venvs.get_by_name(name)
            if not venv.exists():
                self.logger.error('jail does not exist', extra=dict(package=name))
                return False

            # remove symlinks on entrypoints
            self.logger.info('remove executables...')
            for entrypoint in venv.bin_path.iterdir():
                global_entrypoint = Path(self.config['bin']) / entrypoint.name
                if not global_entrypoint.exists():
                    continue
                if not global_entrypoint.resolve().samefile(entrypoint):
                    continue
                global_entrypoint.unlink()
                self.logger.info('removed', extra=dict(script=entrypoint.name))

            # remove venv
            shutil.rmtree(venv.path)
            self.logger.info('jail removed', extra=dict(package=name))

        return True 
开发者ID:dephell,项目名称:dephell,代码行数:27,代码来源:jail_remove.py

示例3: get_name_variants

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def get_name_variants(pkg):
    # type: (STRING_TYPE) -> Set[STRING_TYPE]
    """
    Given a packager name, get the variants of its name for both the canonicalized
    and "safe" forms.

    :param AnyStr pkg: The package to lookup
    :returns: A list of names.
    :rtype: Set
    """

    if not isinstance(pkg, six.string_types):
        raise TypeError("must provide a string to derive package names")
    from pkg_resources import safe_name
    from packaging.utils import canonicalize_name

    pkg = pkg.lower()
    names = {safe_name(pkg), canonicalize_name(pkg), pkg.replace("-", "_")}
    return names 
开发者ID:pypa,项目名称:pipenv,代码行数:21,代码来源:utils.py

示例4: requirement

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def requirement(self):
        # type: () -> Optional[RequirementType]
        if self._requirement is None:
            self.parse_requirement()
            if self._requirement is None and self._name is not None:
                self._requirement = init_requirement(canonicalize_name(self.name))
                if self.is_file or self.is_remote_url and self._requirement is not None:
                    self._requirement.url = self.url
        if (
            self._requirement
            and self._requirement.specifier
            and not self._requirement.specs
        ):
            specs = self.get_requirement_specs(self._requirement.specifier)
            self._requirement.specs = specs
        return self._requirement 
开发者ID:pypa,项目名称:pipenv,代码行数:18,代码来源:requirements.py

示例5: adding_requirement

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def adding_requirement(self, req, parent):
        print(f"adding_requirement(self, {req!r}, {parent!r})")
        self._track_evaluating(parent)

        self._add_candidate(parent)
        self._add_requirement(req)

        self._ensure_edge(parent, to=req)

        self._active_requirements[canonicalize_name(req.name)][req] += 1
        self._dependencies[parent].add(req)

        if parent is None:
            return

        # We're seeing the parent candidate (which is being "evaluated"), so
        # color all "active" requirements pointing to the it.
        # TODO: How does this interact with revisited candidates?
        for parent_req in self._active_requirements[
            canonicalize_name(parent.name)
        ]:
            self._ensure_edge(parent_req, to=parent, color="#80CC80") 
开发者ID:sarugaku,项目名称:resolvelib,代码行数:24,代码来源:reporter.py

示例6: backtracking

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def backtracking(self, candidate, internal=False):
        print(f"backtracking(self, {candidate!r}, internal={internal})")
        self._track_evaluating(candidate)
        self._evaluating = None

        # Update the graph!
        node_name, node = self._get_node_for(candidate)
        node.attr.update(shape="signature", color="red")

        for edge in self.graph.out_edges_iter([node_name]):
            edge.attr.update(style="dotted", arrowhead="vee", color="#FF9999")
            _, to = edge
            to.attr.update(color="black")

        for edge in self.graph.in_edges_iter([node_name]):
            edge.attr.update(style="dotted", color="#808080")

        # Trim "active" requirements to remove anything not relevant now.
        for requirement in self._dependencies[candidate]:
            active = self._active_requirements[
                canonicalize_name(requirement.name)
            ]
            active[requirement] -= 1
            if not active[requirement]:
                del active[requirement] 
开发者ID:sarugaku,项目名称:resolvelib,代码行数:27,代码来源:reporter.py

示例7: pinning

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def pinning(self, candidate):
        print(f"pinning(self, {candidate!r})")
        assert self._evaluating == candidate or self._evaluating is None
        self._evaluating = None

        self._add_candidate(candidate)

        # Update the graph!
        node_name, node = self._get_node_for(candidate)
        node.attr.update(color="#80CC80")

        # Requirement -> Candidate edges, from this candidate.
        for req in self._active_requirements[
            canonicalize_name(candidate.name)
        ]:
            self._ensure_edge(
                req, to=candidate, arrowhead="vee", color="#80CC80"
            )

        # Candidate -> Requirement edges, from this candidate.
        for edge in self.graph.out_edges_iter([node_name]):
            edge.attr.update(style="solid", arrowhead="vee", color="#80CC80")
            _, to = edge
            to.attr.update(color="#80C080") 
开发者ID:sarugaku,项目名称:resolvelib,代码行数:26,代码来源:reporter.py

示例8: find_matches

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def find_matches(self, requirements):
        assert requirements, "resolver promises at least one requirement"
        assert not any(
            r.extras for r in requirements[1:]
        ), "extras not supported in this example"

        name = canonicalize_name(requirements[0].name)

        # Need to pass the extras to the search, so they
        # are added to the candidate at creation - we
        # treat candidates as immutable once created.
        candidates = []
        for c in get_project_from_pypi(name, set()):
            version = c.version
            if all(version in r.specifier for r in requirements):
                candidates.append(c)
        return sorted(candidates, key=attrgetter("version"), reverse=True) 
开发者ID:sarugaku,项目名称:resolvelib,代码行数:19,代码来源:pypi_wheel_provider.py

示例9: lock

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def lock(self, dev=True):
        if self._poet.is_lock():
            return

        self._command.line('')
        self._command.line('<info>Locking dependencies to <comment>poetry.lock</></>')
        self._command.line('')

        deps = self._poet.pip_dependencies

        if dev:
            deps += self._poet.pip_dev_dependencies

        packages = self.resolve(deps)
        features = {}
        for name, featured_packages in self._poet.features.items():
            name = canonicalize_name(name)
            features[name] = [canonicalize_name(p) for p in featured_packages]

        self._write_lock(packages, features) 
开发者ID:sdispater,项目名称:poet,代码行数:22,代码来源:installer.py

示例10: delete_path

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def delete_path(blob_path: Path, dry_run: bool = False) -> int:
    storage_backend = next(iter(storage_backend_plugins()))
    if dry_run:
        logger.info(f" rm {blob_path}")
    if not storage_backend.exists(blob_path):
        logger.debug(f"{blob_path} does not exist. Skipping")
        return 0
    try:
        storage_backend.delete(blob_path, dry_run=dry_run)
    except FileNotFoundError:
        # Due to using threads in executors we sometimes have a
        # race condition if canonicalize_name == passed in name
        pass
    except OSError:
        logger.exception(f"Unable to delete {blob_path}")
        return 1
    return 0 
开发者ID:pypa,项目名称:bandersnatch,代码行数:19,代码来源:delete.py

示例11: find_required_modules

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def find_required_modules(options, requirements_filename: str):
    explicit = set()
    for requirement in parse_requirements(requirements_filename,
                                          session=PipSession()):
        try:
            requirement_name = requirement.name
        # The type of "requirement" changed between pip versions.
        # We exclude the "except" from coverage so that on any pip version we
        # can report 100% coverage.
        except AttributeError:  # pragma: no cover
            from pip._internal.req.constructors import install_req_from_line
            requirement_name = install_req_from_line(
                requirement.requirement,
            ).name

        if options.ignore_reqs(requirement):
            log.debug('ignoring requirement: %s', requirement_name)
        else:
            log.debug('found requirement: %s', requirement_name)
            explicit.add(canonicalize_name(requirement_name))
    return explicit 
开发者ID:r1chardj0n3s,项目名称:pip-check-reqs,代码行数:23,代码来源:common.py

示例12: _fetch_index_package_info

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def _fetch_index_package_info(self, package_name, current_version):
        """
        :type package_name: str
        :type current_version: version.Version
        """

        try:
            package_canonical_name = package_name
            if self.PYPI_API_TYPE == 'simple_html':
                package_canonical_name = canonicalize_name(package_name)
            response = requests.get(self.PYPI_API_URL.format(package=package_canonical_name), timeout=15)
        except HTTPError as e:  # pragma: nocover
            return False, e.message

        if not response.ok:  # pragma: nocover
            return False, 'API error: {}'.format(response.reason)

        if self.PYPI_API_TYPE == 'pypi_json':
            return self._parse_pypi_json_package_info(package_name, current_version, response)
        elif self.PYPI_API_TYPE == 'simple_html':
            return self._parse_simple_html_package_info(package_name, current_version, response)
        else:  # pragma: nocover
            raise NotImplementedError('This type of PYPI_API_TYPE type is not supported') 
开发者ID:simion,项目名称:pip-upgrader,代码行数:25,代码来源:packages_status_detector.py

示例13: _is_same_dep

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def _is_same_dep(cls, dep1, dep2):
        """Definitions are the same if they refer to the same package, even if versions differ."""
        dep1_name = canonicalize_name(requirements.Requirement(dep1).name)
        try:
            dep2_name = canonicalize_name(requirements.Requirement(dep2).name)
        except requirements.InvalidRequirement:
            # we couldn't parse a version, probably a URL
            return False
        return dep1_name == dep2_name 
开发者ID:tox-dev,项目名称:tox,代码行数:11,代码来源:__init__.py

示例14: ensure_requires_satisfied

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def ensure_requires_satisfied(config, requires, min_version):
        missing_requirements = []
        failed_to_parse = False
        deps = []
        exists = set()
        for require in requires + [min_version]:
            # noinspection PyBroadException
            try:
                package = requirements.Requirement(require)
                # check if the package even applies
                if package.marker and not package.marker.evaluate({"extra": ""}):
                    continue
                package_name = canonicalize_name(package.name)
                if package_name not in exists:
                    deps.append(DepConfig(require, None))
                    exists.add(package_name)
                    dist = importlib_metadata.distribution(package.name)
                    if not package.specifier.contains(dist.version, prereleases=True):
                        raise MissingDependency(package)
            except requirements.InvalidRequirement as exception:
                failed_to_parse = True
                error("failed to parse {!r}".format(exception))
            except Exception as exception:
                verbosity1("could not satisfy requires {!r}".format(exception))
                missing_requirements.append(str(requirements.Requirement(require)))
        if failed_to_parse:
            raise tox.exception.BadRequirement()
        if WITHIN_PROVISION and missing_requirements:
            msg = "break infinite loop provisioning within {} missing {}"
            raise tox.exception.Error(msg.format(sys.executable, missing_requirements))
        config.run_provision = bool(len(missing_requirements))
        return deps 
开发者ID:tox-dev,项目名称:tox,代码行数:34,代码来源:__init__.py

示例15: build

# 需要导入模块: from packaging import utils [as 别名]
# 或者: from packaging.utils import canonicalize_name [as 别名]
def build(config, session):
    build_info = get_build_info(config.setupdir)
    package_venv = session.getvenv(config.isolated_build_env)
    package_venv.envconfig.deps_matches_subset = True

    # we allow user specified dependencies so the users can write extensions to
    # install additional type of dependencies (e.g. binary)
    user_specified_deps = package_venv.envconfig.deps
    package_venv.envconfig.deps = [DepConfig(r, None) for r in build_info.requires]
    package_venv.envconfig.deps.extend(user_specified_deps)

    if package_venv.setupenv():
        package_venv.finishvenv()
    if isinstance(package_venv.status, Exception):
        raise package_venv.status

    build_requires = get_build_requires(build_info, package_venv, config.setupdir)
    # we need to filter out requirements already specified in pyproject.toml or user deps
    base_build_deps = {
        canonicalize_name(Requirement(r.name).name) for r in package_venv.envconfig.deps
    }
    build_requires_dep = [
        DepConfig(r, None)
        for r in build_requires
        if canonicalize_name(Requirement(r).name) not in base_build_deps
    ]
    if build_requires_dep:
        with package_venv.new_action("build_requires", package_venv.envconfig.envdir) as action:
            package_venv.run_install_command(packages=build_requires_dep, action=action)
        package_venv.finishvenv()
    return perform_isolated_build(build_info, package_venv, config.distdir, config.setupdir) 
开发者ID:tox-dev,项目名称:tox,代码行数:33,代码来源:isolated.py


注:本文中的packaging.utils.canonicalize_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。