Пример #1
0
 def _build_wheels(
     self,
     wheels: List[Dict[str, str]],
 ) -> None:
     base_wheel_location: str = glob.glob(
         os.path.join(self.dist_dir, "*.whl"))[0]
     without_platform = base_wheel_location[:-7]
     for wheel_bundle in wheels:
         download_driver(wheel_bundle["zip_name"])
         zip_file = (
             f"driver/playwright-{driver_version}-{wheel_bundle['zip_name']}.zip"
         )
         with zipfile.ZipFile(zip_file, "r") as zip:
             extractall(zip, f"driver/{wheel_bundle['zip_name']}")
         wheel_location = without_platform + wheel_bundle["wheel"]
         shutil.copy(base_wheel_location, wheel_location)
         with zipfile.ZipFile(wheel_location, "a") as zip:
             driver_root = os.path.abspath(
                 f"driver/{wheel_bundle['zip_name']}")
             for dir_path, _, files in os.walk(driver_root):
                 for file in files:
                     from_path = os.path.join(dir_path, file)
                     to_path = os.path.relpath(from_path, driver_root)
                     zip.write(from_path, f"playwright/driver/{to_path}")
             zip.writestr(
                 "playwright/driver/README.md",
                 f"{wheel_bundle['wheel']} driver package",
             )
     os.remove(base_wheel_location)
     if InWheel:
         for whlfile in glob.glob(os.path.join(self.dist_dir, "*.whl")):
             os.makedirs("wheelhouse", exist_ok=True)
             with InWheel(
                     in_wheel=whlfile,
                     out_wheel=os.path.join("wheelhouse",
                                            os.path.basename(whlfile)),
             ):
                 print(f"Updating RECORD file of {whlfile}")
         shutil.rmtree(self.dist_dir)
         print("Copying new wheels")
         shutil.move("wheelhouse", self.dist_dir)
     else:
         print("auditwheel not installed, not updating RECORD file")
Пример #2
0
    def run(self) -> None:
        if os.path.exists("build"):
            shutil.rmtree("build")
        if os.path.exists("dist"):
            shutil.rmtree("dist")
        if os.path.exists("playwright.egg-info"):
            shutil.rmtree("playwright.egg-info")
        super().run()
        os.makedirs("driver", exist_ok=True)
        os.makedirs("playwright/driver", exist_ok=True)
        for platform in ["mac", "linux", "win32", "win32_x64"]:
            zip_file = f"playwright-{driver_version}-{platform}.zip"
            if not os.path.exists("driver/" + zip_file):
                url = "https://playwright.azureedge.net/builds/driver/"
                url = url + "next/"
                url = url + zip_file
                print("Fetching ", url)
                # Don't replace this with urllib - Python won't have certificates to do SSL on all platforms.
                subprocess.check_call(
                    ["curl", url, "-o", "driver/" + zip_file])
        base_wheel_location = glob.glob("dist/*.whl")[0]
        without_platform = base_wheel_location[:-7]
        platform_map = {
            "darwin": "mac",
            "linux": "linux",
            "win32": "win32_x64" if sys.maxsize > 2**32 else "win32",
        }
        for platform in ["mac", "linux", "win32", "win32_x64"]:
            zip_file = f"driver/playwright-{driver_version}-{platform}.zip"
            with zipfile.ZipFile(zip_file, "r") as zip:
                extractall(zip, f"driver/{platform}")
            if platform_map[sys.platform] == platform:
                with zipfile.ZipFile(zip_file, "r") as zip:
                    extractall(zip, "playwright/driver")
            wheel = ""
            if platform == "mac":
                wheel = "macosx_10_13_x86_64.whl"
            if platform == "linux":
                wheel = "manylinux1_x86_64.whl"
            if platform == "win32":
                wheel = "win32.whl"
            if platform == "win32_x64":
                wheel = "win_amd64.whl"
            wheel_location = without_platform + wheel
            shutil.copy(base_wheel_location, wheel_location)
            with zipfile.ZipFile(wheel_location, "a") as zip:
                driver_root = os.path.abspath(f"driver/{platform}")
                for dir_path, _, files in os.walk(driver_root):
                    for file in files:
                        from_path = os.path.join(dir_path, file)
                        to_path = os.path.relpath(from_path, driver_root)
                        zip.write(from_path, f"playwright/driver/{to_path}")
            if platform == "mac":
                # Ship mac both as 10_13 as and 11_0 universal to work across Macs.
                universal_location = without_platform + "macosx_11_0_universal2.whl"
                shutil.copyfile(wheel_location, universal_location)
                with zipfile.ZipFile(universal_location, "a") as zip:
                    zip.writestr("playwright/driver/README.md",
                                 "Universal Mac package")

        os.remove(base_wheel_location)
        for whlfile in glob.glob("dist/*.whl"):

            os.makedirs("wheelhouse", exist_ok=True)
            with InWheel(
                    in_wheel=whlfile,
                    out_wheel=os.path.join("wheelhouse",
                                           os.path.basename(whlfile)),
                    ret_self=True,
            ):
                print("Updating RECORD file of %s" % whlfile)
        shutil.rmtree("dist")
        print("Copying new wheels")
        shutil.move("wheelhouse", "dist")
Пример #3
0
    def run(self) -> None:
        shutil.rmtree("build", ignore_errors=True)
        shutil.rmtree("dist", ignore_errors=True)
        shutil.rmtree("playwright.egg-info", ignore_errors=True)
        super().run()
        os.makedirs("driver", exist_ok=True)
        os.makedirs("playwright/driver", exist_ok=True)
        if self.all:
            # If building for all platforms
            platform_map = {
                "darwin": [
                    {
                        "zip_name":
                        "mac",
                        "wheels": [
                            "macosx_10_13_x86_64.whl",
                            "macosx_11_0_universal2.whl",
                        ],
                    },
                    {
                        "zip_name": "mac-arm64",
                        "wheels": [
                            "macosx_11_0_arm64.whl",
                        ],
                    },
                ],
                "linux": [
                    {
                        "zip_name": "linux",
                        "wheels": ["manylinux1_x86_64.whl"]
                    },
                    {
                        "zip_name":
                        "linux-arm64",
                        "wheels":
                        ["manylinux_2_17_aarch64.manylinux2014_aarch64.whl"],
                    },
                ],
                "win32": [{
                    "zip_name": "win32_x64",
                    "wheels": ["win32.whl", "win_amd64.whl"],
                }],
            }
            platforms = [*platform_map.values()]
        else:
            # If building for only current platform
            platform_map = {
                "darwin": [
                    {
                        "zip_name": "mac",
                        "wheels": ["macosx_10_13_x86_64.whl"],
                    },
                ],
                "linux": [{
                    "zip_name": "linux",
                    "wheels": ["manylinux1_x86_64.whl"]
                }],
                "win32": [{
                    "zip_name": "win32_x64",
                    "wheels": ["win_amd64.whl"],
                }],
            }
            platforms = [platform_map[sys.platform]]
        for platform in platforms:
            for arch in platform:
                zip_file = f"playwright-{driver_version}-{arch['zip_name']}.zip"
                if not os.path.exists("driver/" + zip_file):
                    url = f"https://playwright.azureedge.net/builds/driver/next/{zip_file}"
                    print(f"Fetching {url}")
                    # Don't replace this with urllib - Python won't have certificates to do SSL on all platforms.
                    subprocess.check_call(
                        ["curl", url, "-o", "driver/" + zip_file])
        base_wheel_location = glob.glob(os.path.join(self.dist_dir,
                                                     "*.whl"))[0]
        without_platform = base_wheel_location[:-7]

        for platform in platforms:
            for arch in platform:
                zip_file = f"driver/playwright-{driver_version}-{arch['zip_name']}.zip"
                with zipfile.ZipFile(zip_file, "r") as zip:
                    extractall(zip, f"driver/{arch['zip_name']}")
                if platform_map[sys.platform][0] in platform:
                    with zipfile.ZipFile(zip_file, "r") as zip:
                        extractall(zip, "playwright/driver")
                for wheel in arch["wheels"]:
                    wheel_location = without_platform + wheel
                    shutil.copy(base_wheel_location, wheel_location)
                    with zipfile.ZipFile(wheel_location, "a") as zip:
                        driver_root = os.path.abspath(
                            f"driver/{arch['zip_name']}")
                        for dir_path, _, files in os.walk(driver_root):
                            for file in files:
                                from_path = os.path.join(dir_path, file)
                                to_path = os.path.relpath(
                                    from_path, driver_root)
                                zip.write(from_path,
                                          f"playwright/driver/{to_path}")
                        zip.writestr("playwright/driver/README.md",
                                     f"{wheel} driver package")

        os.remove(base_wheel_location)
        if InWheel:
            for whlfile in glob.glob(os.path.join(self.dist_dir, "*.whl")):
                os.makedirs("wheelhouse", exist_ok=True)
                with InWheel(
                        in_wheel=whlfile,
                        out_wheel=os.path.join("wheelhouse",
                                               os.path.basename(whlfile)),
                ):
                    print(f"Updating RECORD file of {whlfile}")
            shutil.rmtree(self.dist_dir)
            print("Copying new wheels")
            shutil.move("wheelhouse", self.dist_dir)
        else:
            print("auditwheel not installed, not updating RECORD file")