Skip to content

Commit 387609c

Browse files
--exclude option for package command. Python distributive stability fix. (#50)
* --exclude option for package command * Always re-create Python directory * Bump package version to 0.6.1
1 parent 2702b50 commit 387609c

File tree

19 files changed

+119
-60
lines changed

19 files changed

+119
-60
lines changed

src/serious_python/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.6.1
2+
3+
* `--exclude` option for `package` command - to exclude directories and files from Python app package.
4+
* Re-create temp Python distributive directory on every run of `package` command.
5+
16
## 0.6.0
27

38
* `--verbose` flag - verbose output.

src/serious_python/bin/package_command.dart

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const junkFilesAndDirectories = ["__pycache__", "bin"];
2929

3030
class PackageCommand extends Command {
3131
bool _verbose = false;
32+
Directory? _pythonDir;
3233

3334
@override
3435
final name = "package";
@@ -56,6 +57,9 @@ class PackageCommand extends Command {
5657
argParser.addOption('platform',
5758
help:
5859
"Make pip to install dependencies for this platform, e.g. 'emscripten_3_1_45_wasm32'. An attempt to install native Python modules will raise an error.");
60+
argParser.addOption('exclude',
61+
help:
62+
"List of relative paths to exclude from app package, e.g. \"assets,build\".");
5963
}
6064

6165
// [run] may also return a Future.
@@ -86,6 +90,7 @@ class PackageCommand extends Command {
8690
String? reqDepsArg = argResults?['req-deps'];
8791
String? findLinksArg = argResults?['find-links'];
8892
String? platformArg = argResults?['platform'];
93+
String? excludeArg = argResults?['exclude'];
8994
_verbose = argResults?["verbose"];
9095

9196
if (mobile && web) {
@@ -130,7 +135,13 @@ class PackageCommand extends Command {
130135
// copy app to a temp dir
131136
stdout.writeln(
132137
"Copying Python app from ${sourceDir.path} to ${tempDir.path}");
133-
await copyDirectory(sourceDir, tempDir);
138+
await copyDirectory(
139+
sourceDir,
140+
tempDir,
141+
sourceDir.path,
142+
excludeArg != null
143+
? excludeArg.split(",").map((s) => s.trim()).toList()
144+
: []);
134145

135146
// discover dependencies
136147
List<String> dependencies = [];
@@ -310,6 +321,10 @@ class PackageCommand extends Command {
310321
"Deleting sitecustomize directory ${sitecustomizeDir.path}");
311322
await sitecustomizeDir.delete(recursive: true);
312323
}
324+
if (_pythonDir != null && await _pythonDir!.exists()) {
325+
stdout.writeln("Deleting Python directory ${_pythonDir!.path}");
326+
await _pythonDir!.delete(recursive: true);
327+
}
313328
}
314329
}
315330

@@ -330,13 +345,18 @@ class PackageCommand extends Command {
330345
return null;
331346
}
332347

333-
Future<void> copyDirectory(Directory source, Directory destination) async {
348+
Future<void> copyDirectory(Directory source, Directory destination,
349+
String rootDir, List<String> excludeList) async {
334350
await for (var entity in source.list()) {
351+
if (excludeList.contains(path.relative(entity.path, from: rootDir))) {
352+
continue;
353+
}
335354
if (entity is Directory) {
336355
final newDirectory =
337356
Directory(path.join(destination.path, path.basename(entity.path)));
338357
await newDirectory.create();
339-
await copyDirectory(entity.absolute, newDirectory);
358+
await copyDirectory(
359+
entity.absolute, newDirectory, rootDir, excludeList);
340360
} else if (entity is File) {
341361
await entity
342362
.copy(path.join(destination.path, path.basename(entity.path)));
@@ -385,21 +405,8 @@ class PackageCommand extends Command {
385405

386406
Future<int> runPython(List<String> args,
387407
{Map<String, String>? environment}) async {
388-
var pythonDir =
389-
Directory(path.join(Directory.systemTemp.path, "hostpython3.11"));
390-
391-
var pythonExePath = Platform.isWindows
392-
? path.join(pythonDir.path, 'python', 'python.exe')
393-
: path.join(pythonDir.path, 'python', 'bin', 'python3');
394-
395-
if (!await File(pythonExePath).exists()) {
396-
stdout
397-
.writeln("Downloading and extracting Python into ${pythonDir.path}");
398-
399-
if (await pythonDir.exists()) {
400-
await pythonDir.delete(recursive: true);
401-
}
402-
await pythonDir.create(recursive: true);
408+
if (_pythonDir == null) {
409+
_pythonDir = await Directory.systemTemp.createTemp('hostpython3.11_');
403410

404411
var isArm64 = Platform.version.contains("arm64");
405412

@@ -416,20 +423,35 @@ class PackageCommand extends Command {
416423
arch = 'x86_64-pc-windows-msvc-shared';
417424
}
418425

419-
final url =
420-
"https://github.com/indygreg/python-build-standalone/releases/download/20231002/cpython-3.11.6+20231002-$arch-install_only.tar.gz";
426+
var pythonArchiveFilename =
427+
"cpython-3.11.6+20231002-$arch-install_only.tar.gz";
421428

422-
// Download the release asset
423-
var response = await http.get(Uri.parse(url));
424-
var archivePath = path.join(pythonDir.path, 'python.tar.gz');
425-
await File(archivePath).writeAsBytes(response.bodyBytes);
429+
var pythonArchivePath =
430+
path.join(Directory.systemTemp.path, pythonArchiveFilename);
426431

427-
// Extract the archive
428-
await Process.run('tar', ['-xzf', archivePath, '-C', pythonDir.path]);
429-
} else {
430-
verbose("Python executable found at $pythonExePath");
432+
if (!await File(pythonArchivePath).exists()) {
433+
// download Python distr from GitHub
434+
final url =
435+
"https://github.com/indygreg/python-build-standalone/releases/download/20231002/$pythonArchiveFilename";
436+
437+
stdout.writeln(
438+
"Downloading Python distributive from $url to $pythonArchivePath");
439+
440+
var response = await http.get(Uri.parse(url));
441+
await File(pythonArchivePath).writeAsBytes(response.bodyBytes);
442+
}
443+
444+
// extract Python from archive
445+
stdout.writeln(
446+
"Extracting Python distributive from $pythonArchivePath to ${_pythonDir!.path}");
447+
await Process.run(
448+
'tar', ['-xzf', pythonArchivePath, '-C', _pythonDir!.path]);
431449
}
432450

451+
var pythonExePath = Platform.isWindows
452+
? path.join(_pythonDir!.path, 'python', 'python.exe')
453+
: path.join(_pythonDir!.path, 'python', 'bin', 'python3');
454+
433455
// Run the python executable
434456
verbose([pythonExePath, ...args].join(" "));
435457
return await runExec(pythonExePath, args, environment: environment);
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
PODS:
22
- FlutterMacOS (1.0.0)
3+
- package_info_plus (0.0.1):
4+
- FlutterMacOS
35
- path_provider_foundation (0.0.1):
46
- Flutter
57
- FlutterMacOS
6-
- serious_python_darwin (0.3.1):
8+
- serious_python_darwin (0.6.1):
79
- Flutter
810
- FlutterMacOS
911

1012
DEPENDENCIES:
1113
- FlutterMacOS (from `Flutter/ephemeral`)
14+
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
1215
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
1316
- serious_python_darwin (from `Flutter/ephemeral/.symlinks/plugins/serious_python_darwin/darwin`)
1417

1518
EXTERNAL SOURCES:
1619
FlutterMacOS:
1720
:path: Flutter/ephemeral
21+
package_info_plus:
22+
:path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos
1823
path_provider_foundation:
1924
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
2025
serious_python_darwin:
2126
:path: Flutter/ephemeral/.symlinks/plugins/serious_python_darwin/darwin
2227

2328
SPEC CHECKSUMS:
2429
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
25-
path_provider_foundation: eaf5b3e458fc0e5fbb9940fb09980e853fe058b8
26-
serious_python_darwin: 3b3e9802e671014eb062d16976ef5394dea763ce
30+
package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce
31+
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
32+
serious_python_darwin: 6deda6a52f401fcf7e9b9a83c3a9387a9c08d599
2733

28-
PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367
34+
PODFILE CHECKSUM: 9ebaf0ce3d369aaa26a9ea0e159195ed94724cf3
2935

3036
COCOAPODS: 1.12.1

src/serious_python/example/flask_example/pubspec.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,42 +302,42 @@ packages:
302302
path: "../.."
303303
relative: true
304304
source: path
305-
version: "0.6.0"
305+
version: "0.6.1"
306306
serious_python_android:
307307
dependency: transitive
308308
description:
309309
path: "../../../serious_python_android"
310310
relative: true
311311
source: path
312-
version: "0.6.0"
312+
version: "0.6.1"
313313
serious_python_darwin:
314314
dependency: transitive
315315
description:
316316
path: "../../../serious_python_darwin"
317317
relative: true
318318
source: path
319-
version: "0.6.0"
319+
version: "0.6.1"
320320
serious_python_linux:
321321
dependency: transitive
322322
description:
323323
path: "../../../serious_python_linux"
324324
relative: true
325325
source: path
326-
version: "0.6.0"
326+
version: "0.6.1"
327327
serious_python_platform_interface:
328328
dependency: transitive
329329
description:
330330
path: "../../../serious_python_platform_interface"
331331
relative: true
332332
source: path
333-
version: "0.6.0"
333+
version: "0.6.1"
334334
serious_python_windows:
335335
dependency: transitive
336336
description:
337337
path: "../../../serious_python_windows"
338338
relative: true
339339
source: path
340-
version: "0.6.0"
340+
version: "0.6.1"
341341
sky_engine:
342342
dependency: transitive
343343
description: flutter

src/serious_python/example/flet_example/pubspec.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,42 +509,42 @@ packages:
509509
path: "../.."
510510
relative: true
511511
source: path
512-
version: "0.6.0"
512+
version: "0.6.1"
513513
serious_python_android:
514514
dependency: transitive
515515
description:
516516
path: "../../../serious_python_android"
517517
relative: true
518518
source: path
519-
version: "0.6.0"
519+
version: "0.6.1"
520520
serious_python_darwin:
521521
dependency: transitive
522522
description:
523523
path: "../../../serious_python_darwin"
524524
relative: true
525525
source: path
526-
version: "0.6.0"
526+
version: "0.6.1"
527527
serious_python_linux:
528528
dependency: transitive
529529
description:
530530
path: "../../../serious_python_linux"
531531
relative: true
532532
source: path
533-
version: "0.6.0"
533+
version: "0.6.1"
534534
serious_python_platform_interface:
535535
dependency: transitive
536536
description:
537537
path: "../../../serious_python_platform_interface"
538538
relative: true
539539
source: path
540-
version: "0.6.0"
540+
version: "0.6.1"
541541
serious_python_windows:
542542
dependency: transitive
543543
description:
544544
path: "../../../serious_python_windows"
545545
relative: true
546546
source: path
547-
version: "0.6.0"
547+
version: "0.6.1"
548548
shake:
549549
dependency: transitive
550550
description:

src/serious_python/example/run_example/macos/Podfile.lock

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
PODS:
22
- FlutterMacOS (1.0.0)
3+
- package_info_plus (0.0.1):
4+
- FlutterMacOS
35
- path_provider_foundation (0.0.1):
46
- Flutter
57
- FlutterMacOS
6-
- serious_python_darwin (0.3.1):
8+
- serious_python_darwin (0.6.1):
79
- Flutter
810
- FlutterMacOS
911

1012
DEPENDENCIES:
1113
- FlutterMacOS (from `Flutter/ephemeral`)
14+
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
1215
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
1316
- serious_python_darwin (from `Flutter/ephemeral/.symlinks/plugins/serious_python_darwin/darwin`)
1417

1518
EXTERNAL SOURCES:
1619
FlutterMacOS:
1720
:path: Flutter/ephemeral
21+
package_info_plus:
22+
:path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos
1823
path_provider_foundation:
1924
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
2025
serious_python_darwin:
2126
:path: Flutter/ephemeral/.symlinks/plugins/serious_python_darwin/darwin
2227

2328
SPEC CHECKSUMS:
2429
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
30+
package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce
2531
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
26-
serious_python_darwin: 482c39edd868a8f319567c03024fc3e546be81e7
32+
serious_python_darwin: 6deda6a52f401fcf7e9b9a83c3a9387a9c08d599
2733

2834
PODFILE CHECKSUM: 9ebaf0ce3d369aaa26a9ea0e159195ed94724cf3
2935

src/serious_python/example/run_example/pubspec.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,42 +317,42 @@ packages:
317317
path: "../.."
318318
relative: true
319319
source: path
320-
version: "0.6.0"
320+
version: "0.6.1"
321321
serious_python_android:
322322
dependency: transitive
323323
description:
324324
path: "../../../serious_python_android"
325325
relative: true
326326
source: path
327-
version: "0.6.0"
327+
version: "0.6.1"
328328
serious_python_darwin:
329329
dependency: transitive
330330
description:
331331
path: "../../../serious_python_darwin"
332332
relative: true
333333
source: path
334-
version: "0.6.0"
334+
version: "0.6.1"
335335
serious_python_linux:
336336
dependency: transitive
337337
description:
338338
path: "../../../serious_python_linux"
339339
relative: true
340340
source: path
341-
version: "0.6.0"
341+
version: "0.6.1"
342342
serious_python_platform_interface:
343343
dependency: transitive
344344
description:
345345
path: "../../../serious_python_platform_interface"
346346
relative: true
347347
source: path
348-
version: "0.6.0"
348+
version: "0.6.1"
349349
serious_python_windows:
350350
dependency: transitive
351351
description:
352352
path: "../../../serious_python_windows"
353353
relative: true
354354
source: path
355-
version: "0.6.0"
355+
version: "0.6.1"
356356
sky_engine:
357357
dependency: transitive
358358
description: flutter

src/serious_python/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: serious_python
22
description: A cross-platform plugin for adding embedded Python runtime to your Flutter apps.
33
homepage: https://flet.dev
44
repository: https://github.com/flet-dev/serious-python
5-
version: 0.6.0
5+
version: 0.6.1
66

77
platforms:
88
ios:

src/serious_python_android/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.6.1
2+
3+
* `--exclude` option for `package` command - to exclude directories and files from Python app package.
4+
* Re-create temp Python distributive directory on every run of `package` command.
5+
16
## 0.6.0
27

38
* `--verbose` flag - verbose output.

0 commit comments

Comments
 (0)