Beispiel #1
0
    def build(self,
              ireq: shims.InstallRequirement,
              hashes: Optional[Dict[str, str]] = None) -> str:
        """Build egg_info directory for editable candidates and a wheel for others.

        :param ireq: the InstallRequirment of the candidate.
        :param hashes: a dictionary of filename: hash_value to check against downloaded
        artifacts.
        :returns: The full path of the built artifact.
        """
        from pip._internal.utils.temp_dir import global_tempdir_manager
        from pdm.builders import EditableBuilder
        from pdm.builders import WheelBuilder

        kwargs = self._make_building_args(ireq)
        with self.get_finder() as finder:
            with allow_all_wheels():
                # temporarily allow all wheels to get a link.
                ireq.populate_link(finder, False, bool(hashes))
            if not ireq.editable and not ireq.req.name:
                ireq.source_dir = kwargs["build_dir"]
            else:
                ireq.ensure_has_source_dir(kwargs["build_dir"])

            download_dir = kwargs["download_dir"]
            only_download = False
            if ireq.link.is_wheel:
                download_dir = kwargs["wheel_download_dir"]
                only_download = True
            if hashes:
                ireq.options["hashes"] = convert_hashes(hashes)
            if not (ireq.editable and ireq.req.is_local_dir):
                with global_tempdir_manager():
                    downloaded = shims.shim_unpack(
                        link=ireq.link,
                        download_dir=download_dir,
                        location=ireq.source_dir,
                        hashes=ireq.hashes(False),
                        only_download=only_download,
                        session=finder.session,
                    )
                    # Preserve the downloaded file so that it won't be cleared.
                    if downloaded and only_download:
                        try:
                            shutil.copy(downloaded, download_dir)
                        except shutil.SameFileError:
                            pass
            # Now all source is prepared, build it.
            if ireq.link.is_wheel:
                return (context.cache("wheels") /
                        ireq.link.filename).as_posix()
            builder_class = EditableBuilder if ireq.editable else WheelBuilder
            kwargs["finder"] = finder
            with builder_class(ireq) as builder:
                return builder.build(**kwargs)
Beispiel #2
0
    def build(
        self,
        ireq: shims.InstallRequirement,
        hashes: Optional[Dict[str, str]] = None,
        allow_all: bool = True,
    ) -> str:
        """Build egg_info directory for editable candidates and a wheel for others.

        :param ireq: the InstallRequirment of the candidate.
        :param hashes: a dictionary of filename: hash_value to check against downloaded
        artifacts.
        :param allow_all: Allow building incompatible wheels.
        :returns: The full path of the built artifact.
        """
        from pdm.builders import EditableBuilder, WheelBuilder

        kwargs = self._make_building_args(ireq)
        with self.get_finder() as finder:
            if allow_all:
                with allow_all_wheels():
                    # temporarily allow all wheels to get a link.
                    populate_link(finder, ireq, False)
            else:
                populate_link(finder, ireq, False)
            if not ireq.editable and not ireq.req.name:
                ireq.source_dir = kwargs["build_dir"]
            else:
                ireq.ensure_has_source_dir(kwargs["build_dir"])

            download_dir = kwargs["download_dir"]
            only_download = False
            if ireq.link.is_wheel:
                download_dir = kwargs["wheel_download_dir"]
                only_download = True
            if hashes:
                ireq.hash_options = convert_hashes(hashes)
            if not (ireq.editable and ireq.req.is_local_dir):
                downloader = shims.Downloader(finder.session, "off")
                downloaded = shims.unpack_url(
                    ireq.link,
                    ireq.source_dir,
                    downloader,
                    download_dir,
                    ireq.hashes(False),
                )
                # Preserve the downloaded file so that it won't be cleared.
                if downloaded and only_download:
                    try:
                        shutil.copy(downloaded.path, download_dir)
                    except shutil.SameFileError:
                        pass
            # Now all source is prepared, build it.
            if ireq.link.is_wheel:
                return (self.project.cache("wheels") /
                        ireq.link.filename).as_posix()
            self.ensure_essential_packages()
            if ireq.editable:
                builder_class = EditableBuilder
            else:
                builder_class = WheelBuilder
            kwargs["finder"] = finder
            with builder_class(ireq) as builder, self.activate(True):
                return builder.build(**kwargs)