diff --git a/README.md b/README.md
index c5a61b6..d9aaa13 100644
--- a/README.md
+++ b/README.md
@@ -98,7 +98,7 @@ You can build recipes at the same time by adding them as parameters:
Recipe builds can be removed via the clean command e.g.:
$ toolchain clean openssl
-
+
You can install package that don't require compilation with pip::
$ toolchain pip install plyer
@@ -324,3 +324,4 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
+
diff --git a/kivy_ios/context_managers.py b/kivy_ios/context_managers.py
new file mode 100644
index 0000000..9718f4f
--- /dev/null
+++ b/kivy_ios/context_managers.py
@@ -0,0 +1,46 @@
+"""
+This module houses context managers to assist in the managing of state during
+kivy-ios builds.
+"""
+from logging import getLogger
+from contextlib import contextmanager
+from os import getcwd, chdir, environ
+from os.path import expanduser
+
+
+logger = getLogger(__name__)
+
+
+@contextmanager
+def cd(newdir):
+ """
+ Set the current working directory to `newdir` for the duration of the
+ context.
+ """
+ prevdir = getcwd()
+ logger.info("cd {}".format(newdir))
+ chdir(expanduser(newdir))
+ try:
+ yield
+ finally:
+ logger.info("cd {}".format(prevdir))
+ chdir(prevdir)
+
+
+@contextmanager
+def python_path(newdir):
+ """
+ Set the PYTHONPATH environmnet variable to `newdir` for the duraiton of the
+ context.
+ """
+ prevdir = environ.get("PYTHONPATH")
+ logger.debug("Setting PYTHONPATH to {}".format(newdir))
+ environ["PYTHONPATH"] = newdir
+ try:
+ yield
+ finally:
+ logger.debug("Setting PYTHONPATH to {}".format(prevdir))
+ if prevdir is None:
+ environ.pop("PYTHONPATH")
+ else:
+ environ["PYTHONPATH"] = prevdir
diff --git a/kivy_ios/recipes/host_setuptools3/__init__.py b/kivy_ios/recipes/host_setuptools3/__init__.py
index 449c5c3..6cffa93 100644
--- a/kivy_ios/recipes/host_setuptools3/__init__.py
+++ b/kivy_ios/recipes/host_setuptools3/__init__.py
@@ -1,9 +1,10 @@
-from kivy_ios.toolchain import Recipe, shprint, cd, cache_execution
+from kivy_ios.toolchain import Recipe, shprint, cache_execution
+from kivy_ios.context_managers import cd, python_path
import sh
class HostSetuptools3(Recipe):
- depends = ["openssl", "hostpython3"]
+ depends = ["openssl", "hostpython3", "python3"]
archs = ["x86_64"]
version = '40.9.0'
url = 'https://pypi.python.org/packages/source/s/setuptools/setuptools-{version}.zip'
@@ -13,8 +14,11 @@ class HostSetuptools3(Recipe):
arch = self.filtered_archs[0]
build_dir = self.get_build_dir(arch.arch)
hostpython = sh.Command(self.ctx.hostpython)
- with cd(build_dir):
- shprint(hostpython, "setup.py", "install")
+
+ with python_path(self.ctx.site_packages_dir):
+ with cd(build_dir):
+ shprint(hostpython, "setup.py", "install",
+ f"--prefix={self.ctx.python_prefix}")
recipe = HostSetuptools3()
diff --git a/kivy_ios/recipes/hostpython3/__init__.py b/kivy_ios/recipes/hostpython3/__init__.py
index d5d1784..ca1d854 100644
--- a/kivy_ios/recipes/hostpython3/__init__.py
+++ b/kivy_ios/recipes/hostpython3/__init__.py
@@ -1,9 +1,11 @@
-from kivy_ios.toolchain import Recipe, cd, shprint
+from kivy_ios.toolchain import Recipe, shprint
from os.path import join
import os
import sh
import shutil
import logging
+from kivy_ios.context_managers import cd
+
logger = logging.getLogger(__name__)
diff --git a/kivy_ios/recipes/itsdangerous/__init__.py b/kivy_ios/recipes/itsdangerous/__init__.py
index d30dd9f..af48f75 100644
--- a/kivy_ios/recipes/itsdangerous/__init__.py
+++ b/kivy_ios/recipes/itsdangerous/__init__.py
@@ -1,5 +1,6 @@
# pure-python package, this can be removed when we'll support any python package
-from kivy_ios.toolchain import PythonRecipe, shprint, cd
+from kivy_ios.toolchain import PythonRecipe, shprint
+from kivy_ios.context_managers import cd
from os.path import join
import sh
diff --git a/kivy_ios/recipes/netifaces/__init__.py b/kivy_ios/recipes/netifaces/__init__.py
index 0209861..33757e0 100644
--- a/kivy_ios/recipes/netifaces/__init__.py
+++ b/kivy_ios/recipes/netifaces/__init__.py
@@ -2,7 +2,8 @@ import sh
from os.path import join
-from kivy_ios.toolchain import CythonRecipe, cd, shprint
+from kivy_ios.toolchain import CythonRecipe, shprint
+from kivy_ios.context_managers import cd
class NetifacesRecipe(CythonRecipe):
diff --git a/kivy_ios/recipes/pycrypto/__init__.py b/kivy_ios/recipes/pycrypto/__init__.py
index 97478c0..3c49c19 100644
--- a/kivy_ios/recipes/pycrypto/__init__.py
+++ b/kivy_ios/recipes/pycrypto/__init__.py
@@ -1,6 +1,7 @@
'''Recipe for pycrypto on ios
'''
-from kivy_ios.toolchain import CythonRecipe, shprint, cd
+from kivy_ios.toolchain import CythonRecipe, shprint
+from kivy_ios.context_managers import cd
from os.path import join
import sh
diff --git a/kivy_ios/recipes/python3/__init__.py b/kivy_ios/recipes/python3/__init__.py
index c6ed739..4ffb113 100644
--- a/kivy_ios/recipes/python3/__init__.py
+++ b/kivy_ios/recipes/python3/__init__.py
@@ -1,4 +1,5 @@
-from kivy_ios.toolchain import Recipe, shprint, cd
+from kivy_ios.toolchain import Recipe, shprint
+from kivy_ios.context_managers import cd
from os.path import join
import sh
import shutil
diff --git a/kivy_ios/toolchain.py b/kivy_ios/toolchain.py
index 67ee2a7..cd73afa 100755
--- a/kivy_ios/toolchain.py
+++ b/kivy_ios/toolchain.py
@@ -9,7 +9,7 @@ This tool intend to replace all the previous tools/ in shell script.
import argparse
import sys
from sys import stdout
-from os.path import join, dirname, realpath, exists, isdir, basename, expanduser
+from os.path import join, dirname, realpath, exists, isdir, basename
from os import listdir, unlink, makedirs, environ, chdir, getcwd, walk
import sh
import zipfile
@@ -21,7 +21,7 @@ import shutil
import fnmatch
import tempfile
import time
-from contextlib import contextmanager, suppress
+from contextlib import suppress
from datetime import datetime
from pprint import pformat
import logging
@@ -46,18 +46,6 @@ sh_logging.setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
-@contextmanager
-def cd(newdir):
- prevdir = getcwd()
- logger.info("cd {}".format(newdir))
- chdir(expanduser(newdir))
- try:
- yield
- finally:
- logger.info("cd {}".format(prevdir))
- chdir(prevdir)
-
-
def shprint(command, *args, **kwargs):
kwargs["_iter"] = True
kwargs["_out_bufsize"] = 1