kivy-ios/recipes/kivent_core/__init__.py
Richard Larkin 64bd692632
Flake8 CI fixes (#451)
* Pep8 fixes

* tox Pep8 compliance

* Excluded external tools folder from flake 8 tests

* Added Flake 8 exclusions

* Pep8 fixes

* Pep8 fixes

* Corrected type

* Pep8 fixes

* Pep 8 compliance

* Pep8 fixes

* Pep8  fixes

* Pep8 fixes

* Pep8 fixes

* Pep 8 fixes

* Pep 8 fixes

* Pep8 fixes

* Pep8 fixes

* Pep8 fixes

* Pep8

* Pep8

* Pep 8

* Pep 8

* Pep8 fixes

* Pep8

* Pep8

* Pep8

* Pep8 fixes

* Pep8 fixes

* Pep8 fixes

* Pep8 fixes

* Pep8 fixes

* Revert chagnes

* Revert changes to kivy/__init.py

* Revert changes

* REvert changes

* Revert changes

* Revert changes to toolchain

* Add files exclusions to tox.ini

* Added exclusions for alias recipes

* Remove dead code

* Added py extension to recipes

* Removed recipe build skip

* Improves recipe matching

Previous expression was matching all the following three lines of a `git diff --name-only` output.
```
recipes/hostlibffi/__init__.py
recipes/hostpython.py
recipes/hostpython2/__init__.py
```
This was resulting to a bug when later splitting with `recipe = file_path.split('/')[1]` the `recipes/hostpython.py` string would return including the `\n` new line char, see:
 ```
>>> 'recipes/hostpython.py\n'.split('/')[1]
'hostpython.py\n'
>>> 'recipes/hostlibffi/__init__.py\n'.split('/')[1]
'hostlibffi'
>>> 
```

Co-authored-by: Andre Miras <AndreMiras@users.noreply.github.com>
2020-04-25 18:28:16 +02:00

102 lines
3.6 KiB
Python

"""
Author: Lawrence Du
E-mail: larrydu88@gmail.com
"""
from toolchain import CythonRecipe, shprint
import sh
from os.path import join
from os import chdir
import logging
logger = logging.getLogger(__name__)
class KiventCoreRecipe(CythonRecipe):
version = 'master'
url = 'https://github.com/kivy/kivent/archive/{version}.zip'
name = 'kivent_core'
depends = ['libffi', 'kivy'] # note: unsure if libffi is necessary here
pre_build_ext = False
subbuilddir = False
cythonize = True
pbx_frameworks = ["OpenGLES"] # note: This line may be unnecessary
def get_recipe_env(self, arch):
env = super(KiventCoreRecipe, self).get_recipe_env(arch)
env['CYTHONPATH'] = self.get_recipe(
'kivy', self.ctx).get_build_dir(arch.arch)
return env
def get_build_dir(self, arch, sub=False):
"""
Call this to get the correct build_dir, where setup.py is located which is
actually under modules/core/setup.py
"""
builddir = super(KiventCoreRecipe, self).get_build_dir(str(arch))
if sub or self.subbuilddir:
core_build_dir = join(builddir, 'modules', 'core')
logger.info("Core build directory is located at {}".format(core_build_dir))
return core_build_dir
else:
logger.info("Building in {}".format(builddir))
return builddir
def build_arch(self, arch):
"""
Override build.arch to avoid calling setup.py here (Call it in
install() instead).
"""
self.subbuildir = True
self.cythonize_build()
self.biglink()
self.subbuilddir = False
def install(self):
"""
This method simply builds the command line call for calling
kivent_core/modules/core/setup.py
This constructs the equivalent of the command
"$python2.7 setup.py build_ext install"
only with the environment variables altered for each different architecture
The appropriate version of kivy also needs to be added to the path, and this
differs for each architecture (i386, x86_64, armv7, etc)
Note: This method is called by build_all() in toolchain.py
"""
arch = list(self.filtered_archs)[0]
build_dir = self.get_build_dir(arch.arch, sub=True)
logger.info("Building kivent_core {} in {}".format(arch.arch, build_dir))
chdir(build_dir)
hostpython = sh.Command(self.ctx.hostpython)
# Get the appropriate environment for this recipe (including CYTHONPATH)
# build_env = arch.get_env()
build_env = self.get_recipe_env(arch)
dest_dir = join(self.ctx.dist_dir, "root", "python")
build_env['PYTHONPATH'] = join(dest_dir, 'lib', 'python2.7', 'site-packages')
# Add Architecture specific kivy path for 'import kivy' to PYTHONPATH
arch_kivy_path = self.get_recipe('kivy', self.ctx).get_build_dir(arch.arch)
build_env['PYTHONPATH'] = join(build_env['PYTHONPATH'], ':', arch_kivy_path)
# Make sure you call kivent_core/modules/core/setup.py
subdir_path = self.get_build_dir(str(arch), sub=True)
setup_path = join(subdir_path, "setup.py")
# Print out directories for sanity check
logger.info("ENVS", build_env)
logger.info("ROOT", self.ctx.root_dir)
logger.info("BUILD", self.ctx.build_dir)
logger.info("INCLUDE", self.ctx.include_dir)
logger.info("DISTDIR", self.ctx.dist_dir)
logger.info("ARCH KIVY LOC", self.get_recipe('kivy', self.ctx).get_build_dir(arch.arch))
shprint(hostpython, setup_path, "build_ext", "install", _env=build_env)
recipe = KiventCoreRecipe()