Skip to content

Commit e678424

Browse files
Copy flutter from site packages (#122)
* Copy `site-packages/flutter` contents to `SERIOUS_PYTHON_FLUTTER_PACKAGES` * Version bumped to 0.8.4 * Added `SERIOUS_PYTHON_ALLOW_SOURCE_DISTRIBUTIONS` variable
1 parent 521aa20 commit e678424

File tree

15 files changed

+74
-14
lines changed

15 files changed

+74
-14
lines changed

src/serious_python/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.8.4
2+
3+
* Copy `site-packages/flutter` contents to `SERIOUS_PYTHON_FLUTTER_PACKAGES`.
4+
* Added `SERIOUS_PYTHON_ALLOW_SOURCE_DISTRIBUTIONS` variable to allow pip installing from source distributions.
5+
16
## 0.8.3
27

38
* Remove `PYTHONOPTIMIZE=2` to make CFFI work.

src/serious_python/bin/package_command.dart

+36-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ const pyodideLockFile = "pyodide-lock.json";
1919
const buildPythonVersion = "3.12.6";
2020
const buildPythonReleaseDate = "20240909";
2121
const defaultSitePackagesDir = "__pypackages__";
22-
const sitePackageEnvironmentVariable = "SERIOUS_PYTHON_SITE_PACKAGES";
22+
const sitePackagesEnvironmentVariable = "SERIOUS_PYTHON_SITE_PACKAGES";
23+
const flutterPackagesFlutterEnvironmentVariable =
24+
"SERIOUS_PYTHON_FLUTTER_PACKAGES";
25+
const allowSourceDistrosEnvironmentVariable =
26+
"SERIOUS_PYTHON_ALLOW_SOURCE_DISTRIBUTIONS";
2327

2428
const platforms = {
2529
"iOS": {
@@ -227,6 +231,7 @@ class PackageCommand extends Command {
227231
if (requirements.isNotEmpty) {
228232
String? sitePackagesRoot;
229233
bool sitePackagesRootDeleted = false;
234+
bool flutterPackagesCopied = false;
230235
// invoke pip for every platform arch
231236
for (var arch in platforms[platform]!.entries) {
232237
if (archArg != null && arch.key != archArg) {
@@ -266,13 +271,13 @@ class PackageCommand extends Command {
266271

267272
if (isMobile) {
268273
if (!Platform.environment
269-
.containsKey(sitePackageEnvironmentVariable)) {
270-
throw "Environment variable is not set: $sitePackageEnvironmentVariable";
274+
.containsKey(sitePackagesEnvironmentVariable)) {
275+
throw "Environment variable is not set: $sitePackagesEnvironmentVariable";
271276
}
272277
sitePackagesRoot =
273-
Platform.environment[sitePackageEnvironmentVariable];
278+
Platform.environment[sitePackagesEnvironmentVariable];
274279
if (sitePackagesRoot!.isEmpty) {
275-
throw "Environment variable cannot be empty: $sitePackageEnvironmentVariable";
280+
throw "Environment variable cannot be empty: $sitePackagesEnvironmentVariable";
276281
}
277282
} else {
278283
sitePackagesRoot =
@@ -298,7 +303,9 @@ class PackageCommand extends Command {
298303

299304
List<String> pipArgs = ["--disable-pip-version-check"];
300305

301-
if (isMobile || isWeb) {
306+
if ((isMobile || isWeb) &&
307+
!Platform.environment
308+
.containsKey(allowSourceDistrosEnvironmentVariable)) {
302309
pipArgs.addAll(["--only-binary", ":all:"]);
303310
}
304311

@@ -317,6 +324,29 @@ class PackageCommand extends Command {
317324
...requirements
318325
], environment: pipEnv);
319326

327+
// move $sitePackagesDir/flutter if env var is defined
328+
if (Platform.environment
329+
.containsKey(flutterPackagesFlutterEnvironmentVariable)) {
330+
var flutterPackagesRoot = Platform
331+
.environment[flutterPackagesFlutterEnvironmentVariable];
332+
var flutterPackagesRootDir = Directory(flutterPackagesRoot!);
333+
var sitePackagesFlutterDir =
334+
Directory(path.join(sitePackagesDir, "flutter"));
335+
if (await sitePackagesFlutterDir.exists()) {
336+
if (!flutterPackagesCopied) {
337+
stdout.writeln(
338+
"Copying Flutter packages to $flutterPackagesRoot");
339+
if (!await flutterPackagesRootDir.exists()) {
340+
await flutterPackagesRootDir.create(recursive: true);
341+
}
342+
await copyDirectory(sitePackagesFlutterDir,
343+
flutterPackagesRootDir, sitePackagesFlutterDir.path, []);
344+
flutterPackagesCopied = true;
345+
}
346+
await sitePackagesFlutterDir.delete(recursive: true);
347+
}
348+
}
349+
320350
// compile packages
321351
if (compilePackages) {
322352
stdout.writeln("Compiling app packages at $sitePackagesDir");

src/serious_python/pubspec.yaml

+1-1
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.8.3
5+
version: 0.8.4
66

77
platforms:
88
ios:

src/serious_python_android/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.8.4
2+
3+
* Copy `site-packages/flutter` contents to `SERIOUS_PYTHON_FLUTTER_PACKAGES`.
4+
* Added `SERIOUS_PYTHON_ALLOW_SOURCE_DISTRIBUTIONS` variable to allow pip installing from source distributions.
5+
16
## 0.8.3
27

38
* Remove `PYTHONOPTIMIZE=2` to make CFFI work.

src/serious_python_android/android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.flet.serious_python_android'
2-
version '0.8.3'
2+
version '0.8.4'
33

44
def python_version = '3.12'
55

src/serious_python_android/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: serious_python_android
22
description: Android implementation of the serious_python plugin
33
homepage: https://flet.dev
44
repository: https://github.com/flet-dev/serious-python
5-
version: 0.8.3
5+
version: 0.8.4
66

77
environment:
88
sdk: ">=3.0.0 <4.0.0"

src/serious_python_darwin/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.8.4
2+
3+
* Copy `site-packages/flutter` contents to `SERIOUS_PYTHON_FLUTTER_PACKAGES`.
4+
* Added `SERIOUS_PYTHON_ALLOW_SOURCE_DISTRIBUTIONS` variable to allow pip installing from source distributions.
5+
16
## 0.8.3
27

38
* Remove `PYTHONOPTIMIZE=2` to make CFFI work.

src/serious_python_darwin/darwin/serious_python_darwin.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
Pod::Spec.new do |s|
66
s.name = 'serious_python_darwin'
7-
s.version = '0.8.3'
7+
s.version = '0.8.4'
88
s.summary = 'A cross-platform plugin for adding embedded Python runtime to your Flutter apps.'
99
s.description = <<-DESC
1010
A cross-platform plugin for adding embedded Python runtime to your Flutter apps.

src/serious_python_darwin/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: serious_python_darwin
22
description: iOS and macOS implementations of the serious_python plugin
33
homepage: https://flet.dev
44
repository: https://github.com/flet-dev/serious-python
5-
version: 0.8.3
5+
version: 0.8.4
66

77
environment:
88
sdk: ">=3.0.0 <4.0.0"

src/serious_python_linux/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.8.4
2+
3+
* Copy `site-packages/flutter` contents to `SERIOUS_PYTHON_FLUTTER_PACKAGES`.
4+
* Added `SERIOUS_PYTHON_ALLOW_SOURCE_DISTRIBUTIONS` variable to allow pip installing from source distributions.
5+
16
## 0.8.3
27

38
* Remove `PYTHONOPTIMIZE=2` to make CFFI work.

src/serious_python_linux/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: serious_python_linux
22
description: Linux implementations of the serious_python plugin
33
homepage: https://flet.dev
44
repository: https://github.com/flet-dev/serious-python
5-
version: 0.8.3
5+
version: 0.8.4
66

77
environment:
88
sdk: '>=3.1.3 <4.0.0'

src/serious_python_platform_interface/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.8.4
2+
3+
* Copy `site-packages/flutter` contents to `SERIOUS_PYTHON_FLUTTER_PACKAGES`.
4+
* Added `SERIOUS_PYTHON_ALLOW_SOURCE_DISTRIBUTIONS` variable to allow pip installing from source distributions.
5+
16
## 0.8.3
27

38
* Remove `PYTHONOPTIMIZE=2` to make CFFI work.

src/serious_python_platform_interface/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: serious_python_platform_interface
22
description: A common platform interface for the serious_python plugin.
33
homepage: https://flet.dev
44
repository: https://github.com/flet-dev/serious-python
5-
version: 0.8.3
5+
version: 0.8.4
66

77
environment:
88
sdk: ">=3.0.0 <4.0.0"

src/serious_python_windows/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.8.4
2+
3+
* Copy `site-packages/flutter` contents to `SERIOUS_PYTHON_FLUTTER_PACKAGES`.
4+
* Added `SERIOUS_PYTHON_ALLOW_SOURCE_DISTRIBUTIONS` variable to allow pip installing from source distributions.
5+
16
## 0.8.3
27

38
* Remove `PYTHONOPTIMIZE=2` to make CFFI work.

src/serious_python_windows/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: serious_python_windows
22
description: Windows implementations of the serious_python plugin
33
homepage: https://flet.dev
44
repository: https://github.com/flet-dev/serious-python
5-
version: 0.8.3
5+
version: 0.8.4
66

77
environment:
88
sdk: '>=3.1.3 <4.0.0'

0 commit comments

Comments
 (0)