|
| 1 | +from pythonforandroid.toolchain import PythonRecipe, current_directory, shprint |
| 2 | +import sh |
| 3 | + |
| 4 | + |
| 5 | +class Psycopg2Recipe(PythonRecipe): |
| 6 | + version = 'latest' |
| 7 | + url = 'http://initd.org/psycopg/tarballs/psycopg2-{version}.tar.gz' |
| 8 | + depends = [('python2', 'python3'), 'libpq'] |
| 9 | + site_packages_name = 'psycopg2' |
| 10 | + |
| 11 | + def prebuild_arch(self, arch): |
| 12 | + libdir = self.ctx.get_libs_dir(arch.arch) |
| 13 | + with current_directory(self.get_build_dir(arch.arch)): |
| 14 | + # pg_config_helper will return the system installed libpq, but we |
| 15 | + # need the one we just cross-compiled |
| 16 | + shprint(sh.sed, '-i', |
| 17 | + "s|pg_config_helper.query(.libdir.)|'{}'|".format(libdir), |
| 18 | + 'setup.py') |
| 19 | + |
| 20 | + def get_recipe_env(self, arch): |
| 21 | + env = super(Psycopg2Recipe, self).get_recipe_env(arch) |
| 22 | + env['LDFLAGS'] = "{} -L{}".format(env['LDFLAGS'], self.ctx.get_libs_dir(arch.arch)) |
| 23 | + env['EXTRA_CFLAGS'] = "--host linux-armv" |
| 24 | + return env |
| 25 | + |
| 26 | + def install_python_package(self, arch, name=None, env=None, is_dir=True): |
| 27 | + '''Automate the installation of a Python package (or a cython |
| 28 | + package where the cython components are pre-built).''' |
| 29 | + if env is None: |
| 30 | + env = self.get_recipe_env(arch) |
| 31 | + |
| 32 | + with current_directory(self.get_build_dir(arch.arch)): |
| 33 | + hostpython = sh.Command(self.ctx.hostpython) |
| 34 | + |
| 35 | + shprint(hostpython, 'setup.py', 'build_ext', '--static-libpq', |
| 36 | + _env=env) |
| 37 | + shprint(hostpython, 'setup.py', 'install', '-O2', |
| 38 | + '--root={}'.format(self.ctx.get_python_install_dir()), |
| 39 | + '--install-lib=lib/python2.7/site-packages', _env=env) |
| 40 | + |
| 41 | +recipe = Psycopg2Recipe() |
0 commit comments