Example #1
0
def only_binary():
    return Option(
        "--only-binary",
        dest="format_control",
        action="callback",
        callback=_handle_only_binary,
        type="str",
        default=FormatControl(set(), set()),
        help="Do not use source packages. Can be supplied multiple times, and "
        "each time adds to the existing value. Accepts either :all: to "
        "disable all source packages, :none: to empty the set, or one or "
        "more package names with commas between them. Packages without "
        "binary distributions will fail to install when this option is "
        "used on them.")
Example #2
0
def no_binary():
    return Option(
        "--no-binary",
        dest="format_control",
        action="callback",
        callback=_handle_no_binary,
        type="str",
        default=FormatControl(set(), set()),
        help="Do not use binary packages. Can be supplied multiple times, and "
        "each time adds to the existing value. Accepts either :all: to "
        "disable all binary packages, :none: to empty the set, or one or "
        "more package names with commas between them. Note that some "
        "packages are tricky to compile and may fail to install when "
        "this option is used on them.")
Example #3
0
def writer():
    return OutputWriter(src_files=["src_file", "src_file2"],
                        dst_file="dst_file",
                        dry_run=True,
                        emit_header=True,
                        emit_index=True,
                        emit_trusted_host=True,
                        annotate=True,
                        generate_hashes=False,
                        default_index_url=None,
                        index_urls=[],
                        trusted_hosts=[],
                        find_links=[],
                        format_control=FormatControl(set(), set()))
Example #4
0
    def _install_build_reqs(self, reqs, prefix):
        # Local import to avoid circular import (wheel <-> req_install)
        from pip.req.req_install import InstallRequirement
        from pip.index import FormatControl
        # Ignore the --no-binary option when installing the build system, so
        # we don't recurse trying to build a self-hosting build system.
        finder = copy.copy(self.finder)
        finder.format_control = FormatControl(set(), set())
        urls = [finder.find_requirement(InstallRequirement.from_line(r),
                                        upgrade=False).url
                for r in reqs]

        args = [sys.executable, '-m', 'pip', 'install', '--ignore-installed',
                '--prefix', prefix] + list(urls)
        with open_spinner("Installing build dependencies") as spinner:
            call_subprocess(args, show_stdout=False, spinner=spinner)
    def run(self, options, args):
        options.ignore_installed = True

        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(), set([':all:']))
        if dist_restriction_set and options.format_control != binary_only:
            raise CommandError(
                "--only-binary=:all: must be set and --no-binary must not "
                "be set (or must be set to :none:) when restricting platform "
                "and interpreter constraints using --python-version, "
                "--platform, --abi, or --implementation."
            )

        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 BuildDirectory(options.build_dir,
                                delete=build_delete) as build_dir:

                requirement_set = RequirementSet(
                    build_dir=build_dir,
                    src_dir=options.src_dir,
                    download_dir=options.download_dir,
                    ignore_installed=True,
                    ignore_dependencies=options.ignore_dependencies,
                    session=session,
                    isolated=options.isolated_mode,
                    require_hashes=options.require_hashes
                )
                self.populate_requirement_set(
                    requirement_set,
                    args,
                    options,
                    finder,
                    session,
                    self.name,
                    None
                )

                if not requirement_set.has_requirements:
                    return

                requirement_set.prepare_files(finder)

                downloaded = ' '.join([
                    req.name for req in requirement_set.successfully_downloaded
                ])
                if downloaded:
                    logger.info(
                        'Successfully downloaded %s', downloaded
                    )

                # Clean up
                if not options.no_clean:
                    requirement_set.cleanup_files()

        return requirement_set
Example #6
0
    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:'})
        if dist_restriction_set and options.format_control != binary_only:
            raise CommandError(
                "--only-binary=:all: must be set and --no-binary must not "
                "be set (or must be set to :none:) when restricting platform "
                "and interpreter constraints using --python-version, "
                "--platform, --abi, or --implementation."
            )

        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 TempDirectory(
                options.build_dir, delete=build_delete, kind="download"
            ) as directory:

                requirement_set = RequirementSet(
                    build_dir=directory.path,
                    src_dir=options.src_dir,
                    download_dir=options.download_dir,
                    require_hashes=options.require_hashes,
                    progress_bar=options.progress_bar,
                )
                self.populate_requirement_set(
                    requirement_set,
                    args,
                    options,
                    finder,
                    session,
                    self.name,
                    None
                )

                resolver = Resolver(
                    preparer=RequirementPreparer(),
                    finder=finder,
                    session=session,
                    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([
                    req.name for req in requirement_set.successfully_downloaded
                ])
                if downloaded:
                    logger.info(
                        'Successfully downloaded %s', downloaded
                    )

                # Clean up
                if not options.no_clean:
                    requirement_set.cleanup_files()

        return requirement_set