Skip to content

Instantly share code, notes, and snippets.

@bsolomon1124
Last active May 8, 2019 16:58
Show Gist options
  • Select an option

  • Save bsolomon1124/810e29818802e9e852ac02433d71bfe9 to your computer and use it in GitHub Desktop.

Select an option

Save bsolomon1124/810e29818802e9e852ac02433d71bfe9 to your computer and use it in GitHub Desktop.
Clone & make CPython for development on Mac OS X.
#!/bin/bash
#
# Clone & make CPython for development on Mac OS X.
#
# - Clones CPython into your current directory
# - Installs developer tools & development headers if needed, via brew
# - Configures, makes, tests Python
# - Launches Python REPL
#
# The output is verbose by default.
#
# Use the optional -q flag to make all the underlying commands quiet,
# to the extent possible
#
# ./pydev -q
function clonepy() {
# *nix
read -rp "Please enter your GitHub username: " username
origin="[email protected]:${username}/cpython.git"
if [[ -d cpython ]]; then
read -rp "A cpython/ directory already exists here. Overwrite? [y/n] " overwrite
case $overwrite in
[Yy]* ) rm -rf cpython/ && git clone $origin ;;
[Nn]* ) echo "OK, aborting with exit code 1." >&2 && exit 1 ;;
esac
else
git clone $q $origin
fi
if [[ $q == "--quiet" ]]; then
# User hasn't seen anything else, so let them know they're good so far
# (CPython can take a minute or two to download)
echo "Cloned $origin to cpython/"
fi
cd cpython/
[email protected]:python/cpython.git
git remote add upstream $upstream && echo "Added upstream remote: $upstream"
git remote -v
}
function makepymac() {
xcode-select --install
if [[ ! -x $(which brew) ]]; then
echo "It looks like you are missing brew, which this script depends on." >&2
echo "Please install brew yourself first; see https://brew.sh/." >&2
exit 1
fi
brew install openssl xz || brew upgrade openssl xz
# See https://devguide.python.org/setup/
# CPPFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" ./configure --with-pydebug $q
./configure --with-pydebug --with-openssl=$(brew --prefix openssl) $q
ncores=$(python -c 'import multiprocessing as mp; print(mp.cpu_count())')
make $q -j $ncores
./python.exe -m test $q -j $ncores
echo
./python.exe
}
# Main
plat=$(python -c 'import sys; print(sys.platform)')
if [[ $plat != "darwin" ]]; then
echo "This script requires Mac OS X (Darwin), not $plat." >&2
echo "Aborting with exit code 1" >&2
exit 1
fi
q=""
while getopts "q" flag; do
case "$flag" in
q ) q="--quiet" ;;
* ) error "Unexpected option: ${flag}" ;;
esac
done
clonepy && makepymac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment