@@ -76,10 +76,9 @@ int main(int argc, char *argv[]) {
76
76
int ret = 0 ;
77
77
FILE * fd ;
78
78
79
- /* AND: Several filepaths are hardcoded here, these must be made
80
- configurable */
81
- /* AND: P4A uses env vars...not sure what's best */
82
- LOGP ("Initialize Python for Android" );
79
+ setenv ("P4A_BOOTSTRAP" , "SDL2" , 1 ); // env var to identify p4a to applications
80
+
81
+ LOGP ("Initializing Python for Android" );
83
82
env_argument = getenv ("ANDROID_ARGUMENT" );
84
83
setenv ("ANDROID_APP_PATH" , env_argument , 1 );
85
84
env_entrypoint = getenv ("ANDROID_ENTRYPOINT" );
@@ -109,32 +108,47 @@ int main(int argc, char *argv[]) {
109
108
110
109
LOGP ("Preparing to initialize python" );
111
110
111
+ // Set up the python path
112
+ char paths [256 ];
113
+
112
114
char crystax_python_dir [256 ];
113
115
snprintf (crystax_python_dir , 256 ,
114
116
"%s/crystax_python" , getenv ("ANDROID_UNPACK" ));
115
- if (dir_exists (crystax_python_dir )) {
116
- LOGP ("crystax_python exists" );
117
- char paths [256 ];
118
- snprintf (paths , 256 ,
119
- "%s/stdlib.zip:%s/modules" ,
120
- crystax_python_dir , crystax_python_dir );
121
- /* snprintf(paths, 256, "%s/stdlib.zip:%s/modules", env_argument,
122
- * env_argument); */
123
- LOGP ("calculated paths to be..." );
124
- LOGP (paths );
117
+ char python_bundle_dir [256 ];
118
+ snprintf (python_bundle_dir , 256 ,
119
+ "%s/_python_bundle" , getenv ("ANDROID_UNPACK" ));
120
+ if (dir_exists (crystax_python_dir ) || dir_exists (python_bundle_dir )) {
121
+ if (dir_exists (crystax_python_dir )) {
122
+ LOGP ("crystax_python exists" );
123
+ snprintf (paths , 256 ,
124
+ "%s/stdlib.zip:%s/modules" ,
125
+ crystax_python_dir , crystax_python_dir );
126
+ LOGP ("calculated paths to be..." );
127
+ LOGP (paths );
128
+ }
129
+
130
+ if (dir_exists (python_bundle_dir )) {
131
+ LOGP ("_python_bundle dir exists" );
132
+ snprintf (paths , 256 ,
133
+ "%s/stdlib.zip:%s/modules" ,
134
+ python_bundle_dir , python_bundle_dir );
135
+ LOGP ("calculated paths to be..." );
136
+ LOGP (paths );
137
+ }
125
138
126
- #if PY_MAJOR_VERSION >= 3
127
- wchar_t * wchar_paths = Py_DecodeLocale (paths , NULL );
128
- Py_SetPath (wchar_paths );
129
- #else
130
- char * wchar_paths = paths ;
131
- LOGP ("Can't Py_SetPath in python2, so crystax python2 doesn't work yet" );
132
- exit (1 );
133
- #endif
134
139
135
- LOGP ("set wchar paths..." );
140
+ #if PY_MAJOR_VERSION >= 3
141
+ wchar_t * wchar_paths = Py_DecodeLocale (paths , NULL );
142
+ Py_SetPath (wchar_paths );
143
+ #else
144
+ char * wchar_paths = paths ;
145
+ LOGP ("Can't Py_SetPath in python2, so crystax python2 doesn't work yet" );
146
+ exit (1 );
147
+ #endif
148
+
149
+ LOGP ("set wchar paths..." );
136
150
} else {
137
- LOGP ("crystax_python does not exist" );
151
+ LOGP ("crystax_python does not exist" );
138
152
}
139
153
140
154
Py_Initialize ();
@@ -174,8 +188,8 @@ int main(int argc, char *argv[]) {
174
188
" argument ]\n" );
175
189
}
176
190
191
+ char add_site_packages_dir [256 ];
177
192
if (dir_exists (crystax_python_dir )) {
178
- char add_site_packages_dir [256 ];
179
193
snprintf (add_site_packages_dir , 256 ,
180
194
"sys.path.append('%s/site-packages')" ,
181
195
crystax_python_dir );
@@ -188,6 +202,19 @@ int main(int argc, char *argv[]) {
188
202
PyRun_SimpleString ("sys.path = ['.'] + sys.path" );
189
203
}
190
204
205
+ if (dir_exists (python_bundle_dir )) {
206
+ snprintf (add_site_packages_dir , 256 ,
207
+ "sys.path.append('%s/site-packages')" ,
208
+ python_bundle_dir );
209
+
210
+ PyRun_SimpleString ("import sys\n"
211
+ "sys.argv = ['notaninterpreterreally']\n"
212
+ "from os.path import realpath, join, dirname" );
213
+ PyRun_SimpleString (add_site_packages_dir );
214
+ /* "sys.path.append(join(dirname(realpath(__file__)), 'site-packages'))") */
215
+ PyRun_SimpleString ("sys.path = ['.'] + sys.path" );
216
+ }
217
+
191
218
PyRun_SimpleString (
192
219
"class LogFile(object):\n"
193
220
" def __init__(self):\n"
@@ -317,6 +344,7 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
317
344
setenv ("PYTHONHOME" , python_home , 1 );
318
345
setenv ("PYTHONPATH" , python_path , 1 );
319
346
setenv ("PYTHON_SERVICE_ARGUMENT" , arg , 1 );
347
+ setenv ("P4A_BOOTSTRAP" , "SDL2" , 1 );
320
348
321
349
char * argv [] = {"." };
322
350
/* ANDROID_ARGUMENT points to service subdir,
0 commit comments