@@ -76,10 +76,9 @@ int main(int argc, char *argv[]) {
7676 int ret = 0 ;
7777 FILE * fd ;
7878
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" );
8382 env_argument = getenv ("ANDROID_ARGUMENT" );
8483 setenv ("ANDROID_APP_PATH" , env_argument , 1 );
8584 env_entrypoint = getenv ("ANDROID_ENTRYPOINT" );
@@ -109,32 +108,47 @@ int main(int argc, char *argv[]) {
109108
110109 LOGP ("Preparing to initialize python" );
111110
111+ // Set up the python path
112+ char paths [256 ];
113+
112114 char crystax_python_dir [256 ];
113115 snprintf (crystax_python_dir , 256 ,
114116 "%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+ }
125138
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
134139
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..." );
136150 } else {
137- LOGP ("crystax_python does not exist" );
151+ LOGP ("crystax_python does not exist" );
138152 }
139153
140154 Py_Initialize ();
@@ -174,8 +188,8 @@ int main(int argc, char *argv[]) {
174188 " argument ]\n" );
175189 }
176190
191+ char add_site_packages_dir [256 ];
177192 if (dir_exists (crystax_python_dir )) {
178- char add_site_packages_dir [256 ];
179193 snprintf (add_site_packages_dir , 256 ,
180194 "sys.path.append('%s/site-packages')" ,
181195 crystax_python_dir );
@@ -188,6 +202,19 @@ int main(int argc, char *argv[]) {
188202 PyRun_SimpleString ("sys.path = ['.'] + sys.path" );
189203 }
190204
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+
191218 PyRun_SimpleString (
192219 "class LogFile(object):\n"
193220 " def __init__(self):\n"
@@ -317,6 +344,7 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
317344 setenv ("PYTHONHOME" , python_home , 1 );
318345 setenv ("PYTHONPATH" , python_path , 1 );
319346 setenv ("PYTHON_SERVICE_ARGUMENT" , arg , 1 );
347+ setenv ("P4A_BOOTSTRAP" , "SDL2" , 1 );
320348
321349 char * argv [] = {"." };
322350 /* ANDROID_ARGUMENT points to service subdir,
0 commit comments