Skip to content

Commit 330f748

Browse files
Copy .so libraries from {site-packages}/opt to jniLibs (#119)
* Test sqlite * Copy "opt" libs to jniLibs * exclude opt from site packages * cleanup jniLibs folder * Bump packages version to 0.8.2
1 parent 3a56156 commit 330f748

File tree

18 files changed

+124
-36
lines changed

18 files changed

+124
-36
lines changed

src/serious_python/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.2
2+
3+
* Copy `.so` libraries from `{site-packages}/opt` to `jniLibs`.
4+
15
## 0.8.1
26

37
* Remove `--only-binary` when packaging for desktop platforms ([#112](https://github.com/flet-dev/serious-python/issues/112))
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
067c62c8ae15e77a6935577d0a9cbc8a1b4852f7fc9c458be38d15224e992c9a
1+
86fcefd284f101b084bfb8b72d9eebe97d65c880b1dc97a9b8719ed40c4a3e24

src/serious_python/example/run_example/app/src/main.py

+59-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
print("Hello from Python program!")
22

3+
import _imp
34
import os
5+
from pathlib import Path
46
from time import sleep
57

6-
import _imp
7-
88
_imp.extension_suffixes()
99

1010
print("HELLO!")
@@ -73,21 +73,71 @@ def test_numpy_performance():
7373
assert duration < 0.7
7474

7575

76-
test_lru()
77-
test_numpy_basic()
78-
test_numpy_performance()
79-
80-
# result_value = str(_imp.extension_suffixes())
81-
# result_value = decompressed.decode("utf8")
82-
8376
if not result_filename:
8477
print("RESULT_FILENAME is not set")
8578
exit(1)
8679

80+
r = ""
8781
if result_value:
8882
r = result_value
8983
else:
9084
r = "RESULT_VALUE is not set"
9185

86+
87+
def test_sqlite():
88+
try:
89+
import ctypes
90+
91+
ctypes.cdll.LoadLibrary("libsqlite3_python.so")
92+
import sqlite3
93+
94+
out_dir = Path(result_filename).parent
95+
conn = sqlite3.connect(str(out_dir.joinpath("mydb.db")))
96+
97+
conn.execute("""CREATE TABLE COMPANY
98+
(ID INT PRIMARY KEY NOT NULL,
99+
NAME TEXT NOT NULL,
100+
AGE INT NOT NULL,
101+
ADDRESS CHAR(50),
102+
SALARY REAL);""")
103+
104+
conn.execute(
105+
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \
106+
VALUES (1, 'Paul', 32, 'California', 20000.00 )"
107+
)
108+
109+
conn.execute(
110+
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \
111+
VALUES (2, 'Allen', 25, 'Texas', 15000.00 )"
112+
)
113+
114+
conn.execute(
115+
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \
116+
VALUES (3, 'Teddy', 23, 'Norway', 20000.00 )"
117+
)
118+
119+
conn.execute(
120+
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \
121+
VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 )"
122+
)
123+
124+
conn.commit()
125+
print("Records created successfully")
126+
127+
conn.close()
128+
129+
return "\nsqlite: test_basic - OK"
130+
except Exception as e:
131+
return f"\nsqlite: test_basic - error: {e}"
132+
133+
134+
r += test_sqlite()
135+
# test_lru()
136+
# test_numpy_basic()
137+
# test_numpy_performance()
138+
139+
# result_value = str(_imp.extension_suffixes())
140+
# result_value = decompressed.decode("utf8")
141+
92142
with open(result_filename, "w") as f:
93143
f.write(r)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
numpy
1+
#numpy
22
lru-dict

src/serious_python/example/run_example/pubspec.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -296,42 +296,42 @@ packages:
296296
path: "../.."
297297
relative: true
298298
source: path
299-
version: "0.8.0"
299+
version: "0.8.1"
300300
serious_python_android:
301301
dependency: transitive
302302
description:
303303
path: "../../../serious_python_android"
304304
relative: true
305305
source: path
306-
version: "0.8.0"
306+
version: "0.8.1"
307307
serious_python_darwin:
308308
dependency: transitive
309309
description:
310310
path: "../../../serious_python_darwin"
311311
relative: true
312312
source: path
313-
version: "0.8.0"
313+
version: "0.8.1"
314314
serious_python_linux:
315315
dependency: transitive
316316
description:
317317
path: "../../../serious_python_linux"
318318
relative: true
319319
source: path
320-
version: "0.8.0"
320+
version: "0.8.1"
321321
serious_python_platform_interface:
322322
dependency: transitive
323323
description:
324324
path: "../../../serious_python_platform_interface"
325325
relative: true
326326
source: path
327-
version: "0.8.0"
327+
version: "0.8.1"
328328
serious_python_windows:
329329
dependency: transitive
330330
description:
331331
path: "../../../serious_python_windows"
332332
relative: true
333333
source: path
334-
version: "0.8.0"
334+
version: "0.8.1"
335335
shelf:
336336
dependency: transitive
337337
description:

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

77
platforms:
88
ios:

src/serious_python_android/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.2
2+
3+
* Copy `.so` libraries from `{site-packages}/opt` to `jniLibs`.
4+
15
## 0.8.1
26

37
* Remove `--only-binary` when packaging for desktop platforms ([#112](https://github.com/flet-dev/serious-python/issues/112))

src/serious_python_android/android/build.gradle

+26-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.flet.serious_python_android'
2-
version '0.8.1'
2+
version '0.8.2'
33

44
def python_version = '3.12'
55

@@ -82,7 +82,18 @@ task copyBuildDist(type: Copy) {
8282
// Loop through abiFilters
8383
def packageTasks = []
8484
android.defaultConfig.ndk.abiFilters.each { abi ->
85+
86+
def srcDir = System.getenv('SERIOUS_PYTHON_SITE_PACKAGES')
87+
if (srcDir == null || srcDir.allWhitespace) {
88+
throw new InvalidUserDataException("SERIOUS_PYTHON_SITE_PACKAGES environment variable is not set.")
89+
}
90+
8591
packageTasks.add("zipSitePackages_$abi")
92+
packageTasks.add("copyOpt_$abi")
93+
94+
tasks.register("jniCleanUp_$abi", Delete) {
95+
delete "src/main/jniLibs/$abi"
96+
}
8697

8798
tasks.register("downloadDistArchive_$abi", Download) {
8899
src "https://github.com/flet-dev/python-build/releases/download/v${python_version}/python-android-dart-${python_version}-${abi}.tar.gz"
@@ -91,21 +102,24 @@ android.defaultConfig.ndk.abiFilters.each { abi ->
91102
tasks.register("untarFile_$abi", Copy) {
92103
from tarTree(tasks.named("downloadDistArchive_$abi").get().dest)
93104
into "src/main/jniLibs/$abi"
94-
}
95-
tasks.named("untarFile_$abi") {
96-
dependsOn "downloadDistArchive_$abi"
105+
dependsOn "jniCleanUp_$abi", "downloadDistArchive_$abi"
97106
}
98107

99-
tasks.register("zipSitePackages_$abi", Zip) {
100-
def srcDir = System.getenv('SERIOUS_PYTHON_SITE_PACKAGES')
101-
if (srcDir != null) {
102-
from fileTree(dir: "$srcDir/$abi")
103-
archiveFileName = "libpythonsitepackages.so"
104-
destinationDirectory = file("src/main/jniLibs/$abi")
108+
tasks.register("copyOpt_$abi", Copy) {
109+
from fileTree(dir: "$srcDir/$abi/opt", include: ["**/*.so"])
110+
into "src/main/jniLibs/$abi"
111+
eachFile {
112+
path = name
105113
}
114+
includeEmptyDirs = false
115+
dependsOn "jniCleanUp_$abi"
106116
}
107-
tasks.named("zipSitePackages_$abi") {
108-
dependsOn "untarFile_$abi"
117+
118+
tasks.register("zipSitePackages_$abi", Zip) {
119+
from fileTree(dir: "$srcDir/$abi", exclude: ["opt"])
120+
archiveFileName = "libpythonsitepackages.so"
121+
destinationDirectory = file("src/main/jniLibs/$abi")
122+
dependsOn "jniCleanUp_$abi", "untarFile_$abi"
109123
}
110124
}
111125

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

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

src/serious_python_darwin/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.2
2+
3+
* Copy `.so` libraries from `{site-packages}/opt` to `jniLibs`.
4+
15
## 0.8.1
26

37
* Remove `--only-binary` when packaging for desktop platforms ([#112](https://github.com/flet-dev/serious-python/issues/112))

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.1'
7+
s.version = '0.8.2'
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.1
5+
version: 0.8.2
66

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

src/serious_python_linux/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.2
2+
3+
* Copy `.so` libraries from `{site-packages}/opt` to `jniLibs`.
4+
15
## 0.8.1
26

37
* Remove `--only-binary` when packaging for desktop platforms ([#112](https://github.com/flet-dev/serious-python/issues/112))

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

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

src/serious_python_platform_interface/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.2
2+
3+
* Copy `.so` libraries from `{site-packages}/opt` to `jniLibs`.
4+
15
## 0.8.1
26

37
* Remove `--only-binary` when packaging for desktop platforms ([#112](https://github.com/flet-dev/serious-python/issues/112))

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

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

src/serious_python_windows/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.2
2+
3+
* Copy `.so` libraries from `{site-packages}/opt` to `jniLibs`.
4+
15
## 0.8.1
26

37
* Remove `--only-binary` when packaging for desktop platforms ([#112](https://github.com/flet-dev/serious-python/issues/112))

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

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

0 commit comments

Comments
 (0)