• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kivy / python-for-android / 14420258271

12 Apr 2025 01:55PM UTC coverage: 59.141% (+0.03%) from 59.111%
14420258271

push

github

web-flow
Add `SDL3` bootstrap (alongside `SDL3`, `SDL3_ttf`, `SDL3_mixer`, `SDL3_image` recipes) for Kivy `3.0.0` (#3125)

* Add SDL3 bootstrap

* Avoid some DRY issues + minor fixes + version bump

1054 of 2383 branches covered (44.23%)

Branch coverage included in aggregate %.

112 of 160 new or added lines in 14 files covered. (70.0%)

1 existing line in 1 file now uncovered.

4960 of 7786 relevant lines covered (63.7%)

2.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.77
/pythonforandroid/recipes/kivy/__init__.py
1
import glob
4✔
2
from os.path import basename, exists, join
4✔
3
import sys
4✔
4
import packaging.version
4✔
5

6
import sh
4✔
7
from pythonforandroid.recipe import CythonRecipe
4✔
8
from pythonforandroid.toolchain import current_directory, shprint
4✔
9

10

11
def is_kivy_affected_by_deadlock_issue(recipe=None, arch=None):
4✔
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):
4✔
25
    version = '2.3.1'
4✔
26
    url = 'https://github.com/kivy/kivy/archive/{version}.zip'
4✔
27
    name = 'kivy'
4✔
28

29
    depends = [('sdl2', 'sdl3'), 'pyjnius', 'setuptools']
4✔
30
    python_depends = ['certifi', 'chardet', 'idna', 'requests', 'urllib3', 'filetype']
4✔
31
    hostpython_prerequisites = []
4✔
32

33
    # sdl-gl-swapwindow-nogil.patch is needed to avoid a deadlock.
34
    # See: https://github.com/kivy/kivy/pull/8025
35
    # WARNING: Remove this patch when a new Kivy version is released.
36
    patches = [("sdl-gl-swapwindow-nogil.patch", is_kivy_affected_by_deadlock_issue)]
4✔
37

38
    def cythonize_build(self, env, build_dir='.'):
4✔
39
        super().cythonize_build(env, build_dir=build_dir)
×
40

41
        if not exists(join(build_dir, 'kivy', 'include')):
×
42
            return
×
43

44
        # If kivy is new enough to use the include dir, copy it
45
        # manually to the right location as we bypass this stage of
46
        # the build
47
        with current_directory(build_dir):
×
48
            build_libs_dirs = glob.glob(join('build', 'lib.*'))
×
49

50
            for dirn in build_libs_dirs:
×
51
                shprint(sh.cp, '-r', join('kivy', 'include'),
×
52
                        join(dirn, 'kivy'))
53

54
    def cythonize_file(self, env, build_dir, filename):
4✔
55
        # We can ignore a few files that aren't important to the
56
        # android build, and may not work on Android anyway
NEW
57
        do_not_cythonize = ['window_x11.pyx', 'camera_avfoundation.pyx', 'img_imageio.pyx', 'egl_angle_metal.pyx']
×
58
        if basename(filename) in do_not_cythonize:
×
59
            return
×
60
        super().cythonize_file(env, build_dir, filename)
×
61

62
    def get_recipe_env(self, arch):
4✔
63
        env = super().get_recipe_env(arch)
×
64
        # NDKPLATFORM is our switch for detecting Android platform, so can't be None
65
        env['NDKPLATFORM'] = "NOTNONE"
×
66
        if 'sdl2' in self.ctx.recipe_build_order:
×
67
            env['USE_SDL2'] = '1'
×
68
            env['KIVY_SPLIT_EXAMPLES'] = '1'
×
69
            sdl2_mixer_recipe = self.get_recipe('sdl2_mixer', self.ctx)
×
70
            sdl2_image_recipe = self.get_recipe('sdl2_image', self.ctx)
×
71
            env['KIVY_SDL2_PATH'] = ':'.join([
×
72
                join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include'),
73
                *sdl2_image_recipe.get_include_dirs(arch),
74
                *sdl2_mixer_recipe.get_include_dirs(arch),
75
                join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
76
            ])
NEW
77
        if "sdl3" in self.ctx.recipe_build_order:
×
NEW
78
            sdl3_mixer_recipe = self.get_recipe("sdl3_mixer", self.ctx)
×
NEW
79
            sdl3_image_recipe = self.get_recipe("sdl3_image", self.ctx)
×
NEW
80
            sdl3_ttf_recipe = self.get_recipe("sdl3_ttf", self.ctx)
×
NEW
81
            sdl3_recipe = self.get_recipe("sdl3", self.ctx)
×
NEW
82
            env["USE_SDL3"] = "1"
×
NEW
83
            env["KIVY_SPLIT_EXAMPLES"] = "1"
×
NEW
84
            env["KIVY_SDL3_PATH"] = ":".join(
×
85
                [
86
                    *sdl3_mixer_recipe.get_include_dirs(arch),
87
                    *sdl3_image_recipe.get_include_dirs(arch),
88
                    *sdl3_ttf_recipe.get_include_dirs(arch),
89
                    *sdl3_recipe.get_include_dirs(arch),
90
                ]
91
            )
92

93
        return env
×
94

95

96
recipe = KivyRecipe()
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc