at master 3.1 kB view raw
1{ 2 lib, 3 stdenv, 4 auditwheel, 5 buildPythonPackage, 6 gitMinimal, 7 greenlet, 8 fetchFromGitHub, 9 pyee, 10 python, 11 pythonOlder, 12 setuptools, 13 setuptools-scm, 14 playwright-driver, 15 nixosTests, 16 nodejs, 17}: 18 19let 20 driver = playwright-driver; 21in 22buildPythonPackage rec { 23 pname = "playwright"; 24 # run ./pkgs/development/python-modules/playwright/update.sh to update 25 version = "1.54.0"; 26 pyproject = true; 27 disabled = pythonOlder "3.9"; 28 29 src = fetchFromGitHub { 30 owner = "microsoft"; 31 repo = "playwright-python"; 32 tag = "v${version}"; 33 hash = "sha256-xyuofDL0hWL8Gn4sYNLKte8q/4bMo+3aSbYaf5iWiBk="; 34 }; 35 36 patches = [ 37 # This patches two things: 38 # - The driver location, which is now a static package in the Nix store. 39 # - The setup script, which would try to download the driver package from 40 # a CDN and patch wheels so that they include it. We don't want this 41 # we have our own driver build. 42 ./driver-location.patch 43 ]; 44 45 postPatch = '' 46 # if setuptools_scm is not listing files via git almost all python files are excluded 47 export HOME=$(mktemp -d) 48 git init . 49 git add -A . 50 git config --global user.email "nixpkgs" 51 git config --global user.name "nixpkgs" 52 git commit -m "workaround setuptools-scm" 53 54 sed -i -e 's/requires = \["setuptools==.*", "setuptools-scm==.*", "wheel==.*", "auditwheel==.*"\]/requires = ["setuptools", "setuptools-scm", "wheel"]/' pyproject.toml 55 56 # setup.py downloads and extracts the driver. 57 # This is done manually in postInstall instead. 58 rm setup.py 59 60 # Set the correct driver path with the help of a patch in patches 61 substituteInPlace playwright/_impl/_driver.py \ 62 --replace-fail "@node@" "${lib.getExe nodejs}" \ 63 --replace-fail "@driver@" "${driver}/cli.js" 64 ''; 65 66 nativeBuildInputs = [ 67 gitMinimal 68 setuptools-scm 69 setuptools 70 ] 71 ++ lib.optionals stdenv.hostPlatform.isLinux [ auditwheel ]; 72 73 pythonRelaxDeps = [ 74 "greenlet" 75 "pyee" 76 ]; 77 78 propagatedBuildInputs = [ 79 greenlet 80 pyee 81 ]; 82 83 postInstall = '' 84 ln -s ${driver} $out/${python.sitePackages}/playwright/driver 85 ''; 86 87 # Skip tests because they require network access. 88 doCheck = false; 89 90 pythonImportsCheck = [ "playwright" ]; 91 92 passthru = { 93 inherit driver; 94 tests = { 95 driver = playwright-driver; 96 browsers = playwright-driver.browsers; 97 } 98 // lib.optionalAttrs stdenv.hostPlatform.isLinux { 99 inherit (nixosTests) playwright-python; 100 }; 101 # Package and playwright driver versions are tightly coupled. 102 # Use the update script to ensure synchronized updates. 103 skipBulkUpdate = true; 104 updateScript = ./update.sh; 105 }; 106 107 meta = with lib; { 108 description = "Python version of the Playwright testing and automation library"; 109 mainProgram = "playwright"; 110 homepage = "https://github.com/microsoft/playwright-python"; 111 license = licenses.asl20; 112 maintainers = with maintainers; [ 113 techknowlogick 114 yrd 115 ]; 116 platforms = [ 117 "x86_64-linux" 118 "aarch64-linux" 119 "x86_64-darwin" 120 "aarch64-darwin" 121 ]; 122 }; 123}