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