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


Python req.RequirementSet类代码示例

本文整理汇总了Python中pip._internal.req.RequirementSet的典型用法代码示例。如果您正苦于以下问题:Python RequirementSet类的具体用法?Python RequirementSet怎么用?Python RequirementSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_unpinned_hash_checking

 def test_unpinned_hash_checking(self, data):
     """Make sure prepare_files() raises an error when a requirement is not
     version-pinned in hash-checking mode.
     """
     reqset = RequirementSet()
     # Test that there must be exactly 1 specifier:
     reqset.add_requirement(get_processed_req_from_line(
         'simple --hash=sha256:a90427ae31f5d1d0d7ec06ee97d9fcf2d0fc9a786985'
         '250c1c83fd68df5911dd', lineno=1,
     ))
     # Test that the operator must be ==:
     reqset.add_requirement(get_processed_req_from_line(
         'simple2>1.0 --hash=sha256:3ad45e1e9aa48b4462af0'
         '123f6a7e44a9115db1ef945d4d92c123dfe21815a06',
         lineno=2,
     ))
     finder = PackageFinder([data.find_links], [], session=PipSession())
     resolver = self._basic_resolver(finder)
     assert_raises_regexp(
         HashErrors,
         # Make sure all failing requirements are listed:
         r'versions pinned with ==. These do not:\n'
         r'    simple .* \(from -r file \(line 1\)\)\n'
         r'    simple2>1.0 .* \(from -r file \(line 2\)\)',
         resolver.resolve,
         reqset)
开发者ID:jaraco,项目名称:pip,代码行数:26,代码来源:test_req.py

示例2: test_unsupported_hashes

    def test_unsupported_hashes(self, data):
        """VCS and dir links should raise errors when --require-hashes is
        on.

        In addition, complaints about the type of requirement (VCS or dir)
        should trump the presence or absence of a hash.

        """
        reqset = RequirementSet(require_hashes=True)
        reqset.add_requirement(get_processed_req_from_line(
            'git+git://github.com/pypa/pip-test-package --hash=sha256:123',
            lineno=1,
        ))
        dir_path = data.packages.join('FSPkg')
        reqset.add_requirement(get_processed_req_from_line(
            'file://%s' % (dir_path,),
            lineno=2,
        ))
        finder = PackageFinder([data.find_links], [], session=PipSession())
        resolver = self._basic_resolver(finder)
        sep = os.path.sep
        if sep == '\\':
            sep = '\\\\'  # This needs to be escaped for the regex
        assert_raises_regexp(
            HashErrors,
            r"Can't verify hashes for these requirements because we don't "
            r"have a way to hash version control repositories:\n"
            r"    git\+git://github\.com/pypa/pip-test-package \(from -r file "
            r"\(line 1\)\)\n"
            r"Can't verify hashes for these file:// requirements because they "
            r"point to directories:\n"
            r"    file://.*{sep}data{sep}packages{sep}FSPkg "
            r"\(from -r file \(line 2\)\)".format(sep=sep),
            resolver.resolve,
            reqset)
开发者ID:jaraco,项目名称:pip,代码行数:35,代码来源:test_req.py

示例3: test_unsupported_wheel_local_file_requirement_raises

    def test_unsupported_wheel_local_file_requirement_raises(self, data):
        reqset = RequirementSet()
        req = install_req_from_line(
            data.packages.join('simple.dist-0.1-py1-none-invalid.whl'),
        )
        assert req.link is not None
        assert req.link.is_wheel
        assert req.link.scheme == "file"

        with pytest.raises(InstallationError):
            reqset.add_requirement(req)
开发者ID:jaraco,项目名称:pip,代码行数:11,代码来源:test_req.py

示例4: test_unsupported_wheel_link_requirement_raises

    def test_unsupported_wheel_link_requirement_raises(self):
        reqset = RequirementSet()
        req = install_req_from_line(
            'https://whatever.com/peppercorn-0.4-py2.py3-bogus-any.whl',
        )
        assert req.link is not None
        assert req.link.is_wheel
        assert req.link.scheme == "https"

        with pytest.raises(InstallationError):
            reqset.add_requirement(req)
开发者ID:jaraco,项目名称:pip,代码行数:11,代码来源:test_req.py

示例5: test_exclusive_environment_markers

def test_exclusive_environment_markers():
    """Make sure RequirementSet accepts several excluding env markers"""
    eq26 = InstallRequirement.from_line(
        "Django>=1.6.10,<1.7 ; python_version == '2.6'")
    ne26 = InstallRequirement.from_line(
        "Django>=1.6.10,<1.8 ; python_version != '2.6'")

    req_set = RequirementSet('', '', '')
    req_set.add_requirement(eq26)
    req_set.add_requirement(ne26)
    assert req_set.has_requirement('Django')
开发者ID:oz123,项目名称:pip,代码行数:11,代码来源:test_req.py

示例6: test_environment_marker_extras

 def test_environment_marker_extras(self, data):
     """
     Test that the environment marker extras are used with
     non-wheel installs.
     """
     reqset = RequirementSet()
     req = InstallRequirement.from_editable(
         data.packages.join("LocalEnvironMarker"))
     reqset.add_requirement(req)
     finder = PackageFinder([data.find_links], [], session=PipSession())
     resolver = self._basic_resolver(finder)
     resolver.resolve(reqset)
     # This is hacky but does test both case in py2 and py3
     if sys.version_info[:2] in ((2, 7), (3, 4)):
         assert reqset.has_requirement('simple')
     else:
         assert not reqset.has_requirement('simple')
开发者ID:oz123,项目名称:pip,代码行数:17,代码来源:test_req.py

示例7: test_missing_hash_with_require_hashes

 def test_missing_hash_with_require_hashes(self, data):
     """Setting --require-hashes explicitly should raise errors if hashes
     are missing.
     """
     reqset = RequirementSet(require_hashes=True)
     reqset.add_requirement(
         list(process_line('simple==1.0', 'file', 1))[0])
     finder = PackageFinder([data.find_links], [], session=PipSession())
     resolver = self._basic_resolver(finder)
     assert_raises_regexp(
         HashErrors,
         r'Hashes are required in --require-hashes mode, but they are '
         r'missing .*\n'
         r'    simple==1.0 --hash=sha256:393043e672415891885c9a2a0929b1af95'
         r'fb866d6ca016b42d2e6ce53619b653$',
         resolver.resolve,
         reqset)
开发者ID:oz123,项目名称:pip,代码行数:17,代码来源:test_req.py

示例8: test_no_reuse_existing_build_dir

    def test_no_reuse_existing_build_dir(self, data):
        """Test prepare_files raise exception with previous build dir"""

        build_dir = os.path.join(self.tempdir, 'build', 'simple')
        os.makedirs(build_dir)
        open(os.path.join(build_dir, "setup.py"), 'w')
        reqset = RequirementSet()
        req = InstallRequirement.from_line('simple')
        reqset.add_requirement(req)
        finder = PackageFinder([data.find_links], [], session=PipSession())
        resolver = self._basic_resolver(finder)
        assert_raises_regexp(
            PreviousBuildDirError,
            r"pip can't proceed with [\s\S]*%s[\s\S]*%s" %
            (req, build_dir.replace('\\', '\\\\')),
            resolver.resolve,
            reqset,
        )
开发者ID:oz123,项目名称:pip,代码行数:18,代码来源:test_req.py

示例9: test_unhashed_deps_on_require_hashes

 def test_unhashed_deps_on_require_hashes(self, data):
     """Make sure unhashed, unpinned, or otherwise unrepeatable
     dependencies get complained about when --require-hashes is on."""
     reqset = RequirementSet()
     finder = PackageFinder([data.find_links], [], session=PipSession())
     resolver = self._basic_resolver(finder)
     reqset.add_requirement(next(process_line(
         'TopoRequires2==0.0.1 '  # requires TopoRequires
         '--hash=sha256:eaf9a01242c9f2f42cf2bd82a6a848cd'
         'e3591d14f7896bdbefcf48543720c970',
         'file', 1)))
     assert_raises_regexp(
         HashErrors,
         r'In --require-hashes mode, all requirements must have their '
         r'versions pinned.*\n'
         r'    TopoRequires from .*$',
         resolver.resolve,
         reqset)
开发者ID:oz123,项目名称:pip,代码行数:18,代码来源:test_req.py

示例10: test_hash_mismatch

 def test_hash_mismatch(self, data):
     """A hash mismatch should raise an error."""
     file_url = path_to_url(
         (data.packages / 'simple-1.0.tar.gz').abspath)
     reqset = RequirementSet(require_hashes=True)
     reqset.add_requirement(get_processed_req_from_line(
         '%s --hash=sha256:badbad' % file_url, lineno=1,
     ))
     finder = PackageFinder([data.find_links], [], session=PipSession())
     resolver = self._basic_resolver(finder)
     assert_raises_regexp(
         HashErrors,
         r'THESE PACKAGES DO NOT MATCH THE HASHES.*\n'
         r'    file:///.*/data/packages/simple-1\.0\.tar\.gz .*:\n'
         r'        Expected sha256 badbad\n'
         r'             Got        393043e672415891885c9a2a0929b1af95fb866d'
         r'6ca016b42d2e6ce53619b653$',
         resolver.resolve,
         reqset)
开发者ID:jaraco,项目名称:pip,代码行数:19,代码来源:test_req.py

示例11: test_missing_hash_checking

 def test_missing_hash_checking(self):
     """Make sure prepare_files() raises an error when a requirement has no
     hash in implicit hash-checking mode.
     """
     reqset = RequirementSet()
     # No flags here. This tests that detection of later flags nonetheless
     # requires earlier packages to have hashes:
     reqset.add_requirement(get_processed_req_from_line(
         'blessings==1.0', lineno=1
     ))
     # This flag activates --require-hashes mode:
     reqset.add_requirement(get_processed_req_from_line(
         'tracefront==0.1 --hash=sha256:somehash', lineno=2,
     ))
     # This hash should be accepted because it came from the reqs file, not
     # from the internet:
     reqset.add_requirement(get_processed_req_from_line(
         'https://files.pythonhosted.org/packages/source/m/more-itertools/'
         'more-itertools-1.0.tar.gz#md5=b21850c3cfa7efbb70fd662ab5413bdd',
         lineno=3,
     ))
     # The error text should list this as a URL and not `peep==3.1.1`:
     reqset.add_requirement(get_processed_req_from_line(
         'https://files.pythonhosted.org/'
         'packages/source/p/peep/peep-3.1.1.tar.gz',
         lineno=4,
     ))
     finder = PackageFinder(
         [],
         ['https://pypi.org/simple/'],
         session=PipSession(),
     )
     resolver = self._basic_resolver(finder)
     assert_raises_regexp(
         HashErrors,
         r'Hashes are required in --require-hashes mode, but they are '
         r'missing .*\n'
         r'    https://files\.pythonhosted\.org/packages/source/p/peep/peep'
         r'-3\.1\.1\.tar\.gz --hash=sha256:[0-9a-f]+\n'
         r'    blessings==1.0 --hash=sha256:[0-9a-f]+\n'
         r'THESE PACKAGES DO NOT MATCH THE HASHES.*\n'
         r'    tracefront==0.1 .*:\n'
         r'        Expected sha256 somehash\n'
         r'             Got        [0-9a-f]+$',
         resolver.resolve,
         reqset
     )
开发者ID:jaraco,项目名称:pip,代码行数:47,代码来源:test_req.py

示例12: test_hashed_deps_on_require_hashes

    def test_hashed_deps_on_require_hashes(self, data):
        """Make sure hashed dependencies get installed when --require-hashes
        is on.

        (We actually just check that no "not all dependencies are hashed!"
        error gets raised while preparing; there is no reason to expect
        installation to then fail, as the code paths are the same as ever.)

        """
        reqset = RequirementSet()
        reqset.add_requirement(next(process_line(
            'TopoRequires2==0.0.1 '  # requires TopoRequires
            '--hash=sha256:eaf9a01242c9f2f42cf2bd82a6a848cd'
            'e3591d14f7896bdbefcf48543720c970',
            'file', 1)))
        reqset.add_requirement(next(process_line(
            'TopoRequires==0.0.1 '
            '--hash=sha256:d6dd1e22e60df512fdcf3640ced3039b3b02a56ab2cee81ebcb'
            '3d0a6d4e8bfa6',
            'file', 2)))
开发者ID:oz123,项目名称:pip,代码行数:20,代码来源:test_req.py

示例13: run

    def run(self, options, args):
        options.ignore_installed = True
        # editable doesn't really make sense for `pip download`, but the bowels
        # of the RequirementSet code require that property.
        options.editables = []

        if options.python_version:
            python_versions = [options.python_version]
        else:
            python_versions = None

        dist_restriction_set = any([
            options.python_version,
            options.platform,
            options.abi,
            options.implementation,
        ])
        binary_only = FormatControl(set(), {':all:'})
        no_sdist_dependencies = (
            options.format_control != binary_only and
            not options.ignore_dependencies
        )
        if dist_restriction_set and no_sdist_dependencies:
            raise CommandError(
                "When restricting platform and interpreter constraints using "
                "--python-version, --platform, --abi, or --implementation, "
                "either --no-deps must be set, or --only-binary=:all: must be "
                "set and --no-binary must not be set (or must be set to "
                ":none:)."
            )

        options.src_dir = os.path.abspath(options.src_dir)
        options.download_dir = normalize_path(options.download_dir)

        ensure_dir(options.download_dir)

        with self._build_session(options) as session:
            finder = self._build_package_finder(
                options=options,
                session=session,
                platform=options.platform,
                python_versions=python_versions,
                abi=options.abi,
                implementation=options.implementation,
            )
            build_delete = (not (options.no_clean or options.build_dir))
            if options.cache_dir and not check_path_owner(options.cache_dir):
                logger.warning(
                    "The directory '%s' or its parent directory is not owned "
                    "by the current user and caching wheels has been "
                    "disabled. check the permissions and owner of that "
                    "directory. If executing pip with sudo, you may want "
                    "sudo's -H flag.",
                    options.cache_dir,
                )
                options.cache_dir = None

            with RequirementTracker() as req_tracker, TempDirectory(
                options.build_dir, delete=build_delete, kind="download"
            ) as directory:

                requirement_set = RequirementSet(
                    require_hashes=options.require_hashes,
                )
                self.populate_requirement_set(
                    requirement_set,
                    args,
                    options,
                    finder,
                    session,
                    self.name,
                    None
                )

                preparer = RequirementPreparer(
                    build_dir=directory.path,
                    src_dir=options.src_dir,
                    download_dir=options.download_dir,
                    wheel_download_dir=None,
                    progress_bar=options.progress_bar,
                    build_isolation=options.build_isolation,
                    req_tracker=req_tracker,
                )

                resolver = Resolver(
                    preparer=preparer,
                    finder=finder,
                    session=session,
                    wheel_cache=None,
                    use_user_site=False,
                    upgrade_strategy="to-satisfy-only",
                    force_reinstall=False,
                    ignore_dependencies=options.ignore_dependencies,
                    ignore_requires_python=False,
                    ignore_installed=True,
                    isolated=options.isolated_mode,
                )
                resolver.resolve(requirement_set)

                downloaded = ' '.join([
#.........这里部分代码省略.........
开发者ID:547358880,项目名称:flask-tutorial,代码行数:101,代码来源:download.py

示例14: run

    def run(self, options, args):
        self.check_required_packages()
        cmdoptions.check_install_build_global(options)

        index_urls = [options.index_url] + options.extra_index_urls
        if options.no_index:
            logger.debug('Ignoring indexes: %s', ','.join(index_urls))
            index_urls = []

        if options.build_dir:
            options.build_dir = os.path.abspath(options.build_dir)

        options.src_dir = os.path.abspath(options.src_dir)

        with self._build_session(options) as session:
            finder = self._build_package_finder(options, session)
            build_delete = (not (options.no_clean or options.build_dir))
            wheel_cache = WheelCache(options.cache_dir, options.format_control)

            with TempDirectory(
                options.build_dir, delete=build_delete, kind="wheel"
            ) as directory:
                requirement_set = RequirementSet(
                    require_hashes=options.require_hashes,
                )

                self.populate_requirement_set(
                    requirement_set, args, options, finder, session, self.name,
                    wheel_cache
                )

                preparer = RequirementPreparer(
                    build_dir=directory.path,
                    src_dir=options.src_dir,
                    download_dir=None,
                    wheel_download_dir=options.wheel_dir,
                    progress_bar=options.progress_bar,
                )

                resolver = Resolver(
                    preparer=preparer,
                    finder=finder,
                    session=session,
                    wheel_cache=wheel_cache,
                    use_user_site=False,
                    upgrade_strategy="to-satisfy-only",
                    force_reinstall=False,
                    ignore_dependencies=options.ignore_dependencies,
                    ignore_requires_python=options.ignore_requires_python,
                    ignore_installed=True,
                    isolated=options.isolated_mode,
                )
                resolver.resolve(requirement_set)

                try:
                    # build wheels
                    wb = WheelBuilder(
                        requirement_set,
                        finder,
                        preparer,
                        wheel_cache,
                        build_options=options.build_options or [],
                        global_options=options.global_options or [],
                        no_clean=options.no_clean,
                    )
                    wheels_built_successfully = wb.build(session=session)
                    if not wheels_built_successfully:
                        raise CommandError(
                            "Failed to build one or more wheels"
                        )
                except PreviousBuildDirError:
                    options.no_clean = True
                    raise
                finally:
                    if not options.no_clean:
                        requirement_set.cleanup_files()
开发者ID:aodag,项目名称:pip,代码行数:76,代码来源:wheel.py

示例15: run

    def run(self, options, args):
        cmdoptions.check_install_build_global(options)

        upgrade_strategy = "to-satisfy-only"
        if options.upgrade:
            upgrade_strategy = options.upgrade_strategy

        if options.build_dir:
            options.build_dir = os.path.abspath(options.build_dir)

        options.src_dir = os.path.abspath(options.src_dir)
        install_options = options.install_options or []
        if options.use_user_site:
            if options.prefix_path:
                raise CommandError(
                    "Can not combine '--user' and '--prefix' as they imply "
                    "different installation locations"
                )
            if virtualenv_no_global():
                raise InstallationError(
                    "Can not perform a '--user' install. User site-packages "
                    "are not visible in this virtualenv."
                )
            install_options.append('--user')
            install_options.append('--prefix=')

        target_temp_dir = TempDirectory(kind="target")
        if options.target_dir:
            options.ignore_installed = True
            options.target_dir = os.path.abspath(options.target_dir)
            if (os.path.exists(options.target_dir) and not
                    os.path.isdir(options.target_dir)):
                raise CommandError(
                    "Target path exists but is not a directory, will not "
                    "continue."
                )

            # Create a target directory for using with the target option
            target_temp_dir.create()
            install_options.append('--home=' + target_temp_dir.path)

        global_options = options.global_options or []

        with self._build_session(options) as session:
            finder = self._build_package_finder(options, session)
            build_delete = (not (options.no_clean or options.build_dir))
            wheel_cache = WheelCache(options.cache_dir, options.format_control)

            if options.cache_dir and not check_path_owner(options.cache_dir):
                logger.warning(
                    "The directory '%s' or its parent directory is not owned "
                    "by the current user and caching wheels has been "
                    "disabled. check the permissions and owner of that "
                    "directory. If executing pip with sudo, you may want "
                    "sudo's -H flag.",
                    options.cache_dir,
                )
                options.cache_dir = None

            with TempDirectory(
                options.build_dir, delete=build_delete, kind="install"
            ) as directory:
                requirement_set = RequirementSet(
                    require_hashes=options.require_hashes,
                )

                try:
                    self.populate_requirement_set(
                        requirement_set, args, options, finder, session,
                        self.name, wheel_cache
                    )
                    preparer = RequirementPreparer(
                        build_dir=directory.path,
                        src_dir=options.src_dir,
                        download_dir=None,
                        wheel_download_dir=None,
                        progress_bar=options.progress_bar,
                        build_isolation=options.build_isolation,
                    )

                    resolver = Resolver(
                        preparer=preparer,
                        finder=finder,
                        session=session,
                        wheel_cache=wheel_cache,
                        use_user_site=options.use_user_site,
                        upgrade_strategy=upgrade_strategy,
                        force_reinstall=options.force_reinstall,
                        ignore_dependencies=options.ignore_dependencies,
                        ignore_requires_python=options.ignore_requires_python,
                        ignore_installed=options.ignore_installed,
                        isolated=options.isolated_mode,
                    )
                    resolver.resolve(requirement_set)

                    protect_pip_from_modification_on_windows(
                        modifying_pip=requirement_set.has_requirement("pip")
                    )

                    # If caching is disabled or wheel is not installed don't
#.........这里部分代码省略.........
开发者ID:vtitor,项目名称:pip,代码行数:101,代码来源:install.py


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