Skip to content

Commit

Permalink
Merge pull request #455 from misl6/add-plain-python-requirements
Browse files Browse the repository at this point in the history
Add python depends
  • Loading branch information
AndreMiras authored May 9, 2020
2 parents 085d04b + 85177f5 commit 5da6cb8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
1 change: 1 addition & 0 deletions kivy_ios/recipes/kivy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
69 changes: 40 additions & 29 deletions kivy_ios/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ class Recipe:
"archs": [],
"depends": [],
"optional_depends": [],
"python_depends": [],
"library": None,
"libraries": [],
"include_dir": None,
Expand Down Expand Up @@ -814,6 +815,8 @@ def build_all(self):
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()

Expand Down Expand Up @@ -929,6 +932,11 @@ def install_include(self):
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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1415,35 +1454,7 @@ def pip3(self):
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
Expand Down

0 comments on commit 5da6cb8

Please sign in to comment.