From f480b09b983a5374ed5dd6aa9088575fbebfc97c Mon Sep 17 00:00:00 2001
From: u214892 <u214892@sbb.ch>
Date: Thu, 20 Jun 2019 00:20:22 +0200
Subject: [PATCH] #71 one-click-installer-runner

---
 getting_started/run_notebooks.bat | 53 +++++++++++++++++++++++++++++++
 getting_started/run_notebooks.sh  | 44 +++++++++++++++++++++++++
 setup.py                          |  1 +
 3 files changed, 98 insertions(+)
 create mode 100644 getting_started/run_notebooks.bat
 create mode 100644 getting_started/run_notebooks.sh

diff --git a/getting_started/run_notebooks.bat b/getting_started/run_notebooks.bat
new file mode 100644
index 00000000..afe41e08
--- /dev/null
+++ b/getting_started/run_notebooks.bat
@@ -0,0 +1,53 @@
+@echo on
+
+set PWD_BEFORE=%cd%
+
+@echo off
+echo "************ TESTING PREREQUISITES PYTHON3 + GIT *************************"
+@echo on
+
+git --version || goto :error
+python3 --version || goto :error
+
+
+@echo off
+echo "************ SETUP VIRTUAL ENVIRONMENT FLATLAND *************************"
+@echo on
+
+set FLATLAND_BASEDIR=%~dp0\..
+set WORKON_HOME=%FLATLAND_BASEDIR%\getting_started\envs_win
+if not exist "%WORKON_HOME%" md "%WORKON_HOME%" || goto :error
+cd "%WORKON_HOME%"
+rem use venv instead of virtualenv/virtualenv-wrapper because of https://github.com/pypa/virtualenv/issues/355
+python3 -m venv flatland || goto :error
+rem ignore activation error: https://stackoverflow.com/questions/51358202/python-3-7-activate-venv-error-parameter-format-not-correct-65001-windows
+call "%WORKON_HOME%\flatland\Scripts\activate.bat" || true
+
+
+@echo off
+echo "************ INSTALL FLATLAND IN THE VIRTUALENV  *************************"
+@echo on
+python -m pip install --upgrade pip || goto :error
+cd %FLATLAND_BASEDIR% || goto :error
+python setup.py install || goto :error
+REM ensure jupyter is installed in the virtualenv
+pip install -r "%FLATLAND_BASEDIR%/requirements_dev.txt" -r "%FLATLAND_BASEDIR%\requirements_continuous_integration.txt" || goto :error
+
+@echo off
+echo "************ INSTALL JUPYTER EXTENSION *************************"
+@echo on
+jupyter nbextension install --py --sys-prefix widgetsnbextension || goto :error
+jupyter nbextension enable --py --sys-prefix widgetsnbextension || goto :error
+jupyter nbextension install --py --sys-prefix jpy_canvas || goto :error
+jupyter nbextension enable --py --sys-prefix jpy_canvas || goto :error
+jupyter notebook || goto :error
+
+
+goto :EOF
+
+
+:error
+echo Failed with error #%errorlevel%.
+cd "%PWD_BEFORE%" || true
+deactivate || true
+pause
diff --git a/getting_started/run_notebooks.sh b/getting_started/run_notebooks.sh
new file mode 100644
index 00000000..70654ae5
--- /dev/null
+++ b/getting_started/run_notebooks.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+set -e # stop on error
+set -x # echo commands
+
+
+# https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself
+FLATLAND_BASEDIR=$(dirname "$0")/..
+FLATLAND_BASEDIR=$(realpath "$FLATLAND_BASEDIR")
+echo "BASEDIR=${FLATLAND_BASEDIR}"
+
+set +x
+echo "************ TESTING PREREQUISITES PYTHON3 + GIT *************************"
+set -x
+
+
+set +x
+echo "************ SETUP VIRTUAL ENVIRONMENT FLATLAND *************************"
+set -x
+
+export WORKON_HOME=${FLATLAND_BASEDIR}/getting_started/envs
+echo WORKON_HOME=$WORKON_HOME
+echo PWD=$PWD
+mkdir -p ${WORKON_HOME}
+# cannot work with virtualenvwrapper in script
+cd ${WORKON_HOME}
+python3 -m venv flatland
+source flatland/bin/activate
+
+set +x
+echo "************ INSTALL FLATLAND IN THE VIRTUALENV  *************************"
+set -x
+cd ${FLATLAND_BASEDIR}
+python setup.py install
+# ensure jupyter is installed in the virtualenv
+pip install -r ${FLATLAND_BASEDIR}/requirements_dev.txt -r requirements_continuous_integration.txt
+
+set +x
+echo "************ INSTALL JUPYTER EXTENSION *************************"
+set -x
+jupyter nbextension install --py --sys-prefix widgetsnbextension
+jupyter nbextension enable --py --sys-prefix widgetsnbextension
+jupyter nbextension install --py --sys-prefix jpy_canvas
+jupyter nbextension enable --py --sys-prefix jpy_canvas
+jupyter notebook
diff --git a/setup.py b/setup.py
index eaabda40..7e9a8b04 100644
--- a/setup.py
+++ b/setup.py
@@ -8,6 +8,7 @@ import sys
 
 from setuptools import setup, find_packages
 
+assert sys.version_info >= (3, 6)
 with open('README.rst') as readme_file:
     readme = readme_file.read()
 
-- 
GitLab