Skip to content

Commit 85a3199

Browse files
committed
common pip_install_hostpython_package()
1 parent 733dd33 commit 85a3199

File tree

10 files changed

+20165
-90
lines changed

10 files changed

+20165
-90
lines changed

pythonforandroid/recipe.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from os.path import join, dirname, isdir, exists, isfile, split, realpath, basename
1+
from os.path import (join, dirname, normpath, isfile,
2+
isdir, exists, realpath, basename)
23
import importlib
3-
import zipfile
44
import glob
55
from shutil import rmtree
66
from six import PY2, with_metaclass
@@ -788,7 +788,6 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
788788
with current_directory(self.get_build_dir(arch.arch)):
789789
hostpython = sh.Command(self.hostpython_location)
790790

791-
792791
if self.ctx.python_recipe.from_crystax:
793792
hpenv = env.copy()
794793
shprint(hostpython, 'setup.py', 'install', '-O2',
@@ -819,7 +818,8 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
819818
def get_hostrecipe_env(self, arch):
820819
env = {}
821820
env['PATH'] = '/usr/local/bin:/usr/bin:/bin'
822-
env['PYTHONPATH'] = join(dirname(self.real_hostpython_location), 'Lib', 'site-packages')
821+
env['PYTHONPATH'] = join(dirname(self.real_hostpython_location),
822+
'Lib', 'site-packages')
823823
return env
824824

825825
def install_hostpython_package(self, arch):
@@ -830,6 +830,22 @@ def install_hostpython_package(self, arch):
830830
'--install-lib=Lib/site-packages',
831831
_env=env, *self.setup_extra_args)
832832

833+
def pip_install_hostpython_package(self, arch):
834+
""" calling recipe build_arch() must hast 'host_pip' in depends[] """
835+
package = (self.name + '==' + self.version if hasattr(self, 'version')
836+
else self.name)
837+
env = self.get_hostrecipe_env(arch)
838+
real_hostpython = sh.Command(self.real_hostpython_location)
839+
build_dir = normpath(join(dirname(self.real_hostpython_location),
840+
'..', self.name))
841+
target_dir = env['PYTHONPATH']
842+
ensure_dir(build_dir)
843+
with current_directory(build_dir):
844+
shprint(real_hostpython, '-mpip', 'install', '--upgrade', package,
845+
"--build={}".format(build_dir),
846+
"--target={}".format(target_dir),
847+
_env=env, *self.setup_extra_args)
848+
833849

834850
class CompiledComponentsPythonRecipe(PythonRecipe):
835851
pre_build_ext = False

pythonforandroid/recipes/cryptography/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ class CryptographyRecipe(CompiledComponentsPythonRecipe):
55
name = 'cryptography'
66
version = 'master'
77
url = 'git+file:///home/enoch/cryptography'
8-
depends = ['hostcffi', 'idna', 'asn1crypto', 'six',
9-
'cffi', 'enum34', 'ipaddress', 'openssl']
8+
depends = ['host_cffi', 'host_setuptools', 'host_sh',
9+
'idna', 'asn1crypto', 'six', 'cffi',
10+
'enum34', 'ipaddress', 'openssl']
1011

1112
call_hostpython_via_targetpython = False
1213

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pythonforandroid.recipe import PythonRecipe
2+
3+
4+
class Host_cffi_recipe(PythonRecipe):
5+
name = 'cffi'
6+
version = '1.11.2'
7+
8+
depends = ['host_pip']
9+
10+
def unpack(self, arch):
11+
return
12+
13+
def build_arch(self, arch):
14+
self.pip_install_hostpython_package(arch)
15+
16+
17+
recipe = Host_cffi_recipe()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from os.path import dirname, join, normpath
2+
from sh import Command
3+
from pythonforandroid.recipe import PythonRecipe
4+
from pythonforandroid.util import current_directory, ensure_dir
5+
from pythonforandroid.logger import shprint
6+
7+
8+
class Host_pip_recipe(PythonRecipe):
9+
name = 'pip'
10+
url = 'https://bootstrap.pypa.io/get-pip.py'
11+
12+
depends = ['hostpython2']
13+
14+
def unpack(self, arch):
15+
return
16+
17+
def build_arch(self, arch):
18+
env = self.get_hostrecipe_env(arch)
19+
real_hostpython = Command(self.real_hostpython_location)
20+
script = join(self.ctx.packages_path, 'pip', 'get-pip.py')
21+
build_dir = normpath(join(dirname(self.real_hostpython_location),
22+
'..', self.name))
23+
target_dir = env['PYTHONPATH']
24+
ensure_dir(build_dir)
25+
with current_directory(build_dir):
26+
shprint(real_hostpython, script,
27+
"--build={}".format(build_dir),
28+
"--target={}".format(target_dir),
29+
_env=env)
30+
31+
32+
recipe = Host_pip_recipe()

0 commit comments

Comments
 (0)