1
- from copy import copy
2
- from distutils .spawn import find_executable
1
+ import copy
3
2
import os
4
3
import re
5
4
import shutil
17
16
class Configuration (sipconfig .Configuration ):
18
17
19
18
def __init__ (self ):
20
- env = copy (os .environ )
19
+ env = copy . copy (os .environ )
21
20
env ['QT_SELECT' ] = '5'
22
- qmake_exe = 'qmake-qt5' if find_executable ('qmake-qt5' ) else 'qmake'
21
+ qmake_exe = 'qmake-qt5' if shutil . which ('qmake-qt5' ) else 'qmake'
23
22
qtconfig = subprocess .check_output (
24
23
[qmake_exe , '-query' ], env = env , universal_newlines = True )
25
24
qtconfig = dict (line .split (':' , 1 ) for line in qtconfig .splitlines ())
@@ -45,7 +44,7 @@ def __init__(self):
45
44
macros = sipconfig ._default_macros .copy ()
46
45
macros ['INCDIR_QT' ] = qtconfig ['QT_INSTALL_HEADERS' ]
47
46
macros ['LIBDIR_QT' ] = qtconfig ['QT_INSTALL_LIBS' ]
48
- macros ['MOC' ] = 'moc-qt5' if find_executable ('moc-qt5' ) else 'moc'
47
+ macros ['MOC' ] = 'moc-qt5' if shutil . which ('moc-qt5' ) else 'moc'
49
48
self .set_build_macros (macros )
50
49
51
50
@@ -61,25 +60,30 @@ def get_sip_dir_flags(config):
61
60
sip_flags = config .pyqt_sip_flags
62
61
return sip_dir , sip_flags
63
62
except AttributeError :
64
- # sipconfig.Configuration does not have a pyqt_sip_dir or pyqt_sip_flags AttributeError
65
- sip_flags = QtCore .PYQT_CONFIGURATION ['sip_flags' ]
66
-
67
- # Archlinux installs sip files here by default
68
- default_sip_dir = os .path .join (PyQt5 .__path__ [0 ], 'bindings' )
69
- if os .path .exists (default_sip_dir ):
70
- return default_sip_dir , sip_flags
71
-
72
- # sip4 installs here by default
73
- default_sip_dir = os .path .join (sipconfig ._pkg_config ['default_sip_dir' ], 'PyQt5' )
74
- if os .path .exists (default_sip_dir ):
75
- return default_sip_dir , sip_flags
76
-
77
- # Homebrew installs sip files here by default
78
- default_sip_dir = os .path .join (sipconfig ._pkg_config ['default_sip_dir' ], 'Qt5' )
79
- if os .path .exists (default_sip_dir ):
80
- return default_sip_dir , sip_flags
81
- raise FileNotFoundError ('The sip directory for PyQt5 could not be located. Please ensure' +
82
- ' that PyQt5 is installed' )
63
+ pass
64
+
65
+ # We didn't find the sip_dir and sip_flags from the config, continue looking
66
+
67
+ # sipconfig.Configuration does not have a pyqt_sip_dir or pyqt_sip_flags AttributeError
68
+ sip_flags = QtCore .PYQT_CONFIGURATION ['sip_flags' ]
69
+
70
+ candidate_sip_dirs = []
71
+
72
+ # Archlinux installs sip files here by default
73
+ candidate_sip_dirs .append (os .path .join (PyQt5 .__path__ [0 ], 'bindings' ))
74
+
75
+ # sip4 installs here by default
76
+ candidate_sip_dirs .append (os .path .join (sipconfig ._pkg_config ['default_sip_dir' ], 'PyQt5' ))
77
+
78
+ # Homebrew installs sip files here by default
79
+ candidate_sip_dirs .append (os .path .join (sipconfig ._pkg_config ['default_sip_dir' ], 'Qt5' ))
80
+
81
+ for sip_dir in candidate_sip_dirs :
82
+ if os .path .exists (sip_dir ):
83
+ return sip_dir , sip_flags
84
+
85
+ raise FileNotFoundError ('The sip directory for PyQt5 could not be located. Please ensure' +
86
+ ' that PyQt5 is installed' )
83
87
84
88
85
89
if len (sys .argv ) != 8 :
0 commit comments