Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Win installer: Use private python installation #57

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/build-win-installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ jobs:
run: |
echo PATH=$PATH
mkdir dist
./scripts/windows/build-win-installer.sh --no-index --find-links=./wheels --python-version $PYTHON_VERSION --platform $PLATTAG --pip-arg=--pre --pip-arg=-r --pip-arg=$ENVSPEC --pip-arg=Orange3
./scripts/windows/build-win-installer.sh \
--no-index --find-links=./wheels \
--python-version $PYTHON_VERSION \
--platform $PLATTAG \
--pip-arg=--pre --pip-arg=-r --pip-arg=$ENVSPEC --pip-arg=Orange3

INSTALLER=( dist/Orange3*.exe )
SHA256=$( sha256sum -b $INSTALLER )
Expand Down Expand Up @@ -113,7 +117,7 @@ jobs:
- name: Run tests
shell: bash
run: |
PYTHON=$(cygpath -u 'D:\test-install\Scripts\python')
PYTHON=$(cygpath -u 'D:\test-install\python')
$PYTHON --version
$PYTHON -m pip --version
$PYTHON -m pip list --format=freeze
Expand Down
11 changes: 11 additions & 0 deletions scripts/windows/activate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off
:: get full directory path where this file is located
for /F "delims=" %%i in ( "%~dp0" ) do ( set "ENV_PATH=%%~fi" )
:: strip trailing \
if "%ENV_PATH:~-1%" == "\" set "ENV_PATH=%ENV_PATH:~0,-1%"
:: get directory name
for /F "delims=" %%i in ( "%ENV_PATH%" ) do ( set "ENV=%%~nxi" )

if not defined PROMPT set PROMPT=$P$G
set "PROMPT=(%ENV%) %PROMPT%"
set "PATH=%ENV_PATH%;%ENV_PATH%\Scripts;%PATH%"
86 changes: 55 additions & 31 deletions scripts/windows/build-win-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Examples:
'
}

# The application name
NAME=Orange3
# version is determined at the end when all packages are available
VERSION=
Expand All @@ -56,7 +57,7 @@ PIP_INDEX_ARGS=()
PIP_ARGS=()

PYTHON_VERSION=
PLATTAG=
PLATTAG=win_amd64

while [[ "${1:0:1}" = "-" ]]; do
case $1 in
Expand Down Expand Up @@ -137,12 +138,15 @@ if [[ -d "${BASEDIR:?}" ]]; then
fi

# BASEDIR/
# wheelhouse/
# Python/
# wheels/
# requirements.txt
# icons/

mkdir -p "${BASEDIR:?}"/wheelhouse
mkdir -p "${BASEDIR:?}"/wheels
mkdir -p "${BASEDIR:?}"/icons

mkdir -p "${CACHEDIR:?}"/wheelhouse
mkdir -p "${CACHEDIR:?}"/wheels
mkdir -p "${CACHEDIR:?}"/python


Expand Down Expand Up @@ -195,6 +199,25 @@ python-installer-filename(){
echo ${filename}
}

function download {
# $ download URL DEST
#
# Download the URL to DEST path/filename. If DEST already exists
# do nothing.
local url=${1:?}
local dest=${2:?}
local tmpname=""
mkdir -p $(dirname "${dest}")
if [[ ! -f "${dest}" ]]; then
tmpname=$(mktemp "${dest}.XXXXX")
if curl -fSL -o "${tmpname}" "${url}"; then
mv "${tmpname}" "${dest}"
else
return $?
fi
fi
}

fetch-python() {
# $ fetch-python major.minor.micro plattag [ dest ]
#
Expand All @@ -208,23 +231,20 @@ fetch-python() {
if [[ ! ${filename} ]]; then
return 1
fi
download "https://www.python.org/ftp/python/${version}/${filename}" "${dest}/${filename}"
}

dest="${dest}/${filename}"
if [[ ! -f "${dest}" ]]; then
local tmpname=$(mktemp "${dest}.XXXXX")
if curl -s -f -L -o "${tmpname}" \
https://www.python.org/ftp/python/${version}/${filename}; then
mv "${tmpname}" "${dest}"
else
return $?
fi
fi
fetch-python-nupkg() {
# $ fetch-python-nupkg major.minor.micro dest
local version=${1:?}
local dest=${2:?}
download https://www.nuget.org/api/v2/package/python/${version} "${dest}"
}

fetch-requirements() {
# Download binary packages for the specified platform (all packages
# must be available as .whl files)
local wheeldir="${CACHEDIR}/wheelhouse"
local wheeldir="${CACHEDIR}/wheels"
pip download \
"${PIP_INDEX_ARGS[@]}" \
--dest "${wheeldir}" \
Expand All @@ -236,18 +256,15 @@ fetch-requirements() {
"$@"
}

# Package install requirements in "${BASEDIR}/wheelhouse".
# All the requirements MUST have the .whl cached in ${CACHEDIR}/wheelhouse
# Package install requirements in "${BASEDIR}/wheels".
# All the requirements MUST have the .whl cached in ${CACHEDIR}/wheels

package-requirements() {
local pyfilename=$(python-installer-filename ${PYTHON_VERSION} ${PLATTAG})
cp "${CACHEDIR:?}/python/${pyfilename:?}" \
"${BASEDIR:?}/"
local wheeldir="${CACHEDIR:?}/wheelhouse"
local wheeldir="${CACHEDIR:?}/wheels"
pip download \
--no-index \
--find-links "${wheeldir}" \
--dest "${BASEDIR:?}/wheelhouse" \
--dest "${BASEDIR:?}/wheels" \
--only-binary :all: \
--python-version "${PYTAG}" \
--platform "${PLATTAG}" \
Expand All @@ -256,12 +273,9 @@ package-requirements() {

echo "# Env spec " > "${BASEDIR:?}"/requirements.txt
(
cd "${BASEDIR:?}/wheelhouse"
cd "${BASEDIR:?}/wheels"
ls -1 *.whl
) >> "${BASEDIR:?}/requirements.txt"

mkdir -p "${BASEDIR:?}/icons"
cp "$(dirname "$0")"/{orange.ico,OrangeOWS.ico} "${BASEDIR:?}/icons"
}


Expand Down Expand Up @@ -300,14 +314,14 @@ wheel-version() {
wheel-metadata "${1:?}" | grep -E "^Version: " | cut -d " " -f 2
}

PYINSTALL_TYPE=Normal
PYINSTALL_TYPE=Private

make-installer() {
local scriptdir="$(dirname "$0")"
local nsis_script="${scriptdir:?}/orange-install.nsi"
local outpath=${DISTDIR}
local filename=${NAME}-${VERSION}-Python${PYTAG:?}-${PLATTAG:?}.exe
local pyinstaller=$(python-installer-filename ${PYTHON_VERSION} ${PLATTAG})
local pyinstaller="Python"
local basedir=$(win-path "${BASEDIR:?}")
local versionstr=${VERSION}
local major=$(version-component 1 "${versionstr}")
Expand All @@ -331,7 +345,7 @@ EOF

makensis -DOUTFILENAME="${outpath}/${filename}" \
-DAPPNAME=Orange \
-DVERSION=${VERSION} \
-DVERSION=${VERSION:?} \
-DVERMAJOR=${major} -DVERMINOR=${minor} -DVERMICRO=${micro} \
-DPYMAJOR=${pymajor} -DPYMINOR=${pyminor} -DPYMICRO=${pymicro} \
-DPYARCH=${PLATTAG} \
Expand All @@ -341,6 +355,7 @@ EOF
-DINSTALL_REGISTRY_KEY=OrangeCanvas \
-DINSTALLERICON="$(win-path "${scriptdir}")/Orange.ico" \
-DLICENSE_FILE="${BASEDIR}"/license.txt \
-DLAUNCHERMODULE=Orange.canvas \
-NOCD \
-V4 \
"-X!addincludedir $(win-path "${scriptdir}")" \
Expand All @@ -349,12 +364,21 @@ EOF

DIRNAME=$(dirname "${0}")

fetch-python ${PYTHON_VERSION} ${PLATTAG} "${CACHEDIR:?}"/python
fetch-python-nupkg ${PYTHON_VERSION} "${CACHEDIR:?}"/python-${PYTHON_VERSION}

7z x '-i!tools' -y -o"${BUILDBASE}/python" "${CACHEDIR:?}"/python-${PYTHON_VERSION}
mv "${BUILDBASE}/python/tools" "${BASEDIR}/Python"
rm -r "${BUILDBASE}/python"
cp "${DIRNAME}/activate.bat" "${BASEDIR}/Python"

fetch-requirements "${PIP_ARGS[@]}"
package-requirements "${PIP_ARGS[@]}"

# move icons in place
cp "${DIRNAME}"/{"Orange.ico","OrangeOWS.ico"} "${BASEDIR:?}/icons"

shopt -s failglob
WHEEL=( "${BASEDIR}"/wheelhouse/${NAME}*.whl )
WHEEL=( "${BASEDIR}"/wheels/${NAME}*.whl )
shopt -u failglob

if [[ ! "${WHEEL}" ]]; then
Expand Down
Loading
Loading