Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,19 @@ def run(self) -> None:
super().run()
os.makedirs("driver", exist_ok=True)
os.makedirs("playwright/driver", exist_ok=True)
platform_map = {

platform_to_driver_map = {
"darwin": "mac",
"linux": "linux",
"win32": "win32_x64" if sys.maxsize > 2 ** 32 else "win32",
"win32": "win32",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ends up using the wrong 32 bit variant of Node.js which is 404 when we roll. See here: https://github.com/microsoft/playwright/blob/82dd7c87ad44cd2c71358c455ba8ee7532b7ab72/utils/build/build-playwright-driver.sh#L75

}
# 1. Download necessary zip files
if self.all:
platforms = ["mac", "linux", "win32", "win32_x64"]
drivers = ["mac", "linux", "win32"]
else:
platforms = [platform_map[sys.platform]]
for platform in platforms:
zip_file = f"playwright-{driver_version}-{platform}.zip"
drivers = [platform_to_driver_map[sys.platform]]
for driver in drivers:
zip_file = f"playwright-{driver_version}-{driver}.zip"
if not os.path.exists("driver/" + zip_file):
url = "https://playwright.azureedge.net/builds/driver/"
url = url + "next/"
Expand All @@ -81,36 +83,34 @@ def run(self) -> None:
base_wheel_location = glob.glob(os.path.join(self.dist_dir, "*.whl"))[0]
without_platform = base_wheel_location[:-7]

for platform in platforms:
zip_file = f"driver/playwright-{driver_version}-{platform}.zip"
# 2. Bake wheels.
wheel_to_driver_map = {
"macosx_10_13_x86_64.whl": "mac",
"macosx_11_0_universal2.whl": "mac",
"manylinux1_x86_64.whl": "linux",
"win32.whl": "win32",
"win_amd64.whl": "win32",
}
if self.all:
wheels = wheel_to_driver_map.keys()
else:
wheels = []
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems by default not creating any wheels, we need to create the sys.platform wheels by default. For local installation and conda builds.

for wheel in wheels:
driver = wheel_to_driver_map[wheel]
zip_file = f"driver/playwright-{driver_version}-{driver}.zip"
with zipfile.ZipFile(zip_file, "r") as zip:
extractall(zip, f"driver/{platform}")
if platform_map[sys.platform] == platform:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropping this would also break the local installations I think.

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"
extractall(zip, f"driver/{driver}")
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}")
driver_root = os.path.abspath(f"driver/{driver}")
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" and self.all:
# 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:
if wheel == "macosx_11_0_universal2.whl":
# Make sure Mac wheels differ.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why make sure the wheels differ?

zip.writestr("playwright/driver/README.md", "Universal Mac package")

os.remove(base_wheel_location)
Expand Down