(
self,
wheel_bundle: Dict[str, str],
)
| 147 | self._build_wheel(wheel) |
| 148 | |
| 149 | def _build_wheel( |
| 150 | self, |
| 151 | wheel_bundle: Dict[str, str], |
| 152 | ) -> None: |
| 153 | assert self.dist_dir |
| 154 | base_wheel_location: str = glob.glob(os.path.join(self.dist_dir, "*.whl"))[0] |
| 155 | without_platform = base_wheel_location[:-7] |
| 156 | ensure_driver_bundle(wheel_bundle["zip_name"]) |
| 157 | # Although the build produces every platform's bundle, only this wheel's |
| 158 | # target platform driver is extracted and packed below, so the wheel |
| 159 | # stays single-platform. |
| 160 | zip_file = f"driver/playwright-{driver_version}-{wheel_bundle['zip_name']}.zip" |
| 161 | extract_dir = f"driver/{wheel_bundle['zip_name']}" |
| 162 | if os.path.exists(extract_dir): |
| 163 | shutil.rmtree(extract_dir) |
| 164 | with zipfile.ZipFile(zip_file, "r") as zip: |
| 165 | extractall(zip, extract_dir) |
| 166 | wheel_location = without_platform + wheel_bundle["wheel"] |
| 167 | shutil.copy(base_wheel_location, wheel_location) |
| 168 | with zipfile.ZipFile( |
| 169 | wheel_location, mode="a", compression=zipfile.ZIP_DEFLATED |
| 170 | ) as zip: |
| 171 | driver_root = os.path.abspath(f"driver/{wheel_bundle['zip_name']}") |
| 172 | for dir_path, _, files in os.walk(driver_root): |
| 173 | for file in files: |
| 174 | from_path = os.path.join(dir_path, file) |
| 175 | to_path = os.path.relpath(from_path, driver_root) |
| 176 | zip.write(from_path, f"playwright/driver/{to_path}") |
| 177 | zip.writestr( |
| 178 | "playwright/driver/README.md", |
| 179 | f"{wheel_bundle['wheel']} driver package", |
| 180 | ) |
| 181 | os.remove(base_wheel_location) |
| 182 | for whlfile in glob.glob(os.path.join(self.dist_dir, "*.whl")): |
| 183 | os.makedirs("wheelhouse", exist_ok=True) |
| 184 | if InWheel: |
| 185 | wheelhouse_whl = os.path.join("wheelhouse", os.path.basename(whlfile)) |
| 186 | shutil.move(whlfile, wheelhouse_whl) |
| 187 | with InWheel(in_wheel=Path(wheelhouse_whl), out_wheel=Path(whlfile)): |
| 188 | print(f"Updating RECORD file of {whlfile}") |
| 189 | print("Copying new wheels") |
| 190 | shutil.rmtree("wheelhouse") |
| 191 | |
| 192 | def _download_and_extract_local_driver( |
| 193 | self, |
no test coverage detected