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

kivy / python-for-android / 20391339064

20 Dec 2025 07:46AM UTC coverage: 63.356%. First build
20391339064

Pull #3271

github

web-flow
Merge 854ab4e21 into 6494ac165
Pull Request #3271: `toolchain`: auto resolve deps

1781 of 3073 branches covered (57.96%)

Branch coverage included in aggregate %.

18 of 79 new or added lines in 5 files covered. (22.78%)

5216 of 7971 relevant lines covered (65.44%)

5.22 hits per line

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

96.05
/pythonforandroid/recipes/hostpython3/__init__.py
1
import sh
8✔
2
import os
8✔
3

4
from multiprocessing import cpu_count
8✔
5
from pathlib import Path
8✔
6
from os.path import join
8✔
7

8
from packaging.version import Version
8✔
9
from pythonforandroid.logger import shprint
8✔
10
from pythonforandroid.recipe import Recipe
8✔
11
from pythonforandroid.util import (
8✔
12
    BuildInterruptingException,
13
    current_directory,
14
    ensure_dir,
15
)
16
from pythonforandroid.prerequisites import OpenSSLPrerequisite
8✔
17

18
HOSTPYTHON_VERSION_UNSET_MESSAGE = (
8✔
19
    'The hostpython recipe must have set version'
20
)
21

22
SETUP_DIST_NOT_FIND_MESSAGE = (
8✔
23
    'Could not find Setup.dist or Setup in Python build'
24
)
25

26

27
class HostPython3Recipe(Recipe):
8✔
28
    '''
29
    The hostpython3's recipe.
30

31
    .. versionchanged:: 2019.10.06.post0
32
        Refactored from deleted class ``python.HostPythonRecipe`` into here.
33

34
    .. versionchanged:: 0.6.0
35
        Refactored into  the new class
36
        :class:`~pythonforandroid.python.HostPythonRecipe`
37
    '''
38

39
    version = '3.14.2'
8✔
40

41
    url = 'https://github.com/python/cpython/archive/refs/tags/v{version}.tar.gz'
8✔
42
    '''The default url to download our host python recipe. This url will
6✔
43
    change depending on the python version set in attribute :attr:`version`.'''
44

45
    build_subdir = 'native-build'
8✔
46
    '''Specify the sub build directory for the hostpython3 recipe. Defaults
6✔
47
    to ``native-build``.'''
48

49
    @property
8✔
50
    def _exe_name(self):
8✔
51
        '''
52
        Returns the name of the python executable depending on the version.
53
        '''
54
        if not self.version:
8✔
55
            raise BuildInterruptingException(HOSTPYTHON_VERSION_UNSET_MESSAGE)
8✔
56
        return f'python{self.version.split(".")[0]}'
8✔
57

58
    @property
8✔
59
    def python_exe(self):
8✔
60
        '''Returns the full path of the hostpython executable.'''
61
        return join(self.get_path_to_python(), self._exe_name)
8✔
62

63
    def get_recipe_env(self, arch=None):
8✔
64
        env = os.environ.copy()
8✔
65
        openssl_prereq = OpenSSLPrerequisite()
8✔
66
        if env.get("PKG_CONFIG_PATH", ""):
8!
67
            env["PKG_CONFIG_PATH"] = os.pathsep.join(
8✔
68
                [openssl_prereq.pkg_config_location, env["PKG_CONFIG_PATH"]]
69
            )
70
        else:
71
            env["PKG_CONFIG_PATH"] = openssl_prereq.pkg_config_location
×
72
        return env
8✔
73

74
    def should_build(self, arch):
8✔
75
        if Path(self.python_exe).exists():
8✔
76
            # no need to build, but we must set hostpython for our Context
77
            self.ctx.hostpython = self.python_exe
8✔
78
            return False
8✔
79
        return True
8✔
80

81
    def get_build_container_dir(self, arch=None):
8✔
82
        choices = self.check_recipe_choices()
8✔
83
        dir_name = '-'.join([self.name] + choices)
8✔
84
        return join(self.ctx.build_dir, 'other_builds', dir_name, 'desktop')
8✔
85

86
    def get_build_dir(self, arch=None):
8✔
87
        '''
88
        .. note:: Unlike other recipes, the hostpython build dir doesn't
89
            depend on the target arch
90
        '''
91
        return join(self.get_build_container_dir(), self.name)
8✔
92

93
    def get_path_to_python(self):
8✔
94
        return join(self.get_build_dir(), self.build_subdir)
8✔
95

96
    @property
8✔
97
    def site_root(self):
8✔
98
        return join(self.get_path_to_python(), "root")
8✔
99

100
    @property
8✔
101
    def site_bin(self):
8✔
102
        return join(self.site_root, self.site_dir, "bin")
8✔
103

104
    @property
8✔
105
    def local_bin(self):
8✔
106
        return join(self.site_root, "usr/local/bin/")
8✔
107

108
    @property
8✔
109
    def site_dir(self):
8✔
110
        p_version = Version(self.version)
8✔
111
        return join(
8✔
112
            self.site_root,
113
            f"usr/local/lib/python{p_version.major}.{p_version.minor}/site-packages/"
114
        )
115

116
    @property
8✔
117
    def _pip(self):
8✔
NEW
118
        return join(self.local_bin, "pip3")
×
119

120
    @property
8✔
121
    def pip(self):
8✔
NEW
122
        return sh.Command(self._pip)
×
123

124
    def build_arch(self, arch):
8✔
125
        env = self.get_recipe_env(arch)
8✔
126

127
        recipe_build_dir = self.get_build_dir(arch.arch)
8✔
128

129
        # Create a subdirectory to actually perform the build
130
        build_dir = join(recipe_build_dir, self.build_subdir)
8✔
131
        ensure_dir(build_dir)
8✔
132

133
        # Configure the build
134
        build_configured = False
8✔
135
        with current_directory(build_dir):
8✔
136
            if not Path('config.status').exists():
8✔
137
                shprint(sh.Command(join(recipe_build_dir, 'configure')), _env=env)
8✔
138
                build_configured = True
8✔
139

140
        with current_directory(recipe_build_dir):
8✔
141
            # Create the Setup file. This copying from Setup.dist is
142
            # the normal and expected procedure before Python 3.8, but
143
            # after this the file with default options is already named "Setup"
144
            setup_dist_location = join('Modules', 'Setup.dist')
8✔
145
            if Path(setup_dist_location).exists():
8✔
146
                shprint(sh.cp, setup_dist_location,
8✔
147
                        join(build_dir, 'Modules', 'Setup'))
148
            else:
149
                # Check the expected file does exist
150
                setup_location = join('Modules', 'Setup')
8✔
151
                if not Path(setup_location).exists():
8✔
152
                    raise BuildInterruptingException(
8✔
153
                        SETUP_DIST_NOT_FIND_MESSAGE
154
                    )
155

156
            shprint(sh.make, '-j', str(cpu_count()), '-C', build_dir, _env=env)
8✔
157

158
            # make a copy of the python executable giving it the name we want,
159
            # because we got different python's executable names depending on
160
            # the fs being case-insensitive (Mac OS X, Cygwin...) or
161
            # case-sensitive (linux)...so this way we will have an unique name
162
            # for our hostpython, regarding the used fs
163
            for exe_name in ['python.exe', 'python']:
8!
164
                exe = join(self.get_path_to_python(), exe_name)
8✔
165
                if Path(exe).is_file():
8!
166
                    shprint(sh.cp, exe, self.python_exe)
8✔
167
                    break
8✔
168

169
        ensure_dir(self.site_root)
8✔
170
        self.ctx.hostpython = self.python_exe
8✔
171

172
        if build_configured:
8✔
173
            # , "PATH": self.local_bin
174
            shprint(
8✔
175
                sh.Command(self.python_exe), "-m", "ensurepip", "--root", self.site_root, "-U",
176
                _env={"HOME": "/tmp"}
177
            )
178

179

180
recipe = HostPython3Recipe()
8✔
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