1{
2 lib,
3 stdenv,
4 auditwheel,
5 buildPythonPackage,
6 git,
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.47.0";
26 pyproject = true;
27 disabled = pythonOlder "3.7";
28
29 src = fetchFromGitHub {
30 owner = "microsoft";
31 repo = "playwright-python";
32 rev = "refs/tags/v${version}";
33 hash = "sha256-C/spH54hhLI0Egs2jjTjQ5BH1pIw1syrfSyUvVQRoKM=";
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 substituteInPlace setup.py \
55 --replace "setuptools-scm==8.1.0" "setuptools-scm" \
56 --replace-fail "wheel==0.42.0" "wheel"
57
58 substituteInPlace pyproject.toml \
59 --replace 'requires = ["setuptools==68.2.2", "setuptools-scm==8.1.0", "wheel==0.42.0", "auditwheel==5.4.0"]' \
60 'requires = ["setuptools", "setuptools-scm", "wheel"]'
61
62 # Skip trying to download and extract the driver.
63 # This is done manually in postInstall instead.
64 substituteInPlace setup.py \
65 --replace "self._download_and_extract_local_driver(base_wheel_bundles)" ""
66
67 # Set the correct driver path with the help of a patch in patches
68 substituteInPlace playwright/_impl/_driver.py \
69 --replace-fail "@node@" "${lib.getExe nodejs}" \
70 --replace-fail "@driver@" "${driver}/cli.js"
71 '';
72
73 nativeBuildInputs = [
74 git
75 setuptools-scm
76 setuptools
77 ] ++ lib.optionals stdenv.hostPlatform.isLinux [ auditwheel ];
78
79 pythonRelaxDeps = [
80 "greenlet"
81 "pyee"
82 ];
83
84 propagatedBuildInputs = [
85 greenlet
86 pyee
87 ];
88
89 postInstall = ''
90 ln -s ${driver} $out/${python.sitePackages}/playwright/driver
91 '';
92
93 # Skip tests because they require network access.
94 doCheck = false;
95
96 pythonImportsCheck = [ "playwright" ];
97
98 passthru = {
99 inherit driver;
100 tests =
101 {
102 driver = playwright-driver;
103 browsers = playwright-driver.browsers;
104 }
105 // lib.optionalAttrs stdenv.hostPlatform.isLinux {
106 inherit (nixosTests) playwright-python;
107 };
108 updateScript = ./update.sh;
109 };
110
111 meta = with lib; {
112 description = "Python version of the Playwright testing and automation library";
113 mainProgram = "playwright";
114 homepage = "https://github.com/microsoft/playwright-python";
115 license = licenses.asl20;
116 maintainers = with maintainers; [
117 techknowlogick
118 yrd
119 ];
120 platforms = [
121 "x86_64-linux"
122 "aarch64-linux"
123 "x86_64-darwin"
124 "aarch64-darwin"
125 ];
126 };
127}