From 85177f51ec73eb98023d8047103decba86270046 Mon Sep 17 00:00:00 2001 From: Mirko Galimberti Date: Sun, 26 Apr 2020 17:53:38 +0200 Subject: [PATCH] Add python depends --- kivy_ios/recipes/kivy/__init__.py | 1 + kivy_ios/toolchain.py | 69 ++++++++++++++++++------------- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/kivy_ios/recipes/kivy/__init__.py b/kivy_ios/recipes/kivy/__init__.py index 940a67e..c03e80b 100644 --- a/kivy_ios/recipes/kivy/__init__.py +++ b/kivy_ios/recipes/kivy/__init__.py @@ -18,6 +18,7 @@ class KivyRecipe(CythonRecipe): library = "libkivy.a" depends = ["sdl2", "sdl2_image", "sdl2_mixer", "sdl2_ttf", "ios", "pyobjus", "python", "host_setuptools3"] + python_depends = ["certifi"] pbx_frameworks = ["OpenGLES", "Accelerate", "CoreMedia", "CoreVideo"] pre_build_ext = True diff --git a/kivy_ios/toolchain.py b/kivy_ios/toolchain.py index 930bf42..7628773 100755 --- a/kivy_ios/toolchain.py +++ b/kivy_ios/toolchain.py @@ -424,6 +424,7 @@ class Recipe: "archs": [], "depends": [], "optional_depends": [], + "python_depends": [], "library": None, "libraries": [], "include_dir": None, @@ -814,6 +815,8 @@ class Recipe: self.install_frameworks() logger.info("Install sources for {}".format(self.name)) self.install_sources() + logger.info("Install python deps for {}".format(self.name)) + self.install_python_deps() logger.info("Install {}".format(self.name)) self.install() @@ -929,6 +932,11 @@ class Recipe: ensure_dir(dirname(dest)) shutil.copy(src_dir, dest) + @cache_execution + def install_python_deps(self): + for dep in self.python_depends: + _pip(["install", dep]) + @cache_execution def install(self): pass @@ -1126,6 +1134,37 @@ def ensure_recipes_loaded(ctx): recipe.init_with_ctx(ctx) +def _pip(args): + ctx = Context() + for recipe in Recipe.list_recipes(): + key = "{}.build_all".format(recipe) + if key not in ctx.state: + continue + recipe = Recipe.get_recipe(recipe, ctx) + recipe.init_with_ctx(ctx) + if not hasattr(ctx, "site_packages_dir"): + logger.error("python must be compiled before using pip") + sys.exit(1) + + pip_env = { + "CC": "/bin/false", + "CXX": "/bin/false", + "PYTHONPATH": ctx.site_packages_dir, + "PYTHONOPTIMIZE": "2", + # "PIP_INSTALL_TARGET": ctx.site_packages_dir + } + + pip_path = join(ctx.dist_dir, 'hostpython3', 'bin', 'pip3') + + if len(args) > 1 and args[0] == "install": + pip_args = ["--isolated", "--ignore-installed", "--prefix", ctx.python_prefix] + args = ["install"] + pip_args + args[1:] + + logger.error("Executing pip with: {}".format(args)) + pip_cmd = sh.Command(pip_path) + shprint(pip_cmd, *args, _env=pip_env) + + def update_pbxproj(filename, pbx_frameworks=None): # list all the compiled recipes ctx = Context() @@ -1415,35 +1454,7 @@ pip Install a pip dependency into the distribution self.pip() def pip(self): - ctx = Context() - for recipe in Recipe.list_recipes(): - key = "{}.build_all".format(recipe) - if key not in ctx.state: - continue - recipe = Recipe.get_recipe(recipe, ctx) - recipe.init_with_ctx(ctx) - if not hasattr(ctx, "site_packages_dir"): - logger.error("python must be compiled before using pip") - sys.exit(1) - - pip_env = { - "CC": "/bin/false", - "CXX": "/bin/false", - "PYTHONPATH": ctx.site_packages_dir, - "PYTHONOPTIMIZE": "2", - # "PIP_INSTALL_TARGET": ctx.site_packages_dir - } - pip_path = join(ctx.dist_dir, 'hostpython3', 'bin', 'pip3') - pip_args = [] - if len(sys.argv) > 2 and sys.argv[2] == "install": - pip_args = ["--isolated", "--ignore-installed", "--prefix", ctx.python_prefix] - args = [pip_path] + [sys.argv[2]] + pip_args + sys.argv[3:] - else: - args = [pip_path] + pip_args + sys.argv[2:] - - import os - logger.error("Executing pip with: {}".format(args)) - os.execve(pip_path, args, pip_env) + _pip(sys.argv[2:]) def launchimage(self): import xcassets