1{ lib 2, buildPythonPackage 3, git 4, greenlet 5, fetchFromGitHub 6, pyee 7, python 8, pythonOlder 9, setuptools-scm 10, playwright-driver 11}: 12 13let 14 driver = playwright-driver; 15in 16buildPythonPackage rec { 17 pname = "playwright"; 18 # run ./pkgs/development/python-modules/playwright/update.sh to update 19 version = "1.38.0"; 20 format = "setuptools"; 21 disabled = pythonOlder "3.7"; 22 23 src = fetchFromGitHub { 24 owner = "microsoft"; 25 repo = "playwright-python"; 26 rev = "refs/tags/v${version}"; 27 hash = "sha256-K3ZLDnDtV9PWX0etVv6RIDHp0vZZ7b7DGJ1GjP2kfXU="; 28 }; 29 30 patches = [ 31 # This patches two things: 32 # - The driver location, which is now a static package in the Nix store. 33 # - The setup script, which would try to download the driver package from 34 # a CDN and patch wheels so that they include it. We don't want this 35 # we have our own driver build. 36 ./driver-location.patch 37 ]; 38 39 postPatch = '' 40 # if setuptools_scm is not listing files via git almost all python files are excluded 41 export HOME=$(mktemp -d) 42 git init . 43 git add -A . 44 git config --global user.email "nixpkgs" 45 git config --global user.name "nixpkgs" 46 git commit -m "workaround setuptools-scm" 47 48 substituteInPlace setup.py \ 49 --replace "greenlet==2.0.1" "greenlet>=2.0.1" \ 50 --replace "pyee==8.1.0" "pyee>=8.1.0" \ 51 --replace "setuptools-scm==7.0.5" "setuptools-scm>=7.0.5" \ 52 --replace "wheel==0.38.1" "wheel>=0.37.1" 53 54 # Skip trying to download and extract the driver. 55 # This is done manually in postInstall instead. 56 substituteInPlace setup.py \ 57 --replace "self._download_and_extract_local_driver(base_wheel_bundles)" "" 58 59 # Set the correct driver path with the help of a patch in patches 60 substituteInPlace playwright/_impl/_driver.py \ 61 --replace "@driver@" "${driver}/bin/playwright" 62 ''; 63 64 65 nativeBuildInputs = [ git setuptools-scm ]; 66 67 propagatedBuildInputs = [ 68 greenlet 69 pyee 70 ]; 71 72 postInstall = '' 73 ln -s ${driver} $out/${python.sitePackages}/playwright/driver 74 ''; 75 76 SETUPTOOLS_SCM_PRETEND_VERSION = version; 77 78 # Skip tests because they require network access. 79 doCheck = false; 80 81 pythonImportsCheck = [ 82 "playwright" 83 ]; 84 85 passthru = { 86 inherit driver; 87 tests = { 88 driver = playwright-driver; 89 browsers = playwright-driver.browsers; 90 }; 91 updateScript = ./update.sh; 92 }; 93 94 meta = with lib; { 95 description = "Python version of the Playwright testing and automation library"; 96 homepage = "https://github.com/microsoft/playwright-python"; 97 license = licenses.asl20; 98 maintainers = with maintainers; [ techknowlogick yrd ]; 99 platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; 100 }; 101}