@@ -6,7 +6,14 @@ usage() {
66Fetch, extract and layout a macOS relocatable Python framework at FRAMEWORKPATH
77
88Options:
9- --version VERSION Python version (default 3.5.3)
9+ --version VERSION Python version (default ${VERSION} )
10+ --macos MACOSVER Minimum supported macOS version (as of 3.6.5 and
11+ 3.7.0 the python.org provides binaries for 10.6
12+ and 10.9 macOS versions; default ${MACOSVER} )
13+ --install-certifi If present then certifi pypi package will be
14+ installed and its cert store linked in
15+ \$ {PREFIX}/etc/openssl
16+ -v --verbose Increase verbosity level
1017
1118Note:
1219 Python >= 3.6 comes with a bundled openssl library build that is
1522
1623 This script will patch python's stdlib ssl.py to add a
1724 \$ {PREFIX}/etc/openssl/cert.pem (where \$ {PREFIX} is the runtime prefix)
18- certificate store to the default verification chain. However it does not
19- actually supply the file.
25+ certificate store to the default verification chain. However it will only
26+ supply the file if the --install-certifi parameter is passed
2027
2128Example
2229-------
@@ -28,9 +35,10 @@ Example
2835}
2936
3037
31-
32- VERSION=3.5.3
38+ VERSION=3.7.5
39+ MACOSVER=10.9
3340VERBOSE_LEVEL=0
41+ INSTALL_CERTIFI=
3442
3543
3644verbose () {
@@ -44,11 +52,13 @@ verbose() {
4452python-framework-fetch-pkg () {
4553 local cachedir=${1:? }
4654 local version=${2:? }
47- local filename=python-${version} -macosx10.6.pkg
48- local url=" https://www.python.org/ftp/python/${version} /${filename} "
55+ local macosver=${3:- 10.6}
56+ local versiondir=${version%% [abrpc]* } # strip alpha, beta, rc component
57+ local filename=python-${version} -macosx${macosver} .pkg
58+ local url=" https://www.python.org/ftp/python/${versiondir} /${filename} "
4959 mkdir -p " ${cachedir} "
5060 if [[ -f " ${cachedir} /${filename} " ]]; then
51- verbose 1 " python-${version} -macosx10.6 .pkg is present in cache"
61+ verbose 1 " python-${version} -macosx{macosver} .pkg is present in cache"
5262 return 0
5363 fi
5464 local tmpfile=$( mktemp " ${cachedir} /${filename} " -XXXX)
@@ -70,10 +80,22 @@ python-framework-fetch-pkg() {
7080python-framework-extract-pkg () {
7181 local targetdir=${1:? }
7282 local pkgpath=${2:? }
83+ local pkgfilename
84+ pkgfilename=$( basename " ${pkgpath} " )
7385 mkdir -p " ${targetdir} " /Python.framework
7486 verbose 1 " Extracting framework at ${targetdir} /Python.framework"
75- tar -O -xf " ${pkgpath} " Python_Framework.pkg/Payload | \
76- tar -x -C " ${targetdir} " /Python.framework
87+ (
88+ tmpdir=$( mktemp -d -t python-framework-extract-pkg)
89+ cleanup-on-exit () {
90+ if [ -d " ${tmpdir:? } " ] ; then
91+ rm -rf " ${tmpdir:? } "
92+ fi
93+ }
94+ trap cleanup-on-exit EXIT
95+ pkgutil --expand " ${pkgpath} " " ${tmpdir:? } /${pkgfilename} " || exit 1
96+ tar -C " ${targetdir} " /Python.framework \
97+ -xf " ${tmpdir} /${pkgfilename} /Python_Framework.pkg/Payload" || exit 1
98+ )
7799}
78100
79101
@@ -234,6 +256,20 @@ patch-ssl() {
234256EOF
235257}
236258
259+
260+ install-certifi () {
261+ local prefix=${1:? }
262+ " ${prefix} " /bin/python? .? -B -m ensurepip
263+ " ${prefix} " /bin/python? .? -B -m pip --isolated install certifi
264+ (
265+ mkdir -p " ${prefix} " /etc/openssl
266+ cd " ${prefix} " /etc/openssl
267+ ln -shf ../../lib/python? .? /site-packages/certifi/cacert.pem ./cert.pem
268+ )
269+ test -r " ${prefix} " /etc/openssl/cert.pem
270+ }
271+
272+
237273while [[ " ${1: 0: 1} " == " -" ]]; do
238274 case " ${1} " in
239275 --version)
@@ -242,20 +278,30 @@ while [[ "${1:0:1}" == "-" ]]; do
242278 --version=* )
243279 VERSION=${1##* =}
244280 shift 1;;
281+ --macos)
282+ MACOSVER=${2:? " --macos: missing argument" }
283+ shift 2;;
284+ --macos=* )
285+ MACOSVER=${1##* =}
286+ shift 1;;
245287 -v|--verbose)
246288 VERBOSE_LEVEL=$(( $VERBOSE_LEVEL + 1 ))
247289 shift 1;;
290+ --install-certifi)
291+ INSTALL_CERTIFI=1
292+ shift 1;;
248293 --help|-h)
249294 usage; exit 0;;
250295 -* )
296+ echo " Unrecognized argument ${1} " >&2
251297 usage >&2 ; exit 1;;
252298 esac
253299done
254300
255- python-framework-fetch-pkg ~ /.cache/pkgs/ ${VERSION}
301+ python-framework-fetch-pkg ~ /.cache/pkgs/ ${VERSION} ${MACOSVER}
256302python-framework-extract-pkg \
257303 " ${1:? " FRAMEWORKPATH argument is missing" } " \
258- ~ /.cache/pkgs/python-${VERSION} -macosx10.6 .pkg
304+ ~ /.cache/pkgs/python-${VERSION} -macosx ${MACOSVER} .pkg
259305
260306python-framework-relocate " ${1:? } " /Python.framework
261307
@@ -265,3 +311,8 @@ python-framework-relocate "${1:?}"/Python.framework
265311 shopt -s failglob
266312 ln -shf ? .? ./Current # assuming single version framework
267313)
314+
315+ if [[ ${INSTALL_CERTIFI} ]]; then
316+ verbose 1 " Installing and linking certifi pypi package"
317+ install-certifi " ${1:? } " /Python.framework/Versions/Current
318+ fi
0 commit comments