Skip to content

Commit e3538b5

Browse files
committed
kivy and pyjnius: switch to PyProjectRecipe
1 parent fbd5255 commit e3538b5

File tree

6 files changed

+45
-97
lines changed

6 files changed

+45
-97
lines changed

ci/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TargetPython(Enum):
1919
# requires `libpq-dev` system dependency e.g. for `pg_config` binary
2020
'psycopg2',
2121
# most likely some setup in the Docker container, because it works in host
22-
'pyjnius', 'pyopenal',
22+
'pyopenal',
2323
# SyntaxError: invalid syntax (Python2)
2424
'storm',
2525
# mpmath package with a version >= 0.19 required

pythonforandroid/recipes/kivy/__init__.py

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,23 @@
1-
import glob
2-
from os.path import basename, exists, join
3-
import sys
4-
import packaging.version
1+
from os.path import join
2+
from pythonforandroid.recipe import PyProjectRecipe
53

6-
import sh
7-
from pythonforandroid.recipe import CythonRecipe
8-
from pythonforandroid.toolchain import current_directory, shprint
94

10-
11-
def is_kivy_affected_by_deadlock_issue(recipe=None, arch=None):
12-
with current_directory(join(recipe.get_build_dir(arch.arch), "kivy")):
13-
kivy_version = shprint(
14-
sh.Command(sys.executable),
15-
"-c",
16-
"import _version; print(_version.__version__)",
17-
)
18-
19-
return packaging.version.parse(
20-
str(kivy_version)
21-
) < packaging.version.Version("2.2.0.dev0")
22-
23-
24-
class KivyRecipe(CythonRecipe):
5+
class KivyRecipe(PyProjectRecipe):
256
version = '2.3.1'
267
url = 'https://github.com/kivy/kivy/archive/{version}.zip'
27-
name = 'kivy'
28-
29-
depends = ['sdl2', 'pyjnius', 'setuptools']
8+
depends = ['sdl2', 'pyjnius']
309
python_depends = ['certifi', 'chardet', 'idna', 'requests', 'urllib3', 'filetype']
10+
patches = ["use_cython.patch"]
3111

32-
# sdl-gl-swapwindow-nogil.patch is needed to avoid a deadlock.
33-
# See: https://github.com/kivy/kivy/pull/8025
34-
# WARNING: Remove this patch when a new Kivy version is released.
35-
patches = [("sdl-gl-swapwindow-nogil.patch", is_kivy_affected_by_deadlock_issue)]
36-
37-
def cythonize_build(self, env, build_dir='.'):
38-
super().cythonize_build(env, build_dir=build_dir)
39-
40-
if not exists(join(build_dir, 'kivy', 'include')):
41-
return
42-
43-
# If kivy is new enough to use the include dir, copy it
44-
# manually to the right location as we bypass this stage of
45-
# the build
46-
with current_directory(build_dir):
47-
build_libs_dirs = glob.glob(join('build', 'lib.*'))
48-
49-
for dirn in build_libs_dirs:
50-
shprint(sh.cp, '-r', join('kivy', 'include'),
51-
join(dirn, 'kivy'))
52-
53-
def cythonize_file(self, env, build_dir, filename):
54-
# We can ignore a few files that aren't important to the
55-
# android build, and may not work on Android anyway
56-
do_not_cythonize = ['window_x11.pyx', ]
57-
if basename(filename) in do_not_cythonize:
58-
return
59-
super().cythonize_file(env, build_dir, filename)
60-
61-
def get_recipe_env(self, arch):
62-
env = super().get_recipe_env(arch)
12+
def get_recipe_env(self, arch, **kwargs):
13+
env = super().get_recipe_env(arch, **kwargs)
6314
# NDKPLATFORM is our switch for detecting Android platform, so can't be None
6415
env['NDKPLATFORM'] = "NOTNONE"
16+
env['LIBLINK'] = "NOTNONE"
6517
if 'sdl2' in self.ctx.recipe_build_order:
6618
env['USE_SDL2'] = '1'
6719
env['KIVY_SPLIT_EXAMPLES'] = '1'
20+
sdl_recipe = self.get_recipe("sdl2", self.ctx)
6821
sdl2_mixer_recipe = self.get_recipe('sdl2_mixer', self.ctx)
6922
sdl2_image_recipe = self.get_recipe('sdl2_image', self.ctx)
7023
env['KIVY_SDL2_PATH'] = ':'.join([
@@ -73,7 +26,7 @@ def get_recipe_env(self, arch):
7326
*sdl2_mixer_recipe.get_include_dirs(arch),
7427
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
7528
])
76-
29+
env["LDFLAGS"] += " -L" + join(sdl_recipe.get_build_dir(arch.arch), "../..", "libs", arch.arch)
7730
return env
7831

7932

pythonforandroid/recipes/kivy/sdl-gl-swapwindow-nogil.patch

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- kivy-master/setup.py 2025-02-25 03:08:18.000000000 +0530
2+
+++ kivy-master.mod/setup.py 2025-03-01 13:10:24.227808612 +0530
3+
@@ -249,7 +249,7 @@
4+
# This determines whether Cython specific functionality may be used.
5+
can_use_cython = True
6+
7+
-if platform in ('ios', 'android'):
8+
+if platform in ('ios'):
9+
# NEVER use or declare cython on these platforms
10+
print('Not using cython on %s' % platform)
11+
can_use_cython = False

pythonforandroid/recipes/pyjnius/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
from pythonforandroid.recipe import CythonRecipe
1+
from pythonforandroid.recipe import PyProjectRecipe
22
from pythonforandroid.toolchain import shprint, current_directory, info
33
from pythonforandroid.patching import will_build
44
import sh
55
from os.path import join
66

77

8-
class PyjniusRecipe(CythonRecipe):
8+
class PyjniusRecipe(PyProjectRecipe):
99
version = '1.6.1'
1010
url = 'https://github.com/kivy/pyjnius/archive/{version}.zip'
1111
name = 'pyjnius'
12-
depends = [('genericndkbuild', 'sdl2'), 'six']
12+
depends = ['six']
1313
site_packages_name = 'jnius'
14+
patches = [('genericndkbuild_jnienv_getter.patch', will_build('genericndkbuild')), "use_cython.patch"]
1415

15-
patches = [('genericndkbuild_jnienv_getter.patch', will_build('genericndkbuild'))]
16-
17-
def get_recipe_env(self, arch):
18-
env = super().get_recipe_env(arch)
16+
def get_recipe_env(self, arch, **kwargs):
17+
env = super().get_recipe_env(arch, **kwargs)
1918
# NDKPLATFORM is our switch for detecting Android platform, so can't be None
2019
env['NDKPLATFORM'] = "NOTNONE"
20+
env['LIBLINK'] = "NOTNONE"
21+
env["ANDROID_PYJNIUS_CYTHON_3"] = "1"
22+
sdl_recipe = self.get_recipe("sdl2", self.ctx)
23+
env["LDFLAGS"] += " -L" + join(sdl_recipe.get_build_dir(arch.arch), "../..", "libs", arch.arch)
2124
return env
2225

2326
def postbuild_arch(self, arch):
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--- pyjnius-1.6.1/setup.py 2023-11-05 21:07:43.000000000 +0530
2+
+++ pyjnius-1.6.1.mod/setup.py 2025-03-01 14:47:11.964847337 +0530
3+
@@ -59,10 +59,6 @@
4+
if NDKPLATFORM is not None and getenv('LIBLINK'):
5+
PLATFORM = 'android'
6+
7+
-# detect platform
8+
-if PLATFORM == 'android':
9+
- PYX_FILES = [fn[:-3] + 'c' for fn in PYX_FILES]
10+
-
11+
JAVA=get_java_setup(PLATFORM)
12+
13+
assert JAVA.is_jdk(), "You need a JDK, we only found a JRE. Try setting JAVA_HOME"

0 commit comments

Comments
 (0)