Writing custom recipe for the first time

59 views
Skip to first unread message

Mark Alexa

unread,
Apr 19, 2023, 10:54:26 AM4/19/23
to Kivy users support
Hello community,
I'm writing a new recipe for the EasyOCR module which I need make
work on Android. I've read through tutorial here however I still have questions.
Like for example if the Python package contains C code I need to use `CythonRecipe`, correct ?

Another question I have after reading though examples of recipes how the developer
knows what methods will be needed in order to make the recipe work ?

This is what I've got so far:
```
from pythonforandroid.recipe import CythonRecipe
from pythonforandroid.toolchain import shprint, current_directory
from os.path import exists, join
import sh


class EasyOCR(CythonRecipe):

url = 'https://github.com/JaidedAI/EasyOCR/archive/refs/tags/v1.6.2.tar.gz'
site_packages_name = 'EasyOCR'
version = '1.6.2'
md5sum = 'c4488ad511562196f04c47ee387f25a2'
depends = ['torch', 'torchvision>=0.5' 'opencv-python-headless', 'scipy', 'numpy', 'Pillow',
 'scikit-image', 'python-bidi', 'PyYAML', 'shapely', 'pyclipper', 'ninja', 'cython', 'setuptools']

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
return env

def prebuild_arch(self, arch):
super().prebuild_arch(arch)

def build_arch(self, arch):
super().build_arch(arch)
env = self.get_recipe_env(arch)
with current_directory(self.get_build_dir(build_arch)):
shprint(sh.echo, '$PATH', _env=env)

def postbuild_arch(self, arch):
super().build_arch(arch)

def should_build(self, arch):
name = self.site_packages_name
if name is None:
name = self.name
if self.ctx.has_package(name):
info('Python package already exists in site-packages')
return False
info(f'{name} apparently isn\'t already in site-packages')
return True


recipe = EasyOCR()
```

Thank you for assistance.

Robert

unread,
Apr 19, 2023, 1:27:05 PM4/19/23
to Kivy users support
Reply all
Reply to author
Forward
0 new messages