Skip to content

Commit e01057c

Browse files
committed
Change pure-Python package detection from Root-Is-Purelib to wheel tag (closes #1374)
1 parent 5eeb6c9 commit e01057c

9 files changed

Lines changed: 61 additions & 1 deletion

File tree

product/gradle-plugin/src/main/python/chaquopy/pip_install.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,15 @@ def pip_install(self, abi, reqs):
149149
# do it manually.
150150
for dist_info in Path(abi_dir).glob("*.dist-info"):
151151
try:
152+
# pip now installs all packages via wheels, even if they're installed
153+
# from source code, so the WHEEL file is guaranteed to exist.
152154
wheel_info = email.parser.Parser().parse((dist_info / "WHEEL").open())
153-
is_pure = wheel_info.get("Root-Is-Purelib", "false") == "true"
155+
156+
# If there are multiple tags, we can't know which one matched, so err on
157+
# the side of caution. If this causes us to install the same package
158+
# twice, that will be dealt with in merge_common.
159+
tags = wheel_info.get_all("Tag", [])
160+
is_pure = tags and all(tag.endswith("-any") for tag in tags)
154161

155162
req_tree = {}
156163
for row in csv.reader((dist_info / "RECORD").open()):
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
pip {
15+
install "py3_none"
16+
options "--find-links", "py3_none/dist"
17+
}
18+
}
19+
ndk {
20+
abiFilters "arm64-v8a", "x86_64"
21+
}
22+
}
23+
}

product/gradle-plugin/src/test/integration/data/PythonReqs/py3_none/app/py3_none/arm64_v8a.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
from setuptools import setup
5+
6+
7+
assert len(sys.argv) == 2
8+
abi = sys.argv[1]
9+
sys.argv[1:] = ["bdist_wheel", "--plat-name", f"android_24_{abi}"]
10+
11+
setup(
12+
name="py3_none",
13+
version="0.0.1",
14+
py_modules=[abi],
15+
)

product/gradle-plugin/src/test/integration/data/PythonReqs/py3_none/app/py3_none/x86_64.py

Whitespace-only changes.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,20 @@ def test_wheel_data(self):
12281228
self.RunGradle("base", "PythonReqs/wheel_data",
12291229
requirements=["purelib.txt", "platlib.txt"])
12301230

1231+
# This package has wheels with `Root-Is-Purelib: true`, but platform tags of the
1232+
# form `py3-none-android_...`. pip_install.py should treat this as a non-pure
1233+
# package, and install both ABIs.
1234+
def test_py3_none(self):
1235+
self.RunGradle(
1236+
"base", "PythonReqs/py3_none",
1237+
abis=["arm64-v8a", "x86_64"],
1238+
requirements={
1239+
"common": [],
1240+
"arm64-v8a": ["arm64_v8a.py"],
1241+
"x86_64": ["x86_64.py"],
1242+
},
1243+
)
1244+
12311245
# Even with --only-binary, it should still be possible to install a local path to a
12321246
# pure-Python sdist. It's also possible to install a local path to a source
12331247
# directory, which is covered by test_directory.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved compatibility with various ways of tagging a wheel as Android-specific.

0 commit comments

Comments
 (0)