Commit 618a1d61 authored by Kyle Stewart's avatar Kyle Stewart
Browse files

Add PyPy 2 support for MacOS.

This changes how the the Python implementation is selected.  It's now
primarily based on enviroment variables.

Uses the PYPY_VERSION enviroment variable to determine the version of PyPy to
install.  An example has been added to the matrix in the readme.
parent 291bd40b
...@@ -253,6 +253,10 @@ To use these scripts ...@@ -253,6 +253,10 @@ To use these scripts
language: generic language: generic
env: env:
- MB_PYTHON_VERSION=3.6 - MB_PYTHON_VERSION=3.6
- os: osx
language: generic
env:
- PYPY_VERSION=5.7
before_install: before_install:
- source multibuild/common_utils.sh - source multibuild/common_utils.sh
......
...@@ -262,3 +262,74 @@ function fill_submodule { ...@@ -262,3 +262,74 @@ function fill_submodule {
mv "${repo_copy}" "$repo_dir" mv "${repo_copy}" "$repo_dir"
(cd "$repo_dir" && git remote set-url origin $origin_url) (cd "$repo_dir" && git remote set-url origin $origin_url)
} }
PYPY_URL=https://bitbucket.org/pypy/pypy/downloads
# As of 2017-03-25, the latest verions of PyPy.
LATEST_PP_1=1.9
LATEST_PP_2=2.6
LATEST_PP_2p0=2.0.2
LATEST_PP_2p2=2.2.1
LATEST_PP_2p3=2.3.1
LATEST_PP_2p4=2.4.0
LATEST_PP_2p5=2.5.1
LATEST_PP_2p6=2.6.1
LATEST_PP_4=4.0
LATEST_PP_4p0=4.0.1
LATEST_PP_5=5.7
LATEST_PP_5p0=5.0.1
LATEST_PP_5p1=5.1.1
LATEST_PP_5p3=5.3.1
LATEST_PP_5p4=5.4.1
LATEST_PP_5p6=5.6.0
LATEST_PP_5p7=5.7.0
function unroll_version {
# Convert major or major.minor format to major.minor.micro using the above
# values recursively
# Parameters:
# $prefix : one of LATEST_PP or LATEST_PP3
# $version : major[.minor[.patch]]
# Hence:
# LATEST_PP 5 -> 5.7.0
# LATEST 2.7 -> 2.7.11
local prefix=$1
local ver=$2
local latest=${prefix}_${ver//./p}
if [ -n "${!latest}" ]; then
echo $(unroll_version ${prefix} ${!latest})
else
echo $ver
fi
}
function fill_pypy_ver {
# Convert major or major.minor format to major.minor.micro
# Parameters:
# $version : major[.minor[.patch]]
# Hence:
# 5 -> 5.7.0
echo $(unroll_version LATEST_PP $1)
}
function get_pypy_build_prefix {
# Return the file prefix of a PyPy file
# Parameters:
# $version : pypy2 version number
local version=$1
if [[ $version =~ ([0-9]+)\.([0-9]+) ]]; then
local major=${BASH_REMATCH[1]}
local minor=${BASH_REMATCH[2]}
if (( $major > 5 || ($major == 5 && $minor >= 3) )); then
echo "pypy2-v"
else
echo "pypy-"
fi
else
echo "error: expected version number, got $1" 1>&2
exit 1
fi
}
...@@ -120,6 +120,22 @@ function pyinst_ext_for_version { ...@@ -120,6 +120,22 @@ function pyinst_ext_for_version {
fi fi
} }
function install_python {
# Picks an implementation of Python determined by the current enviroment
# variables, then installs it
# A sub-function will set $PYTHON_EXE variable to the python executable
if [ -n "$MB_PYTHON_VERSION" ]; then
install_macpython $MB_PYTHON_VERSION
elif [ -n "$PYPY_VERSION" ]; then
install_mac_pypy $PYPY_VERSION
else
echo "config error: expected one of these enviroment variables:"
echo " MB_PYTHON_VERSION"
echo " PYPY_VERSION"
exit 1
fi
}
function install_macpython { function install_macpython {
# Installs Python.org Python # Installs Python.org Python
# Parameter $version # Parameter $version
...@@ -147,6 +163,22 @@ function install_macpython { ...@@ -147,6 +163,22 @@ function install_macpython {
fi fi
} }
function install_mac_pypy {
# Installs pypy.org PyPy
# Parameter $version
# Version given in major or major.minor or major.minor.micro e.g
# "3" or "3.4" or "3.4.1".
# sets $PYTHON_EXE variable to python executable
local py_version=$(fill_pypy_ver $1)
local py_build=$(get_pypy_build_prefix $py_version)$py_version-osx64
local py_zip=$py_build.tar.bz2
local zip_path=$DOWNLOADS_SDIR/$py_zip
mkdir -p $DOWNLOADS_SDIR
wget -nv $PYPY_URL/${py_zip} -P $DOWNLOADS_SDIR
untar $zip_path
PYTHON_EXE=$(realpath $py_build/bin/pypy)
}
function install_pip { function install_pip {
# Generic install pip # Generic install pip
# Gets needed version from version implied by $PYTHON_EXE # Gets needed version from version implied by $PYTHON_EXE
...@@ -205,11 +237,9 @@ function set_py_vars { ...@@ -205,11 +237,9 @@ function set_py_vars {
export PYTHON_EXE PIP_CMD export PYTHON_EXE PIP_CMD
} }
function get_macpython_environment { function get_python_environment {
# Set up MacPython environment # Set up MacPython environment
# Parameters: # Parameters:
# $version :
# major.minor.micro e.g. "3.4.1"
# $venv_dir : {directory_name|not defined} # $venv_dir : {directory_name|not defined}
# If defined - make virtualenv in this directory, set python / pip # If defined - make virtualenv in this directory, set python / pip
# commands accordingly # commands accordingly
...@@ -219,10 +249,9 @@ function get_macpython_environment { ...@@ -219,10 +249,9 @@ function get_macpython_environment {
# Sets $PIP_CMD to full command for pip (including sudo if necessary) # Sets $PIP_CMD to full command for pip (including sudo if necessary)
# If $venv_dir defined, Sets $VIRTUALENV_CMD to virtualenv executable # If $venv_dir defined, Sets $VIRTUALENV_CMD to virtualenv executable
# Puts directory of $PYTHON_EXE on $PATH # Puts directory of $PYTHON_EXE on $PATH
local version=$1 local venv_dir=$1
local venv_dir=$2
remove_travis_ve_pip remove_travis_ve_pip
install_macpython $version install_python
install_pip install_pip
if [ -n "$venv_dir" ]; then if [ -n "$venv_dir" ]; then
install_virtualenv install_virtualenv
...@@ -231,6 +260,24 @@ function get_macpython_environment { ...@@ -231,6 +260,24 @@ function get_macpython_environment {
set_py_vars set_py_vars
} }
function get_macpython_environment {
# Set up MacPython environment
# Parameters:
# $version :
# major.minor.micro e.g. "3.4.1"
# $venv_dir : {directory_name|not defined}
# If defined - make virtualenv in this directory, set python / pip
# commands accordingly
#
# Installs Python
# Sets $PYTHON_EXE to path to Python executable
# Sets $PIP_CMD to full command for pip (including sudo if necessary)
# If $venv_dir defined, Sets $VIRTUALENV_CMD to virtualenv executable
# Puts directory of $PYTHON_EXE on $PATH
export MB_PYTHON_VERSION=$1
get_python_environment $2
}
function repair_wheelhouse { function repair_wheelhouse {
local wheelhouse=$1 local wheelhouse=$1
pip install delocate pip install delocate
......
...@@ -15,7 +15,7 @@ source $MULTIBUILD_DIR/library_builders.sh ...@@ -15,7 +15,7 @@ source $MULTIBUILD_DIR/library_builders.sh
function before_install { function before_install {
export CC=clang export CC=clang
export CXX=clang++ export CXX=clang++
get_macpython_environment $MB_PYTHON_VERSION venv get_python_environment venv
source venv/bin/activate source venv/bin/activate
pip install --upgrade pip wheel pip install --upgrade pip wheel
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment