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


Python requirements.Requirement方法代码示例

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


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

示例1: parse_req_from_editable

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def parse_req_from_editable(editable_req):
    # type: (str) -> RequirementParts
    name, url, extras_override = parse_editable(editable_req)

    if name is not None:
        try:
            req = Requirement(name)
        except InvalidRequirement:
            raise InstallationError("Invalid requirement: '%s'" % name)
    else:
        req = None

    link = Link(url)

    return RequirementParts(req, link, None, extras_override)


# ---- The actual constructors follow ---- 
开发者ID:pantsbuild,项目名称:pex,代码行数:20,代码来源:constructors.py

示例2: install_req_from_req

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def install_req_from_req(
    req, comes_from=None, isolated=False, wheel_cache=None
):
    try:
        req = Requirement(req)
    except InvalidRequirement:
        raise InstallationError("Invalid requirement: '%s'" % req)

    domains_not_allowed = [
        PyPI.file_storage_domain,
        TestPyPI.file_storage_domain,
    ]
    if req.url and comes_from.link.netloc in domains_not_allowed:
        # Explicitly disallow pypi packages that depend on external urls
        raise InstallationError(
            "Packages installed from PyPI cannot depend on packages "
            "which are not also hosted on PyPI.\n"
            "%s depends on %s " % (comes_from.name, req)
        )

    return InstallRequirement(
        req, comes_from, isolated=isolated, wheel_cache=wheel_cache
    ) 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:25,代码来源:constructors.py

示例3: check_if_exists

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def check_if_exists(self):
        """Find an installed distribution that satisfies or conflicts
        with this requirement, and set self.satisfied_by or
        self.conflicts_with appropriately.
        """
        if self.req is None:
            return False
        try:
            # get_distribution() will resolve the entire list of requirements
            # anyway, and we've already determined that we need the requirement
            # in question, so strip the marker so that we don't try to
            # evaluate it.
            no_marker = Requirement(str(self.req))
            no_marker.marker = None
            self.satisfied_by = pkg_resources.get_distribution(str(no_marker))
            if self.editable and self.satisfied_by:
                self.conflicts_with = self.satisfied_by
                # when installing editables, nothing pre-existing should ever
                # satisfy
                self.satisfied_by = None
                return True
        except pkg_resources.DistributionNotFound:
            return False
        except pkg_resources.VersionConflict:
            existing_dist = pkg_resources.get_distribution(
                self.req.name
            )
            if self.use_user_site:
                if dist_in_usersite(existing_dist):
                    self.conflicts_with = existing_dist
                elif (running_under_virtualenv() and
                        dist_in_site_packages(existing_dist)):
                    raise InstallationError(
                        "Will not install to the user site because it will "
                        "lack sys.path precedence to %s in %s" %
                        (existing_dist.project_name, existing_dist.location)
                    )
            else:
                self.conflicts_with = existing_dist
        return True 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:42,代码来源:req_install.py

示例4: from_editable

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def from_editable(cls, editable_req, comes_from=None, isolated=False,
                      options=None, wheel_cache=None, constraint=False):
        from pip._internal.index import Link

        name, url, extras_override = parse_editable(editable_req)
        if url.startswith('file:'):
            source_dir = url_to_path(url)
        else:
            source_dir = None

        if name is not None:
            try:
                req = Requirement(name)
            except InvalidRequirement:
                raise InstallationError("Invalid requirement: '%s'" % name)
        else:
            req = None
        return cls(
            req, comes_from, source_dir=source_dir,
            editable=True,
            link=Link(url),
            constraint=constraint,
            isolated=isolated,
            options=options if options else {},
            wheel_cache=wheel_cache,
            extras=extras_override or (),
        ) 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:29,代码来源:req_install.py

示例5: from_req

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def from_req(cls, req, comes_from=None, isolated=False, wheel_cache=None):
        try:
            req = Requirement(req)
        except InvalidRequirement:
            raise InstallationError("Invalid requirement: '%s'" % req)
        if req.url:
            raise InstallationError(
                "Direct url requirement (like %s) are not allowed for "
                "dependencies" % req
            )
        return cls(req, comes_from, isolated=isolated, wheel_cache=wheel_cache) 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:13,代码来源:req_install.py

示例6: check_if_exists

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def check_if_exists(self, use_user_site):
        """Find an installed distribution that satisfies or conflicts
        with this requirement, and set self.satisfied_by or
        self.conflicts_with appropriately.
        """
        if self.req is None:
            return False
        try:
            # get_distribution() will resolve the entire list of requirements
            # anyway, and we've already determined that we need the requirement
            # in question, so strip the marker so that we don't try to
            # evaluate it.
            no_marker = Requirement(str(self.req))
            no_marker.marker = None
            self.satisfied_by = pkg_resources.get_distribution(str(no_marker))
            if self.editable and self.satisfied_by:
                self.conflicts_with = self.satisfied_by
                # when installing editables, nothing pre-existing should ever
                # satisfy
                self.satisfied_by = None
                return True
        except pkg_resources.DistributionNotFound:
            return False
        except pkg_resources.VersionConflict:
            existing_dist = pkg_resources.get_distribution(
                self.req.name
            )
            if use_user_site:
                if dist_in_usersite(existing_dist):
                    self.conflicts_with = existing_dist
                elif (running_under_virtualenv() and
                        dist_in_site_packages(existing_dist)):
                    raise InstallationError(
                        "Will not install to the user site because it will "
                        "lack sys.path precedence to %s in %s" %
                        (existing_dist.project_name, existing_dist.location)
                    )
            else:
                self.conflicts_with = existing_dist
        return True 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:42,代码来源:req_install.py

示例7: check_if_exists

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def check_if_exists(self):
        """Find an installed distribution that satisfies or conflicts
        with this requirement, and set self.satisfied_by or
        self.conflicts_with appropriately.
        """
        if self.req is None:
            return False
        try:
            # get_distribution() will resolve the entire list of requirements
            # anyway, and we've already determined that we need the requirement
            # in question, so strip the marker so that we don't try to
            # evaluate it.
            no_marker = Requirement(str(self.req))
            no_marker.marker = None
            self.satisfied_by = pkg_resources.get_distribution(str(no_marker))
        except pkg_resources.DistributionNotFound:
            return False
        except pkg_resources.VersionConflict:
            existing_dist = pkg_resources.get_distribution(
                self.req.name
            )
            if self.use_user_site:
                if dist_in_usersite(existing_dist):
                    self.conflicts_with = existing_dist
                elif (running_under_virtualenv() and
                        dist_in_site_packages(existing_dist)):
                    raise InstallationError(
                        "Will not install to the user site because it will "
                        "lack sys.path precedence to %s in %s" %
                        (existing_dist.project_name, existing_dist.location)
                    )
            else:
                self.conflicts_with = existing_dist
        return True 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:36,代码来源:req_install.py

示例8: install_req_from_editable

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def install_req_from_editable(
    editable_req,  # type: str
    comes_from=None,  # type: Optional[str]
    use_pep517=None,  # type: Optional[bool]
    isolated=False,  # type: bool
    options=None,  # type: Optional[Dict[str, Any]]
    wheel_cache=None,  # type: Optional[WheelCache]
    constraint=False  # type: bool
):
    # type: (...) -> InstallRequirement
    name, url, extras_override = parse_editable(editable_req)
    if url.startswith('file:'):
        source_dir = url_to_path(url)
    else:
        source_dir = None

    if name is not None:
        try:
            req = Requirement(name)
        except InvalidRequirement:
            raise InstallationError("Invalid requirement: '%s'" % name)
    else:
        req = None
    return InstallRequirement(
        req, comes_from, source_dir=source_dir,
        editable=True,
        link=Link(url),
        constraint=constraint,
        use_pep517=use_pep517,
        isolated=isolated,
        options=options if options else {},
        wheel_cache=wheel_cache,
        extras=extras_override or (),
    ) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:36,代码来源:constructors.py

示例9: install_req_from_req_string

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def install_req_from_req_string(
    req_string,  # type: str
    comes_from=None,  # type: Optional[InstallRequirement]
    isolated=False,  # type: bool
    wheel_cache=None,  # type: Optional[WheelCache]
    use_pep517=None  # type: Optional[bool]
):
    # type: (...) -> InstallRequirement
    try:
        req = Requirement(req_string)
    except InvalidRequirement:
        raise InstallationError("Invalid requirement: '%s'" % req_string)

    domains_not_allowed = [
        PyPI.file_storage_domain,
        TestPyPI.file_storage_domain,
    ]
    if (req.url and comes_from and comes_from.link and
            comes_from.link.netloc in domains_not_allowed):
        # Explicitly disallow pypi packages that depend on external urls
        raise InstallationError(
            "Packages installed from PyPI cannot depend on packages "
            "which are not also hosted on PyPI.\n"
            "%s depends on %s " % (comes_from.name, req)
        )

    return InstallRequirement(
        req, comes_from, isolated=isolated, wheel_cache=wheel_cache,
        use_pep517=use_pep517
    ) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:32,代码来源:constructors.py

示例10: prepare_metadata

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def prepare_metadata(self):
        # type: () -> None
        """Ensure that project metadata is available.

        Under PEP 517, call the backend hook to prepare the metadata.
        Under legacy processing, call setup.py egg-info.
        """
        assert self.source_dir

        with indent_log():
            if self.use_pep517:
                self.prepare_pep517_metadata()
            else:
                self.run_egg_info()

        if not self.req:
            if isinstance(parse_version(self.metadata["Version"]), Version):
                op = "=="
            else:
                op = "==="
            self.req = Requirement(
                "".join([
                    self.metadata["Name"],
                    op,
                    self.metadata["Version"],
                ])
            )
            self._correct_build_location()
        else:
            metadata_name = canonicalize_name(self.metadata["Name"])
            if canonicalize_name(self.req.name) != metadata_name:
                logger.warning(
                    'Generating metadata for package %s '
                    'produced metadata for project name %s. Fix your '
                    '#egg=%s fragments.',
                    self.name, metadata_name, self.name
                )
                self.req = Requirement(metadata_name) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:40,代码来源:req_install.py

示例11: convert_extras

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def convert_extras(extras):
    # type: (Optional[str]) -> Set[str]
    if not extras:
        return set()
    return Requirement("placeholder" + extras.lower()).extras 
开发者ID:pantsbuild,项目名称:pex,代码行数:7,代码来源:constructors.py

示例12: __init__

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def __init__(
            self,
            requirement,  # type: Optional[Requirement]
            link,         # type: Optional[Link]
            markers,      # type: Optional[Marker]
            extras,       # type: Set[str]
    ):
        self.requirement = requirement
        self.link = link
        self.markers = markers
        self.extras = extras 
开发者ID:pantsbuild,项目名称:pex,代码行数:13,代码来源:constructors.py

示例13: _get_url_from_path

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def _get_url_from_path(path, name):
    # type: (str, str) -> str
    """
    First, it checks whether a provided path is an installable directory
    (e.g. it has a setup.py). If it is, returns the path.

    If false, check if the path is an archive file (such as a .whl).
    The function checks if the path is a file. If false, if the path has
    an @, it will treat it as a PEP 440 URL requirement and return the path.
    """
    if _looks_like_path(name) and os.path.isdir(path):
        if is_installable_dir(path):
            return path_to_url(path)
        raise InstallationError(
            "Directory %r is not installable. Neither 'setup.py' "
            "nor 'pyproject.toml' found." % name
        )
    if not is_archive_file(path):
        return None
    if os.path.isfile(path):
        return path_to_url(path)
    urlreq_parts = name.split('@', 1)
    if len(urlreq_parts) >= 2 and not _looks_like_path(urlreq_parts[0]):
        # If the path contains '@' and the part before it does not look
        # like a path, try to treat it as a PEP 440 URL req instead.
        return None
    logger.warning(
        'Requirement %r looks like a filename, but the '
        'file does not exist',
        name
    )
    return path_to_url(path) 
开发者ID:pantsbuild,项目名称:pex,代码行数:34,代码来源:constructors.py

示例14: warn_on_mismatching_name

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def warn_on_mismatching_name(self):
        # type: () -> None
        metadata_name = canonicalize_name(self.metadata["Name"])
        if canonicalize_name(self.req.name) == metadata_name:
            # Everything is fine.
            return

        # If we're here, there's a mismatch. Log a warning about it.
        logger.warning(
            'Generating metadata for package %s '
            'produced metadata for project name %s. Fix your '
            '#egg=%s fragments.',
            self.name, metadata_name, self.name
        )
        self.req = Requirement(metadata_name) 
开发者ID:pantsbuild,项目名称:pex,代码行数:17,代码来源:req_install.py

示例15: install_req_from_req_string

# 需要导入模块: from pip._vendor.packaging import requirements [as 别名]
# 或者: from pip._vendor.packaging.requirements import Requirement [as 别名]
def install_req_from_req_string(
    req_string,  # type: str
    comes_from=None,  # type: Optional[InstallRequirement]
    isolated=False,  # type: bool
    wheel_cache=None,  # type: Optional[WheelCache]
    use_pep517=None  # type: Optional[bool]
):
    # type: (...) -> InstallRequirement
    try:
        req = Requirement(req_string)
    except InvalidRequirement:
        raise InstallationError("Invalid requirement: '%s'" % req)

    domains_not_allowed = [
        PyPI.file_storage_domain,
        TestPyPI.file_storage_domain,
    ]
    if req.url and comes_from.link.netloc in domains_not_allowed:
        # Explicitly disallow pypi packages that depend on external urls
        raise InstallationError(
            "Packages installed from PyPI cannot depend on packages "
            "which are not also hosted on PyPI.\n"
            "%s depends on %s " % (comes_from.name, req)
        )

    return InstallRequirement(
        req, comes_from, isolated=isolated, wheel_cache=wheel_cache,
        use_pep517=use_pep517
    ) 
开发者ID:QData,项目名称:deepWordBug,代码行数:31,代码来源:constructors.py


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