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


Python pkg_resources.Requirement方法代码示例

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


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

示例1: __init__

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def __init__(self, line, env, source=None):
        self.line = line
        self.egg = None
        if isinstance(line, pkg_resources.Requirement):
            self.req = line
        elif test_vcs(line):
            res = parse_vcs_requirement(line)
            if not res:
                raise PundleException('Bad url %r' % line)
            egg, req, version = res
            self.egg = egg
            self.req = None  # pkg_resources.Requirement.parse(res)
        else:
            self.req = pkg_resources.Requirement.parse(line)
        self.sources = set([source])
        self.envs = set()
        self.add_env(env) 
开发者ID:Deepwalker,项目名称:pundler,代码行数:19,代码来源:pundle.py

示例2: cmd_info

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def cmd_info():
    "prints info about Pundle state"
    parser_kw = create_parser_parameters()
    suite = create_parser(**parser_kw).create_suite()
    if suite.need_freeze():
        print('frozen.txt is outdated')
    else:
        print('frozen.txt is up to date')
    for state in suite.required_states():
        print(
            'Requirement "{}", frozen {}, {}'.format(
                state.key,
                state.frozen,
                state.requirement.line if state.requirement else 'None'
            )
        )
        print('Installed versions:')
        for dist in state.installed:
            print('    ', repr(dist))
        if not state.installed:
            print('     None') 
开发者ID:Deepwalker,项目名称:pundler,代码行数:23,代码来源:pundle.py

示例3: strip_extras_markers_from_requirement

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def strip_extras_markers_from_requirement(req):
    # type: (TRequirement) -> TRequirement
    """
    Strips extras markers from requirement instances.

    Given a :class:`~packaging.requirements.Requirement` instance with markers defining
    *extra == 'name'*, strip out the extras from the markers and return the cleaned
    requirement

    :param PackagingRequirement req: A packaging requirement to clean
    :return: A cleaned requirement
    :rtype: PackagingRequirement
    """
    if req is None:
        raise TypeError("Must pass in a valid requirement, received {0!r}".format(req))
    if getattr(req, "marker", None) is not None:
        marker = req.marker  # type: TMarker
        marker._markers = _strip_extras_markers(marker._markers)
        if not marker._markers:
            req.marker = None
        else:
            req.marker = marker
    return req 
开发者ID:pypa,项目名称:pipenv,代码行数:25,代码来源:utils.py

示例4: parse_requirements_from_file

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def parse_requirements_from_file(path):
    """Parses requirements from a requirements file.

    Args:
      path (str): path to the requirements file.

    Yields:
      pkg_resources.Requirement: package resource requirement.
    """
    with open(path, 'r') as file_object:
        file_contents = file_object.read()
    for req in pkg_resources.parse_requirements(file_contents):
        try:
            requirement = str(req.req)
        except AttributeError:
            requirement = str(req)
        yield requirement 
开发者ID:google,项目名称:timesketch,代码行数:19,代码来源:setup.py

示例5: test_get_cmap_filesystem

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def test_get_cmap_filesystem(monkeypatch):
    import pkg_resources
    import importlib

    import terracotta.cmaps.get_cmaps

    def throw_error(*args, **kwargs):
        raise pkg_resources.DistributionNotFound('monkeypatched')

    with monkeypatch.context() as m:
        m.setattr(pkg_resources.Requirement, 'parse', throw_error)

        with pytest.raises(pkg_resources.DistributionNotFound):
            pkg_resources.Requirement.parse('terracotta')

        importlib.reload(terracotta.cmaps.get_cmaps)

        cmap = terracotta.cmaps.get_cmaps.get_cmap('jet')
        assert cmap.shape == (255, 4)
        assert cmap.dtype == np.uint8 
开发者ID:DHI-GRAS,项目名称:terracotta,代码行数:22,代码来源:test_get_cmap.py

示例6: _get_template_file_path

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def _get_template_file_path(options, default_path):
    """
    Get template file path.
    :return:
    """
    forensics_path = options.get("forensics_template", default_path)
    if forensics_path and not os.path.exists(forensics_path):
        log.warning(u"Template file '%s' not found.", forensics_path)
        forensics_path = None
    if not forensics_path:
        # Use the template file installed by this package
        forensics_path = resource_filename(Requirement("fn-proofpoint_tap"),
                                           "fn_proofpoint_tap/data/templates/pp_threat_forensics.jinja")
    if not os.path.exists(forensics_path):
        raise Exception(u"Template file '{}' not found".format(forensics_path))

    return forensics_path 
开发者ID:ibmresilient,项目名称:resilient-community-apps,代码行数:19,代码来源:proofpoint_common.py

示例7: formula_for

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def formula_for(package, also=None):
    also = also or []

    req = pkg_resources.Requirement.parse(package)
    package_name = req.project_name

    nodes = merge_graphs(make_graph(p) for p in [package] + also)
    resources = [value for key, value in nodes.items()
                 if key.lower() != package_name.lower()]

    if package_name in nodes:
        root = nodes[package_name]
    elif package_name.lower() in nodes:
        root = nodes[package_name.lower()]
    else:
        raise Exception("Could not find package {} in nodes {}".format(package, nodes.keys()))

    python = "python" if sys.version_info.major == 2 else "python3"
    return FORMULA_TEMPLATE.render(package=root,
                                   resources=resources,
                                   python=python,
                                   ResourceTemplate=RESOURCE_TEMPLATE) 
开发者ID:tdsmith,项目名称:homebrew-pypi-poet,代码行数:24,代码来源:poet.py

示例8: adjust_with_req

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def adjust_with_req(self, req):
        if not self.req:
            return
            raise PundleException('VCS')
        versions = ','.join(''.join(t) for t in set(self.req.specs + req.req.specs))
        self.requirement = pkg_resources.Requirement.parse('{} {}'.format(
            self.req.project_name, versions
        ))
        self.sources.update(req.sources)
        self.add_env(req.envs) 
开发者ID:Deepwalker,项目名称:pundler,代码行数:12,代码来源:pundle.py

示例9: _get_version_from_pkg_resources

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def _get_version_from_pkg_resources(modulename):
    ws = pkg_resources.working_set
    package = ws.find(pkg_resources.Requirement(modulename))
    try:
        version = package.version
    except AttributeError:
        version = '?'
    return version 
开发者ID:recipy,项目名称:recipy,代码行数:10,代码来源:libraryversions.py

示例10: init_requirement

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def init_requirement(name):
    # type: (AnyStr) -> TRequirement

    if not isinstance(name, six.string_types):
        raise TypeError("must supply a name to generate a requirement")
    from pkg_resources import Requirement

    req = Requirement.parse(name)
    req.vcs = None
    req.local_file = None
    req.revision = None
    req.path = None
    return req 
开发者ID:pypa,项目名称:pipenv,代码行数:15,代码来源:utils.py

示例11: parse_extras

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def parse_extras(extras_str):
    # type: (AnyStr) -> List[AnyStr]
    """Turn a string of extras into a parsed extras list

    :param str extras_str: An extras string
    :return: A sorted list of extras
    :rtype: List[str]
    """

    from pkg_resources import Requirement

    extras = Requirement.parse("fakepkg{0}".format(extras_to_string(extras_str))).extras
    return sorted(dedup([extra.lower() for extra in extras])) 
开发者ID:pypa,项目名称:pipenv,代码行数:15,代码来源:utils.py

示例12: get_setuptools_version

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def get_setuptools_version():
    # type: () -> Optional[STRING_TYPE]
    import pkg_resources

    setuptools_dist = pkg_resources.get_distribution(
        pkg_resources.Requirement("setuptools")
    )
    return getattr(setuptools_dist, "version", None) 
开发者ID:pypa,项目名称:pipenv,代码行数:10,代码来源:utils.py

示例13: _requirement_to_str_lowercase_name

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def _requirement_to_str_lowercase_name(requirement):
    """Formats a packaging.requirements.Requirement with a lowercase name.

    This is simply a copy of
    https://github.com/pypa/packaging/blob/16.8/packaging/requirements.py#L109-L124
    modified to lowercase the dependency name.

    Previously, we were invoking the original Requirement.__str__ method and
    lower-casing the entire result, which would lowercase the name, *and* other,
    important stuff that should not be lower-cased (such as the marker). See
    this issue for more information: https://github.com/pypa/pipenv/issues/2113.
    """
    parts = [requirement.name.lower()]

    if requirement.extras:
        parts.append("[{0}]".format(",".join(sorted(requirement.extras))))

    if requirement.specifier:
        parts.append(str(requirement.specifier))

    if requirement.url:
        parts.append("@ {0}".format(requirement.url))

    if requirement.marker:
        parts.append("; {0}".format(requirement.marker))

    return "".join(parts) 
开发者ID:pypa,项目名称:pipenv,代码行数:29,代码来源:utils.py

示例14: config_section_data

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def config_section_data():
    """sample config data for use in app.config"""
    section_config_fn = resource_filename(Requirement("rc-cts"), "rc_cts/data/app.config.cts")
    with open(section_config_fn, 'r') as section_config_file:
        return section_config_file.read() 
开发者ID:ibmresilient,项目名称:resilient-python-api,代码行数:7,代码来源:threat_webservice.py

示例15: dependencies

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Requirement [as 别名]
def dependencies(self, extras_requested: Optional[Set[str]] = None) -> Set[str]:
        dependency_set = set()

        for wheel_req in self.metadata.requires_dist:
            req = pkg_resources.Requirement(wheel_req)  # type: ignore

            if req.marker is None or any(
                req.marker.evaluate({"extra": extra})
                for extra in extras_requested or [""]
            ):
                dependency_set.add(req.name)  # type: ignore

        return dependency_set 
开发者ID:dillon-giacoppo,项目名称:rules_python_external,代码行数:15,代码来源:wheel.py


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