prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Numpy support w/ python3crystax
  I'm trying to get my app to compile with Python 3 using the Crystax NDK.  Everything is set up, and if I try to push my app to my device without specifying that numpy is needed, everything works fine.  However, numpy raises a few issues:
  1. (easily fixed) The recipe needs to be modified such that python3crystax is supported.  Currently, it only claims python2 support, but that's overridden easily enough (`depends = ['python2']` -> `depends = [('python3crystax', 'python2)]` in the `__init__.py`).
  2. The compiler claims it can't find -lcrystax:
  
  ``` sh
  ...
  don't know how to compile Fortran code on platform 'posix'
  C compiler: /usr/bin/ccache arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/wwoods/walt/dev/kivy/crystax-ndk-10.3.2/platforms/android-19/arch-arm -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/wwoods/walt/dev/kivy/crystax-ndk-10.3.2/platforms/android-19/arch-arm -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -fPIC
  
  compile options: '-Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/home/wwoods/miniconda3/envs/kivy/include/python3.5m -c'
  ccache: _configtest.c
  /usr/bin/ccache arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/wwoods/walt/dev/kivy/crystax-ndk-10.3.2/platforms/android-19/arch-arm _configtest.o -o _configtest
  /home/wwoods/walt/dev/kivy/crystax-ndk-10.3.2/toolchains/arm-linux-androideabi-5/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/5.3/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lcrystax
  collect2: error: ld returned 1 exit status
  /home/wwoods/walt/dev/kivy/crystax-ndk-10.3.2/toolchains/arm-linux-androideabi-5/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/5.3/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lcrystax
  collect2: error: ld returned 1 exit status
  failure.
  removing: _configtest.c _configtest.o
  ```
  
  Everything except numpy works fine, so I think that it's just Numpy's recipe that needs a minor alteration.  Oddly though, specifying a LIBRARY_PATH or LDFLAGS does not have any effect.  In fact, if I add a `get_recipe_env` to the `NumpyRecipe` that prints out what `super().get_recipe_env(arch)` contains, it has LDFLAGS with the appropriate path on there.  Running the linker by hand with the given flags find the library fine (`ld $(LDFLAGS) -lcrystax --verbose`).  In the context of python-for-android though, the linker always fails to find libcrystax.a.
  
  Any help appreciated, thanks.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pythonforandroid/recipes/numpy/__init__.py`
  Content:
  ```
  1 from pythonforandroid.recipe import CompiledComponentsPythonRecipe
  2 from pythonforandroid.toolchain import warning
  3 
  4 
  5 class NumpyRecipe(CompiledComponentsPythonRecipe):
  6 
  7     version = '1.9.2'
  8     url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.tar.gz'
  9     site_packages_name= 'numpy'
  10 
  11     depends = ['python2']
  12 
  13     patches = ['patches/fix-numpy.patch',
  14                'patches/prevent_libs_check.patch',
  15                'patches/ar.patch',
  16                'patches/lib.patch']
  17 
  18     def get_recipe_env(self, arch):
  19         """ looks like numpy has no proper -L flags. Code copied and adapted from
  20             https://github.com/frmdstryr/p4a-numpy/
  21         """
  22 
  23         env = super(NumpyRecipe, self).get_recipe_env(arch)
  24         #: Hack add path L to crystax as a CFLAG
  25 
  26         py_ver = '3.5'
  27         if {'python2crystax', 'python2'} & set(self.ctx.recipe_build_order):
  28             py_ver = '2.7'
  29 
  30         py_so = '2.7' if py_ver == '2.7' else '3.5m'
  31 
  32         api_ver = self.ctx.android_api
  33 
  34         platform = 'arm' if 'arm' in arch.arch else arch.arch
  35         #: Not sure why but we have to inject these into the CC and LD env's for it to
  36         #: use the correct arguments.
  37         flags = " -L{ctx.ndk_dir}/platforms/android-{api_ver}/arch-{platform}/usr/lib/" \
  38                 " --sysroot={ctx.ndk_dir}/platforms/android-{api_ver}/arch-{platform}" \
  39             .format(ctx=self.ctx, arch=arch, platform=platform, api_ver=api_ver,
  40                     py_so=py_so, py_ver=py_ver)
  41         if flags not in env['CC']:
  42             env['CC'] += flags
  43         if flags not in env['LD']:
  44             env['LD'] += flags + ' -shared'
  45 
  46         return env
  47 
  48     def prebuild_arch(self, arch):
  49         super(NumpyRecipe, self).prebuild_arch(arch)
  50 
  51         warning('Numpy is built assuming the archiver name is '
  52                 'arm-linux-androideabi-ar, which may not always be true!')
  53 
  54 
  55 recipe = NumpyRecipe()
  56
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pythonforandroid/recipes/numpy/__init__.py b/pythonforandroid/recipes/numpy/__init__.py
  --- a/pythonforandroid/recipes/numpy/__init__.py
  +++ b/pythonforandroid/recipes/numpy/__init__.py
  @@ -1,48 +1,48 @@
   from pythonforandroid.recipe import CompiledComponentsPythonRecipe
   from pythonforandroid.toolchain import warning
  +from os.path import join
   
   
   class NumpyRecipe(CompiledComponentsPythonRecipe):
   
  -    version = '1.9.2'
  -    url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.tar.gz'
  -    site_packages_name= 'numpy'
  +    version = '1.15.1'
  +    url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.zip'
  +    site_packages_name = 'numpy'
   
  -    depends = ['python2']
  +    depends = [('python2', 'python3crystax')]
   
  -    patches = ['patches/fix-numpy.patch',
  -               'patches/prevent_libs_check.patch',
  -               'patches/ar.patch',
  -               'patches/lib.patch']
  +    patches = [
  +        join('patches', 'fix-numpy.patch'),
  +        join('patches', 'prevent_libs_check.patch'),
  +        join('patches', 'ar.patch'),
  +        join('patches', 'lib.patch'),
  +        join('patches', 'python2-fixes.patch')
  +    ]
   
       def get_recipe_env(self, arch):
  -        """ looks like numpy has no proper -L flags. Code copied and adapted from
  -            https://github.com/frmdstryr/p4a-numpy/
  -        """
  -
           env = super(NumpyRecipe, self).get_recipe_env(arch)
  -        #: Hack add path L to crystax as a CFLAG
  -
  -        py_ver = '3.5'
  -        if {'python2crystax', 'python2'} & set(self.ctx.recipe_build_order):
  -            py_ver = '2.7'
   
  -        py_so = '2.7' if py_ver == '2.7' else '3.5m'
  +        flags = " -L{} --sysroot={}".format(
  +            join(self.ctx.ndk_platform, 'usr', 'lib'),
  +            self.ctx.ndk_platform
  +        )
  +
  +        if self.ctx.ndk == 'crystax':
  +            py_ver = self.ctx.python_recipe.version[0:3]
  +            src_dir = join(self.ctx.ndk_dir, 'sources')
  +            py_inc_dir = join(src_dir, 'python', py_ver, 'include', 'python')
  +            py_lib_dir = join(src_dir, 'python', py_ver, 'libs', arch.arch)
  +            cry_inc_dir = join(src_dir, 'crystax', 'include')
  +            cry_lib_dir = join(src_dir, 'crystax', 'libs', arch.arch)
  +            flags += ' -I{}'.format(py_inc_dir)
  +            flags += ' -L{} -lpython{}m'.format(py_lib_dir, py_ver)
  +            flags += " -I{}".format(cry_inc_dir)
  +            flags += " -L{}".format(cry_lib_dir)
   
  -        api_ver = self.ctx.android_api
  -
  -        platform = 'arm' if 'arm' in arch.arch else arch.arch
  -        #: Not sure why but we have to inject these into the CC and LD env's for it to
  -        #: use the correct arguments.
  -        flags = " -L{ctx.ndk_dir}/platforms/android-{api_ver}/arch-{platform}/usr/lib/" \
  -                " --sysroot={ctx.ndk_dir}/platforms/android-{api_ver}/arch-{platform}" \
  -            .format(ctx=self.ctx, arch=arch, platform=platform, api_ver=api_ver,
  -                    py_so=py_so, py_ver=py_ver)
           if flags not in env['CC']:
               env['CC'] += flags
           if flags not in env['LD']:
               env['LD'] += flags + ' -shared'
  -
           return env
   
       def prebuild_arch(self, arch):
  
verification_info: {"golden_diff": "diff --git a/pythonforandroid/recipes/numpy/__init__.py b/pythonforandroid/recipes/numpy/__init__.py\n--- a/pythonforandroid/recipes/numpy/__init__.py\n+++ b/pythonforandroid/recipes/numpy/__init__.py\n@@ -1,48 +1,48 @@\n from pythonforandroid.recipe import CompiledComponentsPythonRecipe\n from pythonforandroid.toolchain import warning\n+from os.path import join\n \n \n class NumpyRecipe(CompiledComponentsPythonRecipe):\n \n-    version = '1.9.2'\n-    url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.tar.gz'\n-    site_packages_name= 'numpy'\n+    version = '1.15.1'\n+    url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.zip'\n+    site_packages_name = 'numpy'\n \n-    depends = ['python2']\n+    depends = [('python2', 'python3crystax')]\n \n-    patches = ['patches/fix-numpy.patch',\n-               'patches/prevent_libs_check.patch',\n-               'patches/ar.patch',\n-               'patches/lib.patch']\n+    patches = [\n+        join('patches', 'fix-numpy.patch'),\n+        join('patches', 'prevent_libs_check.patch'),\n+        join('patches', 'ar.patch'),\n+        join('patches', 'lib.patch'),\n+        join('patches', 'python2-fixes.patch')\n+    ]\n \n     def get_recipe_env(self, arch):\n-        \"\"\" looks like numpy has no proper -L flags. Code copied and adapted from\n-            https://github.com/frmdstryr/p4a-numpy/\n-        \"\"\"\n-\n         env = super(NumpyRecipe, self).get_recipe_env(arch)\n-        #: Hack add path L to crystax as a CFLAG\n-\n-        py_ver = '3.5'\n-        if {'python2crystax', 'python2'} & set(self.ctx.recipe_build_order):\n-            py_ver = '2.7'\n \n-        py_so = '2.7' if py_ver == '2.7' else '3.5m'\n+        flags = \" -L{} --sysroot={}\".format(\n+            join(self.ctx.ndk_platform, 'usr', 'lib'),\n+            self.ctx.ndk_platform\n+        )\n+\n+        if self.ctx.ndk == 'crystax':\n+            py_ver = self.ctx.python_recipe.version[0:3]\n+            src_dir = join(self.ctx.ndk_dir, 'sources')\n+            py_inc_dir = join(src_dir, 'python', py_ver, 'include', 'python')\n+            py_lib_dir = join(src_dir, 'python', py_ver, 'libs', arch.arch)\n+            cry_inc_dir = join(src_dir, 'crystax', 'include')\n+            cry_lib_dir = join(src_dir, 'crystax', 'libs', arch.arch)\n+            flags += ' -I{}'.format(py_inc_dir)\n+            flags += ' -L{} -lpython{}m'.format(py_lib_dir, py_ver)\n+            flags += \" -I{}\".format(cry_inc_dir)\n+            flags += \" -L{}\".format(cry_lib_dir)\n \n-        api_ver = self.ctx.android_api\n-\n-        platform = 'arm' if 'arm' in arch.arch else arch.arch\n-        #: Not sure why but we have to inject these into the CC and LD env's for it to\n-        #: use the correct arguments.\n-        flags = \" -L{ctx.ndk_dir}/platforms/android-{api_ver}/arch-{platform}/usr/lib/\" \\\n-                \" --sysroot={ctx.ndk_dir}/platforms/android-{api_ver}/arch-{platform}\" \\\n-            .format(ctx=self.ctx, arch=arch, platform=platform, api_ver=api_ver,\n-                    py_so=py_so, py_ver=py_ver)\n         if flags not in env['CC']:\n             env['CC'] += flags\n         if flags not in env['LD']:\n             env['LD'] += flags + ' -shared'\n-\n         return env\n \n     def prebuild_arch(self, arch):\n", "issue": "Numpy support w/ python3crystax\nI'm trying to get my app to compile with Python 3 using the Crystax NDK.  Everything is set up, and if I try to push my app to my device without specifying that numpy is needed, everything works fine.  However, numpy raises a few issues:\n1. (easily fixed) The recipe needs to be modified such that python3crystax is supported.  Currently, it only claims python2 support, but that's overridden easily enough (`depends = ['python2']` -> `depends = [('python3crystax', 'python2)]` in the `__init__.py`).\n2. The compiler claims it can't find -lcrystax:\n\n``` sh\n...\ndon't know how to compile Fortran code on platform 'posix'\nC compiler: /usr/bin/ccache arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/wwoods/walt/dev/kivy/crystax-ndk-10.3.2/platforms/android-19/arch-arm -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/wwoods/walt/dev/kivy/crystax-ndk-10.3.2/platforms/android-19/arch-arm -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb -fPIC\n\ncompile options: '-Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/home/wwoods/miniconda3/envs/kivy/include/python3.5m -c'\nccache: _configtest.c\n/usr/bin/ccache arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/wwoods/walt/dev/kivy/crystax-ndk-10.3.2/platforms/android-19/arch-arm _configtest.o -o _configtest\n/home/wwoods/walt/dev/kivy/crystax-ndk-10.3.2/toolchains/arm-linux-androideabi-5/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/5.3/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lcrystax\ncollect2: error: ld returned 1 exit status\n/home/wwoods/walt/dev/kivy/crystax-ndk-10.3.2/toolchains/arm-linux-androideabi-5/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/5.3/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lcrystax\ncollect2: error: ld returned 1 exit status\nfailure.\nremoving: _configtest.c _configtest.o\n```\n\nEverything except numpy works fine, so I think that it's just Numpy's recipe that needs a minor alteration.  Oddly though, specifying a LIBRARY_PATH or LDFLAGS does not have any effect.  In fact, if I add a `get_recipe_env` to the `NumpyRecipe` that prints out what `super().get_recipe_env(arch)` contains, it has LDFLAGS with the appropriate path on there.  Running the linker by hand with the given flags find the library fine (`ld $(LDFLAGS) -lcrystax --verbose`).  In the context of python-for-android though, the linker always fails to find libcrystax.a.\n\nAny help appreciated, thanks.\n\n", "before_files": [{"content": "from pythonforandroid.recipe import CompiledComponentsPythonRecipe\nfrom pythonforandroid.toolchain import warning\n\n\nclass NumpyRecipe(CompiledComponentsPythonRecipe):\n\n    version = '1.9.2'\n    url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.tar.gz'\n    site_packages_name= 'numpy'\n\n    depends = ['python2']\n\n    patches = ['patches/fix-numpy.patch',\n               'patches/prevent_libs_check.patch',\n               'patches/ar.patch',\n               'patches/lib.patch']\n\n    def get_recipe_env(self, arch):\n        \"\"\" looks like numpy has no proper -L flags. Code copied and adapted from\n            https://github.com/frmdstryr/p4a-numpy/\n        \"\"\"\n\n        env = super(NumpyRecipe, self).get_recipe_env(arch)\n        #: Hack add path L to crystax as a CFLAG\n\n        py_ver = '3.5'\n        if {'python2crystax', 'python2'} & set(self.ctx.recipe_build_order):\n            py_ver = '2.7'\n\n        py_so = '2.7' if py_ver == '2.7' else '3.5m'\n\n        api_ver = self.ctx.android_api\n\n        platform = 'arm' if 'arm' in arch.arch else arch.arch\n        #: Not sure why but we have to inject these into the CC and LD env's for it to\n        #: use the correct arguments.\n        flags = \" -L{ctx.ndk_dir}/platforms/android-{api_ver}/arch-{platform}/usr/lib/\" \\\n                \" --sysroot={ctx.ndk_dir}/platforms/android-{api_ver}/arch-{platform}\" \\\n            .format(ctx=self.ctx, arch=arch, platform=platform, api_ver=api_ver,\n                    py_so=py_so, py_ver=py_ver)\n        if flags not in env['CC']:\n            env['CC'] += flags\n        if flags not in env['LD']:\n            env['LD'] += flags + ' -shared'\n\n        return env\n\n    def prebuild_arch(self, arch):\n        super(NumpyRecipe, self).prebuild_arch(arch)\n\n        warning('Numpy is built assuming the archiver name is '\n                'arm-linux-androideabi-ar, which may not always be true!')\n\n\nrecipe = NumpyRecipe()\n", "path": "pythonforandroid/recipes/numpy/__init__.py"}], "after_files": [{"content": "from pythonforandroid.recipe import CompiledComponentsPythonRecipe\nfrom pythonforandroid.toolchain import warning\nfrom os.path import join\n\n\nclass NumpyRecipe(CompiledComponentsPythonRecipe):\n\n    version = '1.15.1'\n    url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.zip'\n    site_packages_name = 'numpy'\n\n    depends = [('python2', 'python3crystax')]\n\n    patches = [\n        join('patches', 'fix-numpy.patch'),\n        join('patches', 'prevent_libs_check.patch'),\n        join('patches', 'ar.patch'),\n        join('patches', 'lib.patch'),\n        join('patches', 'python2-fixes.patch')\n    ]\n\n    def get_recipe_env(self, arch):\n        env = super(NumpyRecipe, self).get_recipe_env(arch)\n\n        flags = \" -L{} --sysroot={}\".format(\n            join(self.ctx.ndk_platform, 'usr', 'lib'),\n            self.ctx.ndk_platform\n        )\n\n        if self.ctx.ndk == 'crystax':\n            py_ver = self.ctx.python_recipe.version[0:3]\n            src_dir = join(self.ctx.ndk_dir, 'sources')\n            py_inc_dir = join(src_dir, 'python', py_ver, 'include', 'python')\n            py_lib_dir = join(src_dir, 'python', py_ver, 'libs', arch.arch)\n            cry_inc_dir = join(src_dir, 'crystax', 'include')\n            cry_lib_dir = join(src_dir, 'crystax', 'libs', arch.arch)\n            flags += ' -I{}'.format(py_inc_dir)\n            flags += ' -L{} -lpython{}m'.format(py_lib_dir, py_ver)\n            flags += \" -I{}\".format(cry_inc_dir)\n            flags += \" -L{}\".format(cry_lib_dir)\n\n        if flags not in env['CC']:\n            env['CC'] += flags\n        if flags not in env['LD']:\n            env['LD'] += flags + ' -shared'\n        return env\n\n    def prebuild_arch(self, arch):\n        super(NumpyRecipe, self).prebuild_arch(arch)\n\n        warning('Numpy is built assuming the archiver name is '\n                'arm-linux-androideabi-ar, which may not always be true!')\n\n\nrecipe = NumpyRecipe()\n", "path": "pythonforandroid/recipes/numpy/__init__.py"}]}