Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions pkgs/development/python-modules/playwright/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ in
buildPythonPackage rec {
pname = "playwright";
# run ./pkgs/development/python-modules/playwright/update.sh to update
version = "1.44.0";
version = "1.46.0";
pyproject = true;
disabled = pythonOlder "3.7";

src = fetchFromGitHub {
owner = "microsoft";
repo = "playwright-python";
rev = "refs/tags/v${version}";
hash = "sha256-RM04I1QiyJhPvKdAdy8w2GmOOR+BWilxrZ5QUrwxBWA=";
hash = "sha256-88ZFhP8Bd10czoW71ltelWStypX4z4g18LT3Zo5ACMg=";
};

patches = [
Expand All @@ -51,11 +51,11 @@ buildPythonPackage rec {
git commit -m "workaround setuptools-scm"

substituteInPlace setup.py \
--replace "setuptools-scm==8.0.4" "setuptools-scm" \
--replace "setuptools-scm==8.1.0" "setuptools-scm" \
--replace-fail "wheel==0.42.0" "wheel"

substituteInPlace pyproject.toml \
--replace 'requires = ["setuptools==68.2.2", "setuptools-scm==8.0.4", "wheel==0.42.0", "auditwheel==5.4.0"]' \
--replace 'requires = ["setuptools==68.2.2", "setuptools-scm==8.1.0", "wheel==0.42.0", "auditwheel==5.4.0"]' \
'requires = ["setuptools", "setuptools-scm", "wheel"]'

# Skip trying to download and extract the driver.
Expand Down
19 changes: 11 additions & 8 deletions pkgs/development/python-modules/playwright/driver-location.patch
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
diff --git a/playwright/_impl/_driver.py b/playwright/_impl/_driver.py
index 9e8cdc1..7ee382d 100644
index 22b53b8..2d86626 100644
--- a/playwright/_impl/_driver.py
+++ b/playwright/_impl/_driver.py
@@ -23,11 +23,7 @@ from playwright._repo_version import version
@@ -23,14 +23,7 @@ from playwright._repo_version import version


def compute_driver_executable() -> Tuple[str, str]:
- driver_path = Path(inspect.getfile(playwright)).parent / "driver"
- cli_path = str(driver_path / "package" / "cli.js")
- if sys.platform == "win32":
- return (str(driver_path / "node.exe"), cli_path)
- return (
- os.getenv("PLAYWRIGHT_NODEJS_PATH", str(driver_path / "node.exe")),
- cli_path,
- )
- return (os.getenv("PLAYWRIGHT_NODEJS_PATH", str(driver_path / "node")), cli_path)
+ return "@node@", "@driver@"
+ return "@node@", "@driver@"


def get_driver_env() -> dict:
diff --git a/setup.py b/setup.py
index 8709e52..59784dd 100644
Expand Down
59 changes: 39 additions & 20 deletions pkgs/development/python-modules/playwright/update.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl gnused nix-prefetch common-updater-scripts node2nix jq
#!nix-shell -i bash -p curl gnused common-updater-scripts jq prefetch-npm-deps
set -euo pipefail

root="$(dirname "$(readlink -f "$0")")"
driver_file="$root/../../web/playwright/driver.nix"
playwright_test="$root/../../web/playwright-test"

version=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} -s https://api.github.com/repos/microsoft/playwright-python/releases/latest | jq -r '.tag_name | sub("^v"; "")')

# Most of the time, this should be the latest stable release of the Node-based
# Playwright version, but that isn't a guarantee, so this needs to be specified
# as well:
setup_py_url="https://github.com/microsoft/playwright-python/raw/v${version}/setup.py"
driver_version=$(curl -Ls "$setup_py_url" | grep '^driver_version =' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')

fetch_driver_arch() {
nix-prefetch-url "https://playwright.azureedge.net/builds/driver/playwright-${driver_version}-${1}.zip"
}
update-source-version playwright-driver "$driver_version"
update-source-version python3Packages.playwright "$version"

# Update package-lock.json files for all npm deps that are built in playwright
# TODO: skip if update-source-version reported the same version
Copy link
Member

Choose a reason for hiding this comment

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

That's not checked yet, I believe?

driver_file="$root/../../web/playwright/driver.nix"
repo_url_prefix="https://github.com/microsoft/playwright/raw"
temp_dir=$(mktemp -d)

trap 'rm -rf "$temp_dir"' EXIT


replace_sha() {
sed -i "s|$1 = \".\{44,52\}\"|$1 = \"$2\"|" "$driver_file"
# Function to download `package-lock.json` for a given source path and update hash
update_hash() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
update_hash() {
update_npm_hash() {

or something like this? Just to show that it's about npm/nodejs packages here, we are in ./pkgs/development/python-modules here.

local source_root_path="$1"
local existing_hash="$2"

# Formulate download URL
local download_url="${repo_url_prefix}/v${driver_version}${source_root_path}/package-lock.json"

# Download package-lock.json to temporary directory
curl -fsSL -o "${temp_dir}/package-lock.json" "$download_url"

# Calculate the new hash
local new_hash
new_hash=$(prefetch-npm-deps "${temp_dir}/package-lock.json")

# Update npmDepsHash in the original file
sed -i "s|$existing_hash|${new_hash}|" "$driver_file"
}

# Replace SHAs for the driver downloads
replace_sha "x86_64-linux" "$(fetch_driver_arch "linux")"
replace_sha "x86_64-darwin" "$(fetch_driver_arch "mac")"
replace_sha "aarch64-linux" "$(fetch_driver_arch "linux-arm64")"
replace_sha "aarch64-darwin" "$(fetch_driver_arch "mac-arm64")"

# Update the version stamps
sed -i "s/version =\s*\"[^\$]*\"/version = \"$driver_version\"/" "$driver_file"
sed -i "s/\"@playwright\/test\": \"[^\$]*\"/\"@playwright\/test\": \"$driver_version\"/" "$playwright_test/node-packages.json"
(cd "$playwright_test"; node2nix -i node-packages.json)
update-source-version playwright "$version" --rev="v$version"
while IFS= read -r source_root_line; do
[[ "$source_root_line" =~ sourceRoot ]] || continue
source_root_path=$(echo "$source_root_line" | sed -e 's/^.*"${src.name}\(.*\)";.*$/\1/')

# Extract the current npmDepsHash for this sourceRoot
existing_hash=$(grep -A1 "$source_root_line" "$driver_file" | grep 'npmDepsHash' | sed -e 's/^.*npmDepsHash = "\(.*\)";$/\1/')

# Call the function to download and update the hash
update_hash "$source_root_path" "$existing_hash"
done < "$driver_file"
17 changes: 0 additions & 17 deletions pkgs/development/web/playwright-test/default.nix

This file was deleted.

Loading