Fix/host setuptools3 (#533)

* status

* ♻️ Extract context managers

* 🎨 Fix typo

*  Use python_prefix

*  Remove unused import

* 📦 Trigger pipeline

Co-authored-by: richard <richard@dotmodus>
This commit is contained in:
Richard Larkin 2020-07-26 21:07:10 +02:00 committed by GitHub
parent 4567cad31f
commit 7cb14fc7da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 69 additions and 24 deletions

View file

@ -324,3 +324,4 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
<a href="https://opencollective.com/kivy/sponsor/7/website" target="_blank"><img src="https://opencollective.com/kivy/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/kivy/sponsor/8/website" target="_blank"><img src="https://opencollective.com/kivy/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/kivy/sponsor/9/website" target="_blank"><img src="https://opencollective.com/kivy/sponsor/9/avatar.svg"></a>

View file

@ -0,0 +1,46 @@
"""
This module houses context managers to assist in the managing of state during
kivy-ios builds.
"""
from logging import getLogger
from contextlib import contextmanager
from os import getcwd, chdir, environ
from os.path import expanduser
logger = getLogger(__name__)
@contextmanager
def cd(newdir):
"""
Set the current working directory to `newdir` for the duration of the
context.
"""
prevdir = getcwd()
logger.info("cd {}".format(newdir))
chdir(expanduser(newdir))
try:
yield
finally:
logger.info("cd {}".format(prevdir))
chdir(prevdir)
@contextmanager
def python_path(newdir):
"""
Set the PYTHONPATH environmnet variable to `newdir` for the duraiton of the
context.
"""
prevdir = environ.get("PYTHONPATH")
logger.debug("Setting PYTHONPATH to {}".format(newdir))
environ["PYTHONPATH"] = newdir
try:
yield
finally:
logger.debug("Setting PYTHONPATH to {}".format(prevdir))
if prevdir is None:
environ.pop("PYTHONPATH")
else:
environ["PYTHONPATH"] = prevdir

View file

@ -1,9 +1,10 @@
from kivy_ios.toolchain import Recipe, shprint, cd, cache_execution
from kivy_ios.toolchain import Recipe, shprint, cache_execution
from kivy_ios.context_managers import cd, python_path
import sh
class HostSetuptools3(Recipe):
depends = ["openssl", "hostpython3"]
depends = ["openssl", "hostpython3", "python3"]
archs = ["x86_64"]
version = '40.9.0'
url = 'https://pypi.python.org/packages/source/s/setuptools/setuptools-{version}.zip'
@ -13,8 +14,11 @@ class HostSetuptools3(Recipe):
arch = self.filtered_archs[0]
build_dir = self.get_build_dir(arch.arch)
hostpython = sh.Command(self.ctx.hostpython)
with cd(build_dir):
shprint(hostpython, "setup.py", "install")
with python_path(self.ctx.site_packages_dir):
with cd(build_dir):
shprint(hostpython, "setup.py", "install",
f"--prefix={self.ctx.python_prefix}")
recipe = HostSetuptools3()

View file

@ -1,9 +1,11 @@
from kivy_ios.toolchain import Recipe, cd, shprint
from kivy_ios.toolchain import Recipe, shprint
from os.path import join
import os
import sh
import shutil
import logging
from kivy_ios.context_managers import cd
logger = logging.getLogger(__name__)

View file

@ -1,5 +1,6 @@
# pure-python package, this can be removed when we'll support any python package
from kivy_ios.toolchain import PythonRecipe, shprint, cd
from kivy_ios.toolchain import PythonRecipe, shprint
from kivy_ios.context_managers import cd
from os.path import join
import sh

View file

@ -2,7 +2,8 @@ import sh
from os.path import join
from kivy_ios.toolchain import CythonRecipe, cd, shprint
from kivy_ios.toolchain import CythonRecipe, shprint
from kivy_ios.context_managers import cd
class NetifacesRecipe(CythonRecipe):

View file

@ -1,6 +1,7 @@
'''Recipe for pycrypto on ios
'''
from kivy_ios.toolchain import CythonRecipe, shprint, cd
from kivy_ios.toolchain import CythonRecipe, shprint
from kivy_ios.context_managers import cd
from os.path import join
import sh

View file

@ -1,4 +1,5 @@
from kivy_ios.toolchain import Recipe, shprint, cd
from kivy_ios.toolchain import Recipe, shprint
from kivy_ios.context_managers import cd
from os.path import join
import sh
import shutil

View file

@ -9,7 +9,7 @@ This tool intend to replace all the previous tools/ in shell script.
import argparse
import sys
from sys import stdout
from os.path import join, dirname, realpath, exists, isdir, basename, expanduser
from os.path import join, dirname, realpath, exists, isdir, basename
from os import listdir, unlink, makedirs, environ, chdir, getcwd, walk
import sh
import zipfile
@ -21,7 +21,7 @@ import shutil
import fnmatch
import tempfile
import time
from contextlib import contextmanager, suppress
from contextlib import suppress
from datetime import datetime
from pprint import pformat
import logging
@ -46,18 +46,6 @@ sh_logging.setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
@contextmanager
def cd(newdir):
prevdir = getcwd()
logger.info("cd {}".format(newdir))
chdir(expanduser(newdir))
try:
yield
finally:
logger.info("cd {}".format(prevdir))
chdir(prevdir)
def shprint(command, *args, **kwargs):
kwargs["_iter"] = True
kwargs["_out_bufsize"] = 1