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


Python req_file.parse_requirements方法代碼示例

本文整理匯總了Python中pip._internal.req.req_file.parse_requirements方法的典型用法代碼示例。如果您正苦於以下問題:Python req_file.parse_requirements方法的具體用法?Python req_file.parse_requirements怎麽用?Python req_file.parse_requirements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pip._internal.req.req_file的用法示例。


在下文中一共展示了req_file.parse_requirements方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: find_required_modules

# 需要導入模塊: from pip._internal.req import req_file [as 別名]
# 或者: from pip._internal.req.req_file import parse_requirements [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

示例2: parse_requirement_file

# 需要導入模塊: from pip._internal.req import req_file [as 別名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 別名]
def parse_requirement_file(filename):
    from pip._internal.req.constructors import install_req_from_parsed_requirement

    finder = get_finder([])
    ireqs = [
        install_req_from_parsed_requirement(pr)
        for pr in parse_requirements(filename, finder.session, finder)
    ]
    return ireqs, finder 
開發者ID:frostming,項目名稱:pdm,代碼行數:11,代碼來源:requirements.py

示例3: get_requirements

# 需要導入模塊: from pip._internal.req import req_file [as 別名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 別名]
def get_requirements(requirement):
    """Parse a requirement file

    :param requirement: path to requirement file
    :returns: list of InstallRequirement
    :rtype: list[InstallRequirements]

    """
    session = PipSession()
    return parse_requirements(requirement, session=session) 
開發者ID:ali5h,項目名稱:rules_pip,代碼行數:12,代碼來源:piptool.py

示例4: fetch_requirements

# 需要導入模塊: from pip._internal.req import req_file [as 別名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 別名]
def fetch_requirements(requirements_file_path):
    """
    Return a list of requirements and links by parsing the provided requirements file.
    """
    links = []
    reqs = []
    for req in parse_requirements(requirements_file_path, session=False):
        # Note: req.url was used before 9.0.0 and req.link is used in all the recent versions
        link = getattr(req, 'link', getattr(req, 'url', None))
        if link:
            links.append(str(link))
        reqs.append(str(req.req))
    return (reqs, links) 
開發者ID:StackStorm,項目名稱:st2,代碼行數:15,代碼來源:dist_utils_old.py

示例5: load_requirements

# 需要導入模塊: from pip._internal.req import req_file [as 別名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 別名]
def load_requirements(file_path):
    return tuple((r for r in parse_requirements(file_path, session=False))) 
開發者ID:StackStorm,項目名稱:st2,代碼行數:4,代碼來源:fixate-requirements.py

示例6: parse_requirements

# 需要導入模塊: from pip._internal.req import req_file [as 別名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 別名]
def parse_requirements(path):
    from pip._internal.req import req_file

    return req_file.parse_requirements(path, session="unused") 
開發者ID:guildai,項目名稱:guildai,代碼行數:6,代碼來源:pip_util.py

示例7: is_requirements

# 需要導入模塊: from pip._internal.req import req_file [as 別名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 別名]
def is_requirements(path):
    if not util.is_text_file(path):
        return False
    try:
        list(parse_requirements(path))
    except Exception:
        return False
    else:
        return True 
開發者ID:guildai,項目名稱:guildai,代碼行數:11,代碼來源:pip_util.py

示例8: populate_requirement_set

# 需要導入模塊: from pip._internal.req import req_file [as 別名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 別名]
def populate_requirement_set(requirement_set, args, options, finder,
                                 session, name, wheel_cache):
        """
        Marshal cmd line args into a requirement set.
        """
        # NOTE: As a side-effect, options.require_hashes and
        #       requirement_set.require_hashes may be updated

        for filename in options.constraints:
            for req_to_add in parse_requirements(
                    filename,
                    constraint=True, finder=finder, options=options,
                    session=session, wheel_cache=wheel_cache):
                req_to_add.is_direct = True
                requirement_set.add_requirement(req_to_add)

        for req in args:
            req_to_add = InstallRequirement.from_line(
                req, None, isolated=options.isolated_mode,
                wheel_cache=wheel_cache
            )
            req_to_add.is_direct = True
            requirement_set.add_requirement(req_to_add)

        for req in options.editables:
            req_to_add = InstallRequirement.from_editable(
                req,
                isolated=options.isolated_mode,
                wheel_cache=wheel_cache
            )
            req_to_add.is_direct = True
            requirement_set.add_requirement(req_to_add)

        for filename in options.requirements:
            for req_to_add in parse_requirements(
                    filename,
                    finder=finder, options=options, session=session,
                    wheel_cache=wheel_cache):
                req_to_add.is_direct = True
                requirement_set.add_requirement(req_to_add)
        # If --require-hashes was a line in a requirements file, tell
        # RequirementSet about it:
        requirement_set.require_hashes = options.require_hashes

        if not (args or options.editables or options.requirements):
            opts = {'name': name}
            if options.find_links:
                raise CommandError(
                    'You must give at least one requirement to %(name)s '
                    '(maybe you meant "pip %(name)s %(links)s"?)' %
                    dict(opts, links=' '.join(options.find_links)))
            else:
                raise CommandError(
                    'You must give at least one requirement to %(name)s '
                    '(see "pip help %(name)s")' % opts) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:57,代碼來源:basecommand.py

示例9: populate_requirement_set

# 需要導入模塊: from pip._internal.req import req_file [as 別名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 別名]
def populate_requirement_set(requirement_set, args, options, finder,
                                 session, name, wheel_cache):
        """
        Marshal cmd line args into a requirement set.
        """
        # NOTE: As a side-effect, options.require_hashes and
        #       requirement_set.require_hashes may be updated

        for filename in options.constraints:
            for req_to_add in parse_requirements(
                    filename,
                    constraint=True, finder=finder, options=options,
                    session=session, wheel_cache=wheel_cache):
                req_to_add.is_direct = True
                requirement_set.add_requirement(req_to_add)

        for req in args:
            req_to_add = install_req_from_line(
                req, None, isolated=options.isolated_mode,
                wheel_cache=wheel_cache
            )
            req_to_add.is_direct = True
            requirement_set.add_requirement(req_to_add)

        for req in options.editables:
            req_to_add = install_req_from_editable(
                req,
                isolated=options.isolated_mode,
                wheel_cache=wheel_cache
            )
            req_to_add.is_direct = True
            requirement_set.add_requirement(req_to_add)

        for filename in options.requirements:
            for req_to_add in parse_requirements(
                    filename,
                    finder=finder, options=options, session=session,
                    wheel_cache=wheel_cache):
                req_to_add.is_direct = True
                requirement_set.add_requirement(req_to_add)
        # If --require-hashes was a line in a requirements file, tell
        # RequirementSet about it:
        requirement_set.require_hashes = options.require_hashes

        if not (args or options.editables or options.requirements):
            opts = {'name': name}
            if options.find_links:
                raise CommandError(
                    'You must give at least one requirement to %(name)s '
                    '(maybe you meant "pip %(name)s %(links)s"?)' %
                    dict(opts, links=' '.join(options.find_links)))
            else:
                raise CommandError(
                    'You must give at least one requirement to %(name)s '
                    '(see "pip help %(name)s")' % opts) 
開發者ID:luckystarufo,項目名稱:pySINDy,代碼行數:57,代碼來源:base_command.py

示例10: find_missing_reqs

# 需要導入模塊: from pip._internal.req import req_file [as 別名]
# 或者: from pip._internal.req.req_file import parse_requirements [as 別名]
def find_missing_reqs(options, requirements_filename):
    # 1. find files used by imports in the code (as best we can without
    #    executing)
    used_modules = common.find_imported_modules(options)

    # 2. find which packages provide which files
    installed_files = {}
    all_pkgs = (pkg.project_name for pkg in get_installed_distributions())
    for package in search_packages_info(all_pkgs):
        log.debug('installed package: %s (at %s)', package['name'],
                  package['location'])
        for package_file in package.get('files', []) or []:
            path = os.path.realpath(
                os.path.join(package['location'], package_file),
            )
            installed_files[path] = package['name']
            package_path = common.is_package_file(path)
            if package_path:
                # we've seen a package file so add the bare package directory
                # to the installed list as well as we might want to look up
                # a package by its directory path later
                installed_files[package_path] = package['name']

    # 3. match imported modules against those packages
    used = collections.defaultdict(list)
    for modname, info in used_modules.items():
        # probably standard library if it's not in the files list
        if info.filename in installed_files:
            used_name = canonicalize_name(installed_files[info.filename])
            log.debug('used module: %s (from package %s)', modname,
                      installed_files[info.filename])
            used[used_name].append(info)
        else:
            log.debug(
                'used module: %s (from file %s, assuming stdlib or local)',
                modname, info.filename)

    # 4. compare with requirements.txt
    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

        log.debug('found requirement: %s', requirement_name)
        explicit.add(canonicalize_name(requirement_name))

    return [(name, used[name]) for name in used if name not in explicit] 
開發者ID:r1chardj0n3s,項目名稱:pip-check-reqs,代碼行數:60,代碼來源:find_missing_reqs.py


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