Skip to content

Commit e5ad1c2

Browse files
committed
ensure backward compatibility
1 parent 6813d66 commit e5ad1c2

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

pythonforandroid/build.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import re
1212
import shutil
1313
import subprocess
14+
import sys
1415

1516
import sh
1617

@@ -733,20 +734,21 @@ def process_python_modules(ctx, modules, arch):
733734
_python_path, "Modules") + ":" + (libdir[0] if libdir else "")
734735
pip = host_recipe.pip
735736
except Exception:
736-
# hostpython3 non available so we use system pip (like in tests)
737+
# hostpython3 is unavailable, so fall back to system pip
737738
pip = sh.Command("pip")
738739

739740
# add platform tags
740741
platforms = []
741-
tags = PyProjectRecipe.get_wheel_platform_tag(None, arch.arch, ctx=ctx)
742+
tags = PyProjectRecipe.get_wheel_platform_tag(arch.arch, ctx)
742743
for tag in tags:
743744
platforms.append(f"--platform={tag}")
744745

745746
if host_recipe is not None:
746747
platforms.extend(["--python-version", host_recipe.version])
747748
else:
748-
# tests?
749-
platforms.extend(["--python-version", "3.13.4"])
749+
# use the version of the currently running Python interpreter
750+
current_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
751+
platforms.extend(["--python-version", current_version])
750752

751753
indices = []
752754
# add extra index urls

pythonforandroid/recipe.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ def get_pip_install_args(self, arch):
12681268
"--no-deps",
12691269
]
12701270
# add platform tags
1271-
tags = self.get_wheel_platform_tag(arch.arch)
1271+
tags = PyProjectRecipe.get_wheel_platform_tags(arch.arch, self.ctx)
12721272
for tag in tags:
12731273
opts.append(f"--platform={tag}")
12741274

@@ -1297,7 +1297,8 @@ def check_prebuilt(self, arch, msg=""):
12971297
if msg != "":
12981298
info(f"Prebuilt pip wheel found, {msg}")
12991299
return True
1300-
return
1300+
1301+
return False
13011302

13021303
def get_recipe_env(self, arch, **kwargs):
13031304
# Custom hostpython
@@ -1310,16 +1311,15 @@ def get_recipe_env(self, arch, **kwargs):
13101311

13111312
with open(build_opts, "w") as file:
13121313
file.write("[bdist_wheel]\nplat_name={}".format(
1313-
self.get_wheel_platform_tag(arch.arch)[0]
1314+
self.get_wheel_platform_tag(arch.arch)
13141315
))
13151316
file.close()
13161317

13171318
env["DIST_EXTRA_CONFIG"] = build_opts
13181319
return env
13191320

1320-
def get_wheel_platform_tag(self, arch, ctx=None):
1321-
if ctx is None:
1322-
ctx = self.ctx
1321+
@staticmethod
1322+
def get_wheel_platform_tags(arch, ctx):
13231323
# https://peps.python.org/pep-0738/#packaging
13241324
# official python only supports 64 bit:
13251325
# android_21_arm64_v8a
@@ -1332,6 +1332,9 @@ def get_wheel_platform_tag(self, arch, ctx=None):
13321332
}[arch]
13331333
return [f"android_{ctx.ndk_api}_" + _ for _ in _suffix]
13341334

1335+
def get_wheel_platform_tag(self, arch):
1336+
return PyProjectRecipe.get_wheel_platform_tags(arch, self.ctx)[0]
1337+
13351338
def install_prebuilt_wheel(self, arch):
13361339
info("Installing prebuilt built wheel")
13371340
destination = self.ctx.get_python_install_dir(arch.arch)
@@ -1354,10 +1357,14 @@ def install_wheel(self, arch, built_wheels):
13541357
# Fix wheel platform tag
13551358
wheel_tag = wheel_tags(
13561359
_wheel,
1357-
platform_tags=self.get_wheel_platform_tag(arch.arch)[0],
1360+
platform_tags=self.get_wheel_platform_tag(arch.arch),
13581361
remove=True,
13591362
)
13601363
selected_wheel = join(built_wheel_dir, wheel_tag)
1364+
_dev_wheel_dir = environ.get("P4A_WHEEL_DIR", False)
1365+
if _dev_wheel_dir:
1366+
ensure_dir(_dev_wheel_dir)
1367+
shprint(sh.cp, selected_wheel, _dev_wheel_dir)
13611368

13621369
if exists(self.ctx.save_wheel_dir):
13631370
shprint(sh.cp, selected_wheel, self.ctx.save_wheel_dir)
@@ -1370,7 +1377,7 @@ def install_wheel(self, arch, built_wheels):
13701377
wf.close()
13711378

13721379
def build_arch(self, arch):
1373-
if self.check_prebuilt(arch, "skipping build_arch") is not None:
1380+
if self.check_prebuilt(arch, "skipping build_arch"):
13741381
result = self.install_prebuilt_wheel(arch)
13751382
if result:
13761383
return

0 commit comments

Comments
 (0)