Skip to content

Commit b32a261

Browse files
committed
Reliably re-download Python executable
1 parent 8558ccd commit b32a261

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

bin/package_command.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,19 @@ class PackageCommand extends Command {
223223
var pythonDir =
224224
Directory(path.join(Directory.systemTemp.path, "hostpython3.10"));
225225

226-
if (!await pythonDir.exists()) {
226+
var pythonExePath = Platform.isWindows
227+
? path.join(pythonDir.path, 'python', 'python.exe')
228+
: path.join(pythonDir.path, 'python', 'bin', 'python3');
229+
230+
if (!await File(pythonExePath).exists()) {
227231
stdout
228232
.writeln("Downloading and extracting Python into ${pythonDir.path}");
229233

234+
if (await pythonDir.exists()) {
235+
await pythonDir.delete(recursive: true);
236+
}
237+
await pythonDir.create(recursive: true);
238+
230239
var isArm64 = Platform.version.contains("arm64");
231240

232241
String arch = "";
@@ -243,8 +252,6 @@ class PackageCommand extends Command {
243252
final url =
244253
"https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-$arch-install_only.tar.gz";
245254

246-
await pythonDir.create(recursive: true);
247-
248255
// Download the release asset
249256
var response = await http.get(Uri.parse(url));
250257
var archivePath = path.join(pythonDir.path, 'python.tar.gz');
@@ -253,13 +260,10 @@ class PackageCommand extends Command {
253260
// Extract the archive
254261
await Process.run('tar', ['-xzf', archivePath, '-C', pythonDir.path]);
255262
} else {
256-
stdout.writeln("Python has already downloaded to ${pythonDir.path}");
263+
stdout.writeln("Python executable found at $pythonExePath");
257264
}
258265

259266
// Run the python executable
260-
var pythonPath = Platform.isWindows
261-
? path.join(pythonDir.path, 'python', 'python.exe')
262-
: path.join(pythonDir.path, 'python', 'bin', 'python3');
263-
return await runExec(pythonPath, args, environment: environment);
267+
return await runExec(pythonExePath, args, environment: environment);
264268
}
265269
}

0 commit comments

Comments
 (0)