Skip to content

PyProjectRecipe containing install_in_hostpython, does not install in hostpython #3123

Closed

Description

@RobertFlatt

A PyProjectRecipe with install_in_hostpython = True builds but does not install the package in hostpython. It does install the package for target Python.

Presumably because both of these fragments in recipy.py assume only setup.py, and the pyproject.toml case is not implemented:

https://github.com/kivy/python-for-android/blob/develop/pythonforandroid/recipe.py#L1001-L1007

    def install_hostpython_package(self, arch):
        env = self.get_hostrecipe_env(arch)
        real_hostpython = sh.Command(self.real_hostpython_location)
        shprint(real_hostpython, 'setup.py', 'install', '-O2',
                '--root={}'.format(dirname(self.real_hostpython_location)),
                '--install-lib=Lib/site-packages',
                _env=env, *self.setup_extra_args)

https://github.com/kivy/python-for-android/blob/develop/pythonforandroid/recipe.py#L1056-L1068

    def build_compiled_components(self, arch):
        info('Building compiled components in {}'.format(self.name))

        env = self.get_recipe_env(arch)
        hostpython = sh.Command(self.hostpython_location)
        with current_directory(self.get_build_dir(arch.arch)):
            if self.install_in_hostpython:
                shprint(hostpython, 'setup.py', 'clean', '--all', _env=env)
            shprint(hostpython, 'setup.py', self.build_cmd, '-v',
                    _env=env, *self.setup_extra_args)
            build_dir = glob.glob('build/lib.*')[0]
            shprint(sh.find, build_dir, '-name', '"*.o"', '-exec',
                    env['STRIP'], '{}', ';', _env=env)

The good news is none of the existing recipes with install_in_hostpython = True use PyProjectRecipe.

The issue was discovered while updating the (to be reinstated) cppy recipe.

from pythonforandroid.recipe import PyProjectRecipe


class CppyRecipe(PyProjectRecipe):
    site_packages_name = 'cppy'
    version = '1.3.1'
    url = 'https://github.com/nucleic/cppy/archive/refs/tags/{version}.zip'
    call_hostpython_via_targetpython = False
    # to be detected by the matplotlib install script
    install_in_hostpython = True
    depends = ['setuptools']

    def get_recipe_env(self, arch, **kwargs):
        env = super().get_recipe_env(arch, **kwargs)
        env["SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CPPY"] = self.version
        return env


recipe = CppyRecipe()

The simplest test is :

requirements = python3,kivy,cppy
buildozer android debug

This ls shows cppy installed for android:

ls .buildozer/android/platform/build-arm64-v8a/dists/myapp/_python_bundle__arm64-v8a/_python_bundle/site-packages

but these ls show cppy is not installed for either hostpython:

ls .buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages
ls .buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/Lib/site-packages

Build log attached

log.txt

Activity

  1. T-Dynamos commented on Mar 10, 2025

    @T-Dynamos
    Member

    install_in_hostpython isn't required for PyProjectRecipe you can specify in hostpython_prerequisites.

    hostpython_prerequisites = []

  2. RobertFlatt commented on Mar 11, 2025

    @RobertFlatt
    ContributorAuthor

    😎
    Works smoothly.
    Both the dependency .h and .py are found during the build of atom.

    I also tried replacing depends with hostpython_prerequisites on kiwisolver and it worked too (but manual Python.h is still required).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions