Skip to content

Commit e5f23a5

Browse files
committed
Made python3crystax download python 3.6 if necessary
1 parent 6b31b13 commit e5f23a5

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed
Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11

22
from pythonforandroid.recipe import TargetPythonRecipe
33
from pythonforandroid.toolchain import shprint, current_directory, ArchARM
4-
from pythonforandroid.logger import info
5-
from pythonforandroid.util import ensure_dir
4+
from pythonforandroid.logger import info, error
5+
from pythonforandroid.util import ensure_dir, temp_directory
66
from os.path import exists, join
7-
from os import uname
87
import glob
98
import sh
109

10+
prebuilt_download_locations = {
11+
'3.6': ('https://github.com/inclement/crystax_python_builds/'
12+
'releases/download/0.1/crystax_python_3.6_armeabi_armeabi-v7a.tar.gz')}
13+
1114
class Python3Recipe(TargetPythonRecipe):
1215
version = '3.5'
1316
url = ''
@@ -24,19 +27,50 @@ def get_dir_name(self):
2427
return name
2528

2629
def build_arch(self, arch):
27-
info('Extracting CrystaX python3 from NDK package')
30+
# We don't have to actually build anything as CrystaX comes
31+
# with the necessary modules. They are included by modifying
32+
# the Android.mk in the jni folder.
33+
34+
# If the Python version to be used is not prebuilt with the CrystaX
35+
# NDK, we do have to download it.
36+
37+
crystax_python_dir = join(self.ctx.ndk_dir, 'sources', 'python')
38+
if not exists(join(crystax_python_dir, self.version)):
39+
info(('The NDK does not have a prebuilt Python {}, trying '
40+
'to obtain one.').format(self.version))
41+
42+
if self.version not in prebuilt_download_locations:
43+
error(('No prebuilt version for Python {} could be found, '
44+
'the built cannot continue.'))
45+
exit(1)
46+
47+
with temp_directory() as td:
48+
self.download_file(prebuilt_download_locations[self.version],
49+
join(td, 'downloaded_python'))
50+
shprint(sh.tar, 'xf', join(td, 'downloaded_python'),
51+
'--directory', crystax_python_dir)
52+
53+
if not exists(join(crystax_python_dir, self.version)):
54+
error(('Something went wrong, the directory at {} should '
55+
'have been created but does not exist.').format(
56+
join(crystax_python_dir, self.version)))
57+
58+
if not exists(join(
59+
crystax_python_dir, self.version, 'libs', arch.arch)):
60+
error(('The prebuilt Python for version {} does not contain '
61+
'binaries for your chosen architecture "{}".').format(
62+
self.version, arch.arch))
63+
exit(1)
64+
65+
# TODO: We should have an option to build a new Python. This
66+
# would also allow linking to openssl and sqlite from CrystaX.
2867

2968
dirn = self.ctx.get_python_install_dir()
3069
ensure_dir(dirn)
3170

71+
# Instead of using a locally built hostpython, we use the
72+
# user's Python for now. They must have the right version
73+
# available. Using e.g. pyenv makes this easy.
3274
self.ctx.hostpython = 'python{}'.format(self.version)
33-
# ensure_dir(join(dirn, 'lib'))
34-
# ensure_dir(join(dirn, 'lib', 'python{}'.format(self.version),
35-
# 'site-packages'))
36-
37-
# ndk_dir = self.ctx.ndk_dir
38-
# sh.cp('-r', '/home/asandy/kivytest/crystax_stdlib', join(dirn, 'lib', 'python3.5'))
39-
# sh.cp('-r', '/home/asandy/android/crystax-ndk-10.3.0/sources/python/3.5/libs/armeabi/modules', join(dirn, 'lib', 'python3.5', 'lib-dynload'))
40-
# ensure_dir(join(dirn, 'lib', 'site-packages'))
4175

4276
recipe = Python3Recipe()

0 commit comments

Comments
 (0)