1
1
2
2
from pythonforandroid .recipe import TargetPythonRecipe
3
3
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
6
6
from os .path import exists , join
7
- from os import uname
8
7
import glob
9
8
import sh
10
9
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
+
11
14
class Python3Recipe (TargetPythonRecipe ):
12
15
version = '3.5'
13
16
url = ''
@@ -24,19 +27,50 @@ def get_dir_name(self):
24
27
return name
25
28
26
29
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.
28
67
29
68
dirn = self .ctx .get_python_install_dir ()
30
69
ensure_dir (dirn )
31
70
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.
32
74
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'))
41
75
42
76
recipe = Python3Recipe ()
0 commit comments