1{ lib, pythonPackages, pkg-config
2, dbus
3, qmake, lndir
4, qtbase
5, qtsvg
6, qtdeclarative
7, qtwebchannel
8, withConnectivity ? false, qtconnectivity
9, withMultimedia ? false, qtmultimedia
10, withWebKit ? false, qtwebkit
11, withWebSockets ? false, qtwebsockets
12}:
13
14let
15
16 inherit (pythonPackages) buildPythonPackage python isPy3k dbus-python enum34;
17
18 sip = if isPy3k then
19 pythonPackages.sip
20 else
21 (pythonPackages.sip_4.override { sip-module = "PyQt5.sip"; }).overridePythonAttrs(oldAttrs: {
22 # If we install sip in another folder, then we need to create a __init__.py as well
23 # if we want to be able to import it with Python 2.
24 # Python 3 could rely on it being an implicit namespace package, however,
25 # PyQt5 we made an explicit namespace package so sip should be as well.
26 postInstall = ''
27 cat << EOF > $out/${python.sitePackages}/PyQt5/__init__.py
28 from pkgutil import extend_path
29 __path__ = extend_path(__path__, __name__)
30 EOF
31 '';
32 });
33
34 pyqt5_sip = buildPythonPackage rec {
35 pname = "PyQt5_sip";
36 version = "12.8.1";
37
38 src = pythonPackages.fetchPypi {
39 inherit pname version;
40 sha256 = "30e944db9abee9cc757aea16906d4198129558533eb7fadbe48c5da2bd18e0bd";
41 };
42
43 # There is no test code and the check phase fails with:
44 # > error: could not create 'PyQt5/sip.cpython-38-x86_64-linux-gnu.so': No such file or directory
45 doCheck = false;
46 };
47
48in buildPythonPackage rec {
49 pname = "PyQt5";
50 version = "5.15.2";
51 format = "other";
52
53 src = pythonPackages.fetchPypi {
54 inherit pname version;
55 sha256 = "1z74295i69cha52llsqffzhb5zz7qnbjc64h8qg21l91jgf0harp";
56 };
57
58 outputs = [ "out" "dev" ];
59
60 dontWrapQtApps = true;
61
62 nativeBuildInputs = [
63 pkg-config
64 qmake
65 lndir
66 sip
67 qtbase
68 qtsvg
69 qtdeclarative
70 qtwebchannel
71 ]
72 ++ lib.optional withConnectivity qtconnectivity
73 ++ lib.optional withMultimedia qtmultimedia
74 ++ lib.optional withWebKit qtwebkit
75 ++ lib.optional withWebSockets qtwebsockets
76 ;
77
78 buildInputs = [
79 dbus
80 qtbase
81 qtsvg
82 qtdeclarative
83 ]
84 ++ lib.optional withConnectivity qtconnectivity
85 ++ lib.optional withWebKit qtwebkit
86 ++ lib.optional withWebSockets qtwebsockets
87 ;
88
89 propagatedBuildInputs = [
90 dbus-python
91 ] ++ (if isPy3k then [ pyqt5_sip ] else [ sip enum34 ]);
92
93 patches = [
94 # Fix some wrong assumptions by ./configure.py
95 # TODO: figure out how to send this upstream
96 ./pyqt5-fix-dbus-mainloop-support.patch
97 ];
98
99 passthru = {
100 inherit sip;
101 multimediaEnabled = withMultimedia;
102 webKitEnabled = withWebKit;
103 WebSocketsEnabled = withWebSockets;
104 };
105
106 configurePhase = ''
107 runHook preConfigure
108
109 export PYTHONPATH=$PYTHONPATH:$out/${python.sitePackages}
110
111 ${python.executable} configure.py -w \
112 --confirm-license \
113 --dbus-moduledir=$out/${python.sitePackages}/dbus/mainloop \
114 --no-qml-plugin \
115 --bindir=$out/bin \
116 --destdir=$out/${python.sitePackages} \
117 --stubsdir=$out/${python.sitePackages}/PyQt5 \
118 --sipdir=$out/share/sip/PyQt5 \
119 --designer-plugindir=$out/plugins/designer
120
121 runHook postConfigure
122 '';
123
124 postInstall = lib.optionalString (!isPy3k) ''
125 ln -s ${sip}/${python.sitePackages}/PyQt5/sip.* $out/${python.sitePackages}/PyQt5/
126 for i in $out/bin/*; do
127 wrapProgram $i --prefix PYTHONPATH : "$PYTHONPATH"
128 done
129
130 # Let's make it a namespace package
131 cat << EOF > $out/${python.sitePackages}/PyQt5/__init__.py
132 from pkgutil import extend_path
133 __path__ = extend_path(__path__, __name__)
134 EOF
135 '';
136
137 # Checked using pythonImportsCheck
138 doCheck = false;
139
140 pythonImportsCheck = [
141 "PyQt5"
142 "PyQt5.QtCore"
143 "PyQt5.QtQml"
144 "PyQt5.QtWidgets"
145 "PyQt5.QtGui"
146 ]
147 ++ lib.optional withWebSockets "PyQt5.QtWebSockets"
148 ++ lib.optional withWebKit "PyQt5.QtWebKit"
149 ++ lib.optional withMultimedia "PyQt5.QtMultimedia"
150 ++ lib.optional withConnectivity "PyQt5.QtConnectivity"
151 ;
152
153 enableParallelBuilding = true;
154
155 meta = with lib; {
156 description = "Python bindings for Qt5";
157 homepage = "http://www.riverbankcomputing.co.uk";
158 license = licenses.gpl3;
159 platforms = platforms.mesaPlatforms;
160 maintainers = with maintainers; [ sander ];
161 };
162}