Skip to content

Commit 5eeb6c9

Browse files
timridmhsmith
andauthored
Add possibility to extract all packages with extractPackages (#1424)
Co-authored-by: Malcolm Smith <smith@chaquo.com>
1 parent cb1c6b6 commit 5eeb6c9

12 files changed

Lines changed: 58 additions & 8 deletions

File tree

product/gradle-plugin/src/main/kotlin/PythonTasks.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ internal class TaskBuilder(
323323
File(fte.file.parent, fte.name + "c").exists()
324324
) {
325325
! python.extractPackages.any {
326-
fte.path.replace("/", ".").startsWith(it + ".")
326+
it == "*" || fte.path.replace("/", ".").startsWith(it + ".")
327327
}
328328
} else false
329329
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'com.chaquo.python'
3+
4+
android {
5+
namespace "com.chaquo.python.test"
6+
compileSdk 31
7+
defaultConfig {
8+
applicationId "com.chaquo.python.test"
9+
minSdk 24
10+
targetSdk 31
11+
versionCode 1
12+
versionName "0.0.1"
13+
python {
14+
extractPackages "pkg1", "*"
15+
}
16+
ndk {
17+
abiFilters "x86"
18+
}
19+
}
20+
}

product/gradle-plugin/src/test/integration/data/ExtractPackages/wildcard/app/src/main/python/pkg1/__init__.py

Whitespace-only changes.

product/gradle-plugin/src/test/integration/data/ExtractPackages/wildcard/app/src/main/python/pkg2/__init__.py

Whitespace-only changes.

product/gradle-plugin/src/test/integration/data/ExtractPackages/wildcard/app/src/main/python/pkg3/__init__.py

Whitespace-only changes.

product/gradle-plugin/src/test/integration/data/ExtractPackages/wildcard/app/src/main/python/pkg3/mod1.py

Whitespace-only changes.

product/gradle-plugin/src/test/integration/data/ExtractPackages/wildcard/app/src/main/python/pkg3/sub_pkg/__init__.py

Whitespace-only changes.

product/gradle-plugin/src/test/integration/data/ExtractPackages/wildcard/app/src/main/python/pkg3/sub_pkg/mod2.py

Whitespace-only changes.

product/gradle-plugin/src/test/integration/test_gradle_plugin.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def checkZip(self, zip_filename, files, *, pyc=False, extract_packages=[],
193193
with self.subTest(f=f):
194194
filename, attrs = f if isinstance(f, tuple) else (f, {})
195195
if pyc and filename.endswith(".py"):
196-
if any(filename.startswith(ep.replace(".", "/") + "/")
196+
if any(ep == "*" or filename.startswith(ep.replace(".", "/") + "/")
197197
for ep in extract_packages):
198198
expected_files.append(filename)
199199
filename += "c"
@@ -676,6 +676,19 @@ def test_variant_merge(self):
676676
variants={"red-debug": dict(extract_packages=["common"]),
677677
"blue-debug": dict(extract_packages=["common", "blue"])})
678678

679+
def test_wildcard(self):
680+
PY_FILES = [
681+
"pkg1/__init__.py",
682+
"pkg2/__init__.py",
683+
"pkg3/__init__.py",
684+
"pkg3/mod1.py",
685+
"pkg3/sub_pkg/__init__.py",
686+
"pkg3/sub_pkg/mod2.py",
687+
]
688+
self.RunGradle("base", "ExtractPackages/wildcard",
689+
app=PY_FILES,
690+
extract_packages=["pkg1", "*"])
691+
679692

680693
class Pyc(GradleTestCase):
681694
FAILED = "Failed to compile to .pyc format: "

product/runtime/docs/sphinx/android.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,21 @@ can declare them like this::
405405
}
406406
}
407407

408-
Each extracted file will slightly slow down your app's startup, so this setting should be
409-
used on the deepest possible package.
408+
The files are extracted when the package is imported for the first time. Each extracted
409+
file will slightly slow down your app's startup, so this setting should be used on the
410+
deepest possible package.
411+
412+
For development purposes, it is sometimes useful to extract all packages. This is
413+
possible using a wildcard::
414+
415+
chaquopy {
416+
defaultConfig {
417+
extractPackages("*")
418+
}
419+
}
420+
421+
If the wildcard is used, all packages are imported before your app's code starts
422+
running.
410423

411424
.. _android-data:
412425

0 commit comments

Comments
 (0)