Repository: kivy/python-for-android

Issue:
python3 incompatibility
Running python-for-android (master) with 'python3crystax' and 'storm' requirements fails, even though the 'storm' recipe is specified to run with python3.

`/usr/bin/python -m pythonforandroid.toolchain create --dist_name=testApp --bootstrap=sdl2 --requirements=python3crystax,kivy==master,sqlite3,storm --arch armeabi-v7a --copy-libs --color=always --storage-dir=/home/shaana/development/test1/src/.buildozer/android/platform/build`

```
[INFO]:    Building storm for armeabi-v7a
[INFO]:    storm apparently isn't already in site-packages
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/shaana/development/test1/src/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 992, in <module>
    main()
  File "/home/shaana/development/test1/src/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 989, in main
    ToolchainCL()
  File "/home/shaana/development/test1/src/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 526, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/shaana/development/test1/src/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 149, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/shaana/development/test1/src/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 194, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx)
  File "pythonforandroid/build.py", line 574, in build_recipes
    recipe.build_arch(arch)
  File "pythonforandroid/recipe.py", line 806, in build_arch
    self.install_python_package(arch)
  File "pythonforandroid/recipe.py", line 815, in install_python_package
    env = self.get_recipe_env(arch)
  File "pythonforandroid/recipe.py", line 786, in get_recipe_env
    hppath += [join(builddir, d) for d in listdir(builddir)
OSError: [Errno 2] No such file or directory: 'build'
```
Removing the following lines from the recipe might solve the issue.
```
    call_hostpython_via_targetpython = False
    install_in_hostpython = True
```

There are probably other recipes with the same issue.




Discussion:

Resolving patch:
diff --git a/pythonforandroid/recipe.py b/pythonforandroid/recipe.py
--- a/pythonforandroid/recipe.py
+++ b/pythonforandroid/recipe.py
@@ -732,6 +732,10 @@ def real_hostpython_location(self):
             return join(
                 Recipe.get_recipe('hostpython2', self.ctx).get_build_dir(),
                 'hostpython')
+        elif 'hostpython3crystax' in self.ctx.recipe_build_order:
+            return join(
+                Recipe.get_recipe('hostpython3crystax', self.ctx).get_build_dir(),
+                'hostpython')
         else:
             python_recipe = self.ctx.python_recipe
             return 'python{}'.format(python_recipe.version)
diff --git a/pythonforandroid/recipes/hostpython3crystax/__init__.py b/pythonforandroid/recipes/hostpython3crystax/__init__.py
--- a/pythonforandroid/recipes/hostpython3crystax/__init__.py
+++ b/pythonforandroid/recipes/hostpython3crystax/__init__.py
@@ -1,7 +1,5 @@
-
-from pythonforandroid.toolchain import Recipe, shprint, current_directory, info, warning
-from os.path import join, exists
-from os import chdir
+from pythonforandroid.toolchain import Recipe, shprint
+from os.path import join
 import sh
 
 
@@ -13,14 +11,32 @@ class Hostpython3Recipe(Recipe):
 
     conflicts = ['hostpython2']
 
+    def get_build_container_dir(self, arch=None):
+        choices = self.check_recipe_choices()
+        dir_name = '-'.join([self.name] + choices)
+        return join(self.ctx.build_dir, 'other_builds', dir_name, 'desktop')
+
     # def prebuild_armeabi(self):
     #     # Override hostpython Setup?
     #     shprint(sh.cp, join(self.get_recipe_dir(), 'Setup'),
     #             join(self.get_build_dir('armeabi'), 'Modules', 'Setup'))
 
+    def get_build_dir(self, arch=None):
+        return join(self.get_build_container_dir(), self.name)
+
     def build_arch(self, arch):
+        """
+        Creates expected build and symlinks system Python version.
+        """
         self.ctx.hostpython = '/usr/bin/false'
         self.ctx.hostpgen = '/usr/bin/false'
+        # creates the sub buildir (used by other recipes)
+        # https://github.com/kivy/python-for-android/issues/1154
+        sub_build_dir = join(self.get_build_dir(), 'build')
+        shprint(sh.mkdir, '-p', sub_build_dir)
+        system_python = sh.which("python" + self.version)
+        link_dest = join(self.get_build_dir(), 'hostpython')
+        shprint(sh.ln, '-sf', system_python, link_dest)
 
 
 recipe = Hostpython3Recipe()


Test patch: