17
17
import os
18
18
import sys
19
19
20
- from PyInstaller import compat
21
- from PyInstaller .compat import is_py3
20
+ # Do not import 'compat' globally to avoid circual import:
21
+ # import_pywin32_module() is used by compat
22
+ #from ... import compat
22
23
23
24
import PyInstaller .log as logging
24
25
logger = logging .getLogger (__name__ )
@@ -28,12 +29,9 @@ def get_windows_dir():
28
29
"""
29
30
Return the Windows directory e.g. C:\\ Windows.
30
31
"""
31
- try :
32
- import win32api
33
- except ImportError :
34
- windir = compat .getenv ('SystemRoot' , compat .getenv ('WINDIR' ))
35
- else :
36
- windir = win32api .GetWindowsDirectory ()
32
+ # imported here to avoid circular import
33
+ from ... import compat
34
+ windir = compat .win32api .GetWindowsDirectory ()
37
35
if not windir :
38
36
raise SystemExit ("Error: Can not determine your Windows directory" )
39
37
return windir
@@ -43,12 +41,10 @@ def get_system_path():
43
41
"""
44
42
Return the path that Windows will search for dlls.
45
43
"""
44
+ # imported here to avoid circular import
45
+ from ... import compat
46
46
_bpath = []
47
- try :
48
- import win32api
49
- sys_dir = win32api .GetSystemDirectory ()
50
- except ImportError :
51
- sys_dir = os .path .normpath (os .path .join (get_windows_dir (), 'system32' ))
47
+ sys_dir = compat .win32api .GetSystemDirectory ()
52
48
# Ensure C:\Windows\system32 and C:\Windows directories are
53
49
# always present in PATH variable.
54
50
# C:\Windows\system32 is valid even for 64bit Windows. Access do DLLs are
@@ -65,13 +61,15 @@ def extend_system_path(paths):
65
61
66
62
Some hooks might extend PATH where PyInstaller should look for dlls.
67
63
"""
64
+ # imported here to avoid circular import
65
+ from ... import compat
68
66
old_PATH = compat .getenv ('PATH' , '' )
69
67
paths .append (old_PATH )
70
68
new_PATH = os .pathsep .join (paths )
71
69
compat .setenv ('PATH' , new_PATH )
72
70
73
71
74
- def import_pywin32_module (module_name ):
72
+ def import_pywin32_module (module_name , _is_venv = None ):
75
73
"""
76
74
Import and return the PyWin32 module with the passed name.
77
75
@@ -87,6 +85,11 @@ def import_pywin32_module(module_name):
87
85
----------
88
86
module_name : str
89
87
Fully-qualified name of this module.
88
+ _is_venv: bool
89
+ Internal paramter used by compat.py, to prevent circular import. If None
90
+ (the default), compat is imported and comapt.is_venv ist used. If not
91
+ None, it is assumed to be called from compat and the value to be the same
92
+ as compat.is_venv.
90
93
91
94
Returns
92
95
----------
@@ -112,9 +115,13 @@ def import_pywin32_module(module_name):
112
115
# an ugly hack, but there is no other way.
113
116
sys .frozen = '|_|GLYH@CK'
114
117
118
+ if _is_venv is None : # not called from within compat
119
+ # imported here to avoid circular import
120
+ from ... import compat
121
+ _is_venv = compat .is_venv
115
122
# If isolated to a venv, the preferred site.getsitepackages()
116
123
# function is unreliable. Fallback to searching "sys.path" instead.
117
- if compat . is_venv :
124
+ if _is_venv :
118
125
sys_paths = sys .path
119
126
else :
120
127
import site
@@ -154,7 +161,9 @@ def convert_dll_name_to_str(dll_name):
154
161
:param dll_name:
155
162
:return:
156
163
"""
164
+ # imported here to avoid circular import
165
+ from ...compat import is_py3
157
166
if is_py3 and isinstance (dll_name , bytes ):
158
167
return str (dll_name , encoding = 'UTF-8' )
159
168
else :
160
- return dll_name
169
+ return dll_name
0 commit comments