@@ -159,90 +159,7 @@ public override async Task RunPackage(
159
159
Action < ProcessOutput > ? onConsoleOutput
160
160
)
161
161
{
162
- await SetupVenv ( installedPackagePath ) . ConfigureAwait ( false ) ;
163
-
164
- // update gui files to point to venv accelerate
165
- await runner . RunInThreadWithLock ( ( ) =>
166
- {
167
- var scope = Py . CreateScope ( ) ;
168
- scope . Exec (
169
- """
170
- import ast
171
-
172
- class StringReplacer(ast.NodeTransformer):
173
- def __init__(self, old: str, new: str, replace_count: int = -1):
174
- self.old = old
175
- self.new = new
176
- self.replace_count = replace_count
177
-
178
- def visit_Constant(self, node: ast.Constant) -> ast.Constant:
179
- if isinstance(node.value, str) and self.old in node.value:
180
- new_value = node.value.replace(self.old, self.new, self.replace_count)
181
- node.value = new_value
182
- return node
183
-
184
- def rewrite_module(self, module_text: str) -> str:
185
- tree = ast.parse(module_text)
186
- tree = self.visit(tree)
187
- return ast.unparse(tree)
188
- """
189
- ) ;
190
-
191
- var replacementAcceleratePath = Compat . IsWindows
192
- ? @".\venv\scripts\accelerate"
193
- : "./venv/bin/accelerate" ;
194
-
195
- var replacer = scope . InvokeMethod (
196
- "StringReplacer" ,
197
- "accelerate" . ToPython ( ) ,
198
- $ "{ replacementAcceleratePath } ". ToPython ( ) ,
199
- 1 . ToPython ( )
200
- ) ;
201
-
202
- var kohyaGuiDir = Path . Combine ( installedPackagePath , "kohya_gui" ) ;
203
- var guiDirExists = Directory . Exists ( kohyaGuiDir ) ;
204
- var filesToUpdate = new List < string > ( ) ;
205
-
206
- if ( guiDirExists )
207
- {
208
- filesToUpdate . AddRange (
209
- [
210
- "lora_gui.py" ,
211
- "dreambooth_gui.py" ,
212
- "textual_inversion_gui.py" ,
213
- "wd14_caption_gui.py" ,
214
- "finetune_gui.py"
215
- ]
216
- ) ;
217
- }
218
- else
219
- {
220
- filesToUpdate . AddRange (
221
- [
222
- "lora_gui.py" ,
223
- "dreambooth_gui.py" ,
224
- "textual_inversion_gui.py" ,
225
- Path . Combine ( "library" , "wd14_caption_gui.py" ) ,
226
- "finetune_gui.py"
227
- ]
228
- ) ;
229
- }
230
-
231
- foreach ( var file in filesToUpdate )
232
- {
233
- var path = Path . Combine ( guiDirExists ? kohyaGuiDir : installedPackagePath , file ) ;
234
- if ( ! File . Exists ( path ) )
235
- continue ;
236
-
237
- var text = File . ReadAllText ( path ) ;
238
- if ( text . Contains ( replacementAcceleratePath . Replace ( @"\" , @"\\" ) ) )
239
- continue ;
240
-
241
- var result = replacer . InvokeMethod ( "rewrite_module" , text . ToPython ( ) ) ;
242
- var resultStr = result . ToString ( ) ;
243
- File . WriteAllText ( path , resultStr ) ;
244
- }
245
- } ) ;
162
+ var venvRunner = await SetupVenvPure ( installedPackagePath ) . ConfigureAwait ( false ) ;
246
163
247
164
void HandleConsoleOutput ( ProcessOutput s )
248
165
{
@@ -262,7 +179,7 @@ void HandleConsoleOutput(ProcessOutput s)
262
179
263
180
var args = $ "\" { Path . Combine ( installedPackagePath , command ) } \" { arguments } ";
264
181
265
- VenvRunner . RunDetached ( args . TrimEnd ( ) , HandleConsoleOutput , OnExit ) ;
182
+ venvRunner . RunDetached ( args . TrimEnd ( ) , HandleConsoleOutput , OnExit ) ;
266
183
}
267
184
268
185
public override Dictionary < SharedFolderType , IReadOnlyList < string > > ? SharedFolders { get ; }
0 commit comments