Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes building in venv #462

Merged
merged 1 commit into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/kivy_ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ jobs:
run: |
.ci/test_project.sh

build_python3_kivy_venv:
runs-on: macos-latest
steps:
- name: Checkout kivy-ios
uses: actions/checkout@v2
- name: Set up Python 3.7.x
uses: actions/setup-python@v1
with:
python-version: 3.7.x
- name: Install requirements
run: |
python -m venv venv
. venv/bin/activate
pip install -r requirements.txt
pip install sh
brew install autoconf automake libtool pkg-config
brew link libtool
pip install Cython==0.28.1
- name: Build Python & Kivy
run: |
python toolchain.py build python3 kivy

build_updated_recipes:
runs-on: macos-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Kivy for iOS

[![kivy-ios](https://github.com/kivy/kivy-ios/workflows/kivy-ios/badge.svg)](https://github.com/kivy/kivy-ios/actions?query=workflow%3Akivy-ios)
[![Backers on Open Collective](https://opencollective.com/kivy/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/kivy/sponsors/badge.svg)](#sponsors)

Expand Down
33 changes: 9 additions & 24 deletions recipes/host_setuptools3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
from toolchain import Recipe, shprint
from os.path import join
from toolchain import Recipe, shprint, cd, cache_execution
import sh
import os
import shutil


class HostSetuptools3(Recipe):
depends = ["openssl", "hostpython3"]
archs = ["x86_64"]
url = "setuptools"
version = '40.9.0'
url = 'https://pypi.python.org/packages/source/s/setuptools/setuptools-{version}.zip'

def prebuild_arch(self, arch):
@cache_execution
def install(self):
arch = self.filtered_archs[0]
build_dir = self.get_build_dir(arch.arch)
hostpython = sh.Command(self.ctx.hostpython)
sh.curl("-O", "https://bootstrap.pypa.io/ez_setup.py")
shprint(hostpython, "./ez_setup.py")
# Extract setuptools egg and remove .pth files. Otherwise subsequent
# python package installations using setuptools will raise exceptions.
# Setuptools version 28.3.0
site_packages_path = join(
self.ctx.dist_dir, 'hostpython3',
'lib', 'python3.8', 'site-packages')
os.chdir(site_packages_path)
with open('setuptools.pth', 'r') as f:
setuptools_egg_path = f.read().strip('./').strip('\n')
print("setuptools_egg_path=", setuptools_egg_path)
unzip = sh.Command('unzip')
shprint(unzip, "-o", setuptools_egg_path)
os.remove(setuptools_egg_path)
os.remove('setuptools.pth')
os.remove('easy-install.pth')
shutil.rmtree('EGG-INFO')
with cd(build_dir):
shprint(hostpython, "setup.py", "install")


recipe = HostSetuptools3()
25 changes: 17 additions & 8 deletions recipes/hostpython3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from toolchain import Recipe, shprint
from toolchain import Recipe, cd, shprint
from os.path import join
import os
import sh
Expand All @@ -14,6 +14,7 @@ class Hostpython3Recipe(Recipe):
depends = ["hostlibffi", "hostopenssl"]
optional_depends = []
archs = ["x86_64"]
build_subdir = 'native-build'

def init_with_ctx(self, ctx):
super(Hostpython3Recipe, self).init_with_ctx(ctx)
Expand All @@ -24,9 +25,13 @@ def init_with_ctx(self, ctx):
logger.info("Global: hostpython located at {}".format(self.ctx.hostpython))
logger.info("Global: hostpgen located at {}".format(self.ctx.hostpgen))

def get_build_subdir(self, arch):
return join(self.get_build_dir(arch), self.build_subdir)

def prebuild_arch(self, arch):
if self.has_marker("patched"):
return
self.apply_patch("pyconfig_detection.patch")
self.copy_file("ModulesSetup", "Modules/Setup.local")
self.set_marker("patched")

Expand Down Expand Up @@ -55,20 +60,24 @@ def get_build_env(self):
def build_x86_64(self):
build_env = self.get_build_env()
configure = sh.Command(join(self.build_dir, "configure"))
shprint(configure,
"--prefix={}".format(join(self.ctx.dist_dir, "hostpython3")),
"--with-openssl={}".format(join(self.ctx.dist_dir, 'hostopenssl')),
_env=build_env)
shprint(sh.make, "-C", self.build_dir, self.ctx.concurrent_make,
arch = self.filtered_archs[0]
build_subdir = self.get_build_subdir(arch.arch)
os.makedirs(build_subdir, exist_ok=True)
with cd(build_subdir):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice approach

shprint(configure,
"--prefix={}".format(join(self.ctx.dist_dir, "hostpython3")),
"--with-openssl={}".format(join(self.ctx.dist_dir, 'hostopenssl')),
_env=build_env)
shprint(sh.make, "-C", build_subdir, self.ctx.concurrent_make,
_env=build_env)

def install(self):
arch = list(self.filtered_archs)[0]
build_env = self.get_build_env()
build_dir = self.get_build_dir(arch.arch)
build_subdir = self.get_build_subdir(arch.arch)
build_env["PATH"] = os.environ["PATH"]
shprint(sh.make, self.ctx.concurrent_make,
"-C", build_dir,
"-C", build_subdir,
"install",
_env=build_env)
shutil.copy(
Expand Down
25 changes: 25 additions & 0 deletions recipes/hostpython3/pyconfig_detection.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff -Nru Python-3.8.2/Lib/site.py Python-3.8.2-new/Lib/site.py
--- Python-3.8.2/Lib/site.py 2020-02-24 22:36:25.000000000 +0100
+++ Python-3.8.2-new/Lib/site.py 2020-05-01 17:10:43.000000000 +0200
@@ -458,9 +458,8 @@

env = os.environ
if sys.platform == 'darwin' and '__PYVENV_LAUNCHER__' in env:
- executable = sys._base_executable = os.environ['__PYVENV_LAUNCHER__']
- else:
- executable = sys.executable
+ print("Ignoring __PYVENV_LAUNCHER__")
+ executable = sys.executable
exe_dir, _ = os.path.split(os.path.abspath(executable))
site_prefix = os.path.dirname(exe_dir)
sys._home = None
@@ -487,7 +486,8 @@
if key == 'include-system-site-packages':
system_site = value.lower()
elif key == 'home':
- sys._home = value
+ # this is breaking pyconfig.h path detection with venv
+ print('Ignoring "sys._home = value" override')

sys.prefix = sys.exec_prefix = site_prefix

2 changes: 1 addition & 1 deletion recipes/kivy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class KivyRecipe(CythonRecipe):
url = "https://github.com/kivy/kivy/archive/{version}.zip"
library = "libkivy.a"
depends = ["sdl2", "sdl2_image", "sdl2_mixer", "sdl2_ttf", "ios",
"pyobjus", "python"]
"pyobjus", "python", "host_setuptools3"]
pbx_frameworks = ["OpenGLES", "Accelerate", "CoreMedia", "CoreVideo"]
pre_build_ext = True

Expand Down
1 change: 1 addition & 0 deletions recipes/python3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def prebuild_arch(self, arch):
self.apply_patch("posixmodule.patch")
self.apply_patch("dynload_shlib.patch")
self.apply_patch("disable_explicit_blake2.patch")
self.apply_patch("pyconfig_detection.patch")
self.copy_file("ModulesSetup", "Modules/Setup.local")
self.append_file("ModulesSetup.mobile", "Modules/Setup.local")
self.set_marker("patched")
Expand Down
25 changes: 25 additions & 0 deletions recipes/python3/pyconfig_detection.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff -Nru Python-3.8.2/Lib/site.py Python-3.8.2-new/Lib/site.py
--- Python-3.8.2/Lib/site.py 2020-02-24 22:36:25.000000000 +0100
+++ Python-3.8.2-new/Lib/site.py 2020-05-01 17:10:43.000000000 +0200
@@ -458,9 +458,8 @@

env = os.environ
if sys.platform == 'darwin' and '__PYVENV_LAUNCHER__' in env:
- executable = sys._base_executable = os.environ['__PYVENV_LAUNCHER__']
- else:
- executable = sys.executable
+ print("Ignoring __PYVENV_LAUNCHER__")
+ executable = sys.executable
exe_dir, _ = os.path.split(os.path.abspath(executable))
site_prefix = os.path.dirname(exe_dir)
sys._home = None
@@ -487,7 +486,8 @@
if key == 'include-system-site-packages':
system_site = value.lower()
elif key == 'home':
- sys._home = value
+ # this is breaking pyconfig.h path detection with venv
+ print('Ignoring "sys._home = value" override')

sys.prefix = sys.exec_prefix = site_prefix

13 changes: 12 additions & 1 deletion toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import sys
from sys import stdout
from os.path import join, dirname, realpath, exists, isdir, basename
from os.path import join, dirname, realpath, exists, isdir, basename, expanduser
from os import listdir, unlink, makedirs, environ, chdir, getcwd, walk
import zipfile
import tarfile
Expand All @@ -19,6 +19,7 @@
import fnmatch
import tempfile
import time
from contextlib import contextmanager
from datetime import datetime
from pprint import pformat
import logging
Expand Down Expand Up @@ -58,6 +59,16 @@
IS_PY2 = sys.version_info[0] == 2


@contextmanager
def cd(newdir):
prevdir = getcwd()
chdir(expanduser(newdir))
try:
yield
finally:
chdir(prevdir)


def shprint(command, *args, **kwargs):
kwargs["_iter"] = True
kwargs["_out_bufsize"] = 1
Expand Down