@@ -85,8 +85,12 @@ def main(script_path: Optional[str],
85
85
fail ("error: --install-types not supported with incremental mode disabled" ,
86
86
stderr , options )
87
87
88
+ if options .install_types and options .python_executable is None :
89
+ fail ("error: --install-types not supported without python executable or site packages" ,
90
+ stderr , options )
91
+
88
92
if options .install_types and not sources :
89
- install_types (options . cache_dir , formatter , non_interactive = options .non_interactive )
93
+ install_types (formatter , options , non_interactive = options .non_interactive )
90
94
return
91
95
92
96
res , messages , blockers = run_build (sources , options , fscache , t0 , stdout , stderr )
@@ -95,7 +99,7 @@ def main(script_path: Optional[str],
95
99
missing_pkgs = read_types_packages_to_install (options .cache_dir , after_run = True )
96
100
if missing_pkgs :
97
101
# Install missing type packages and rerun build.
98
- install_types (options . cache_dir , formatter , after_run = True , non_interactive = True )
102
+ install_types (formatter , options , after_run = True , non_interactive = True )
99
103
fscache .flush ()
100
104
print ()
101
105
res , messages , blockers = run_build (sources , options , fscache , t0 , stdout , stderr )
@@ -122,8 +126,7 @@ def main(script_path: Optional[str],
122
126
stdout .flush ()
123
127
124
128
if options .install_types and not options .non_interactive :
125
- result = install_types (options .cache_dir , formatter , after_run = True ,
126
- non_interactive = False )
129
+ result = install_types (formatter , options , after_run = True , non_interactive = False )
127
130
if result :
128
131
print ()
129
132
print ("note: Run mypy again for up-to-date results with installed types" )
@@ -1151,20 +1154,21 @@ def read_types_packages_to_install(cache_dir: str, after_run: bool) -> List[str]
1151
1154
return [line .strip () for line in f .readlines ()]
1152
1155
1153
1156
1154
- def install_types (cache_dir : str ,
1155
- formatter : util . FancyFormatter ,
1157
+ def install_types (formatter : util . FancyFormatter ,
1158
+ options : Options ,
1156
1159
* ,
1157
1160
after_run : bool = False ,
1158
1161
non_interactive : bool = False ) -> bool :
1159
1162
"""Install stub packages using pip if some missing stubs were detected."""
1160
- packages = read_types_packages_to_install (cache_dir , after_run )
1163
+ packages = read_types_packages_to_install (options . cache_dir , after_run )
1161
1164
if not packages :
1162
1165
# If there are no missing stubs, generate no output.
1163
1166
return False
1164
1167
if after_run and not non_interactive :
1165
1168
print ()
1166
1169
print ('Installing missing stub packages:' )
1167
- cmd = [sys .executable , '-m' , 'pip' , 'install' ] + packages
1170
+ assert options .python_executable , 'Python executable required to install types'
1171
+ cmd = [options .python_executable , '-m' , 'pip' , 'install' ] + packages
1168
1172
print (formatter .style (' ' .join (cmd ), 'none' , bold = True ))
1169
1173
print ()
1170
1174
if not non_interactive :
0 commit comments