Skip to content

Commit 0984ac6

Browse files
authored
Merge pull request #4130 from ales-erjavec/macos-installer-python-version
[ENH] macOS: Installer python version
2 parents a0507ec + 38f4306 commit 0984ac6

File tree

3 files changed

+72
-59
lines changed

3 files changed

+72
-59
lines changed

scripts/macos/build-macos-app.sh

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ Create (build) an macOS application bundle
88
99
Options:
1010
--python-version VERSION
11-
Python version to install in the application bundle (default: 3.6.1)
11+
Python version to install in the application bundle (default: 3.7.5)
1212
1313
--pip-arg ARG
1414
Pip install arguments to populate the python environemnt in the
1515
application bundle. Can be used multiple times.
16-
If not supplied then by default the latest PyPi published Orange3 and
17-
requirements as recorded in scripts/macos/requirements.txt are
18-
installed.
16+
If not supplied then by default the latest PyPi published Orange3 is
17+
used.
1918
2019
-h|--help
2120
Print this help
@@ -41,7 +40,7 @@ Examples
4140
DIR=$(dirname "$0")
4241

4342
# Python version in the bundled framework
44-
PYTHON_VERSION=3.6.1
43+
PYTHON_VERSION=3.7.5
4544

4645
# Pip arguments used to populate the python environment in the application
4746
# bundle
@@ -73,7 +72,7 @@ APPDIR=${1:?"Target APPDIR argument is missing"}
7372
PYVER=${PYTHON_VERSION%.*} # Major.Minor
7473

7574
if [[ ${#PIP_REQ_ARGS[@]} -eq 0 ]]; then
76-
PIP_REQ_ARGS+=( Orange3 -r "${DIR}"/requirements.txt )
75+
PIP_REQ_ARGS+=( Orange3 'PyQt5~=5.12.0' 'PyQtWebEngine~=5.12.0' )
7776
fi
7877

7978
mkdir -p "${APPDIR}"/Contents/MacOS
@@ -86,6 +85,8 @@ cp -a "${DIR}"/skeleton.app/Contents/{Resources,Info.plist.in} \
8685
# Layout a 'relocatable' python framework in the app directory
8786
"${DIR}"/python-framework.sh \
8887
--version "${PYTHON_VERSION}" \
88+
--macos 10.9 \
89+
--install-certifi \
8990
"${APPDIR}"/Contents/Frameworks
9091

9192
ln -fs ../Frameworks/Python.framework/Versions/${PYVER}/Resources/Python.app/Contents/MacOS/Python \
@@ -95,23 +96,7 @@ ln -fs ../Frameworks/Python.framework/Versions/${PYVER}/bin/python${PYVER} \
9596
"${APPDIR}"/Contents/MacOS/python
9697

9798
"${APPDIR}"/Contents/MacOS/python -m ensurepip
98-
"${APPDIR}"/Contents/MacOS/python -m pip install pip~=9.0 wheel
99-
100-
# Python 3.6 on macOS no longer links the obsolete system libssl.
101-
# Instead it builds/ships a it's own which expects a cert.pem in hardcoded
102-
# /Library/Python.framework/3.6/etc/openssl/ path (but does no actually ship
103-
# the file in the framework installer). Instead a user is prompted during
104-
# .pkg install to run a script that pip install's certifi and links its
105-
# cacert.pem to the etc/openssl dir. We do the same but must also patch
106-
# ssl.py to load the cert store from a python prefix relative path (this is
107-
# done by python-framework.sh script). Another option would be to export system
108-
# certificates at runtime using the 'security' command line tool.
109-
"${APPDIR}"/Contents/MacOS/python -m pip install certifi
110-
# link the certifi supplied cert store to ${prefix}/etc/openssl/cert.pem
111-
ln -fs ../../lib/python${PYVER}/site-packages/certifi/cacert.pem \
112-
"${APPDIR}"/Contents/Frameworks/Python.framework/Versions/${PYVER}/etc/openssl/cert.pem
113-
# sanity check
114-
test -r "${APPDIR}"/Contents/Frameworks/Python.framework/Versions/${PYVER}/etc/openssl/cert.pem
99+
"${APPDIR}"/Contents/MacOS/python -m pip install pip~=19.0 wheel
115100

116101
cat <<'EOF' > "${APPDIR}"/Contents/MacOS/Orange
117102
#!/bin/bash
@@ -145,7 +130,7 @@ chmod +x "${APPDIR}"/Contents/MacOS/pip
145130

146131
PYTHON="${APPDIR}"/Contents/MacOS/python
147132

148-
"${PYTHON}" -m pip install "${PIP_REQ_ARGS[@]}"
133+
"${PYTHON}" -m pip install --no-warn-script-location "${PIP_REQ_ARGS[@]}"
149134

150135
VERSION=$("${PYTHON}" -m pip show orange3 | grep -E '^Version:' |
151136
cut -d " " -f 2)

scripts/macos/python-framework.sh

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ usage() {
66
Fetch, extract and layout a macOS relocatable Python framework at FRAMEWORKPATH
77
88
Options:
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
1118
Note:
1219
Python >= 3.6 comes with a bundled openssl library build that is
@@ -15,8 +22,8 @@ Note:
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
2128
Example
2229
-------
@@ -28,9 +35,10 @@ Example
2835
}
2936

3037

31-
32-
VERSION=3.5.3
38+
VERSION=3.7.5
39+
MACOSVER=10.9
3340
VERBOSE_LEVEL=0
41+
INSTALL_CERTIFI=
3442

3543

3644
verbose() {
@@ -44,11 +52,13 @@ verbose() {
4452
python-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() {
7080
python-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() {
234256
EOF
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+
237273
while [[ "${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
253299
done
254300

255-
python-framework-fetch-pkg ~/.cache/pkgs/ ${VERSION}
301+
python-framework-fetch-pkg ~/.cache/pkgs/ ${VERSION} ${MACOSVER}
256302
python-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

260306
python-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

scripts/macos/requirements.txt

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)