Skip to content
Open
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
9 changes: 8 additions & 1 deletion patch_python_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def patch_file(file_path: str, patched_tree: ast.AST) -> None:
setup_source = f.read()
setup_tree = ast.parse(setup_source)

# Check if driver URL is found in upstream Playwright
upstream_driver_url_found = False

for node in ast.walk(setup_tree):
# Modify driver_version
if isinstance(node, ast.Assign) and isinstance(node.value, ast.Constant) and isinstance(node.targets[0], ast.Name):
Expand All @@ -50,7 +53,8 @@ def patch_file(file_path: str, patched_tree: ast.AST) -> None:

# Modify url
if isinstance(node, ast.Assign) and isinstance(node.value, ast.Constant) and isinstance(node.targets[0], ast.Name):
if node.targets[0].id == "url" and node.value.value == "https://playwright.azureedge.net/builds/driver/":
if node.targets[0].id == "url" and node.value.value == "https://cdn.playwright.dev/builds/driver/":
upstream_driver_url_found = True
node.value = ast.JoinedStr(
values=[
ast.Constant(value='https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/releases/download/v'),
Expand Down Expand Up @@ -97,6 +101,9 @@ def patch_file(file_path: str, patched_tree: ast.AST) -> None:
value=ast.Constant(value=patchright_version)
))

if not upstream_driver_url_found:
raise RuntimeError(f"Upstream Playwright CDN URL is not found in playwright-python/setup.py")

patch_file("playwright-python/setup.py", setup_tree)

# Patching playwright/_impl/__pyinstaller/hook-playwright.async_api.py
Expand Down
Loading