From b899ec2c03de383c7b92855f5da08e3079a71a09 Mon Sep 17 00:00:00 2001 From: Julianne Swinoga Date: Mon, 1 Jul 2024 11:01:28 -0400 Subject: [PATCH] TEMP MacOS WIP --- .github/workflows/build-and-release.yaml | 50 ++++++++- README.md | 8 +- scripts/OATFWGUI_Linux.sh | 2 +- scripts/OATFWGUI_Mac.command | 126 +++++++++++++++++++++++ 4 files changed, 179 insertions(+), 7 deletions(-) create mode 100755 scripts/OATFWGUI_Mac.command diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index ea0e736..5a05f7c 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -123,7 +123,7 @@ jobs: name: ${{ env.ARTIFACT_ZIP_NAME }} path: ${{ env.ARTIFACT_ZIP_NAME }}.zip - build-virtualenv: + build-linux: runs-on: 'ubuntu-20.04' strategy: matrix: @@ -177,10 +177,56 @@ jobs: name: ${{ env.ARTIFACT_ZIP_NAME }} path: ${{ env.ARTIFACT_ZIP_NAME }}.zip + build-macos: + runs-on: 'macos-11' + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + cache: 'pip' + + - name: Run set_version script + uses: ./.github/actions/run-set_version_script + + - run: mkdir dist/ + - run: cp -rv OATFWGUI/ dist/ + - run: cp -v scripts/OATFWGUI_Mac.command dist/ + - run: cp -v requirements.txt dist/ + + - name: Smoke test + run: QT_QPA_PLATFORM=offscreen ./dist/OATFWGUI_Mac.command --no-gui + + - name: Retrieve version + id: version + run: echo "OATFWGUI_VERSION=$(./dist/OATFWGUI_Mac.command --version | tail -1)" >> $GITHUB_ENV + - name: Output version + run: echo "Version is ${{ env.OATFWGUI_VERSION }}" + + - name: Remove smoke test artifacts + run: | + rm -rv ./dist/logs + rm -rv ./dist/.venv_* + rm -rv ./dist/OATFWGUI/__pycache__ + - name: Set artifact name + run: echo "ARTIFACT_ZIP_NAME=OATFWGUI_${{ env.OATFWGUI_VERSION }}_${{ runner.os }}_${{ runner.arch }}" >> $GITHUB_ENV + - name: Rename and Zip artifacts + run: mv dist $ARTIFACT_ZIP_NAME && 7z a -tzip $ARTIFACT_ZIP_NAME.zip $ARTIFACT_ZIP_NAME/ + env: + ARTIFACT_ZIP_NAME: ${{ env.ARTIFACT_ZIP_NAME }} + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ env.ARTIFACT_ZIP_NAME }} + path: ${{ env.ARTIFACT_ZIP_NAME }}.zip + publish-release: # only publish release on tags if: ${{ startsWith(github.ref, 'refs/tags/') == true }} - needs: [build-windows, build-virtualenv] + needs: [build-windows, build-linux, build-macos] runs-on: 'ubuntu-20.04' permissions: # See https://github.com/softprops/action-gh-release/issues/236#issuecomment-1150530128 diff --git a/README.md b/README.md index e796daa..125fe97 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,14 @@ OpenAstroTech FirmWare Graphical User Interface -- A graphical way to build and - Windows 64 bit - Linux 64 bit - Requires Python 3.7..3.11, git, libc >= 2.28 (check with `ldd --version`) - -MacOS support [is in progress](https://github.com/OpenAstroTech/OATFWGUI/commits/feature/js/official-mac-support/), but isn't reliable yet. +- MacOS 11+ (probably, not very well tested) + - Requires Python 3.7..3.11, git ## Installing Simply download the [latest release](https://github.com/OpenAstroTech/OATFWGUI/releases), unzip and run: - Windows: `OATFWGUI_Windows.bat` -- Linux: `OATFWGUI_Linux.sh` - - Override the python interpreter by setting `PYTHON` (i.e. `PYTHON=/usr/bin/python3.10 ./OATFWGUI_Linux.sh`) +- Linux: `OATFWGUI_Linux.sh` and MacOS: `OATFWGUI_Mac.command` + - You can override the python version by setting `PYTHON` (i.e. `PYTHON=/usr/bin/python3.10 ./OATFWGUI_Linux.sh`) - This creates a local python virtual environment in `.venv_OATFWGUI`. If there's an error during the first run, delete that folder to have the script try again. > :warning: **OATFWGUI requires an active internet connection!** diff --git a/scripts/OATFWGUI_Linux.sh b/scripts/OATFWGUI_Linux.sh index 6926378..9b630ff 100755 --- a/scripts/OATFWGUI_Linux.sh +++ b/scripts/OATFWGUI_Linux.sh @@ -116,7 +116,7 @@ i.e. PYTHON=/usr/bin/python3.9 ./OATFWGUI_Linux.sh" SCRIPT_DIR="$( dirname -- "$( readlink -f -- "$0"; )"; )" echo "Script dir: $SCRIPT_DIR" pushd "$SCRIPT_DIR" # relative paths can now be used - +exit 0 if ! check_ldd_version; then echo "Unsupported LIBC version, sorry :/" exit 1 diff --git a/scripts/OATFWGUI_Mac.command b/scripts/OATFWGUI_Mac.command new file mode 100755 index 0000000..dc6c3b2 --- /dev/null +++ b/scripts/OATFWGUI_Mac.command @@ -0,0 +1,126 @@ +#!/bin/bash +set -e +# This is the entry point for the "compiled" MacOS app +# Note that this based off of the Linux script, except for: +# - removal of the libc version check +# - conversion from GNU to BSD-isms +# - special checking for python3 installation + +# list_include_item "10 11 12" "2" +function list_include_item { + local list="$1" + local item="$2" + if [[ $list =~ (^|[[:space:]])"$item"($|[[:space:]]) ]] ; then + # yes, list include item + return 0 + else + return 1 + fi +} + +function check_py_version { + local PY_VER_RAW + PY_VER_RAW=$($PYTHON --version) + echo "Python version: $PY_VER_RAW" + if ! [[ $PY_VER_RAW =~ ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+) ]]; then + echo "Could not match python version! Not sure what's going on." + return 1 + fi + local PY_VER_ALL=${BASH_REMATCH[0]} + local PY_VER_MAJ=${BASH_REMATCH[1]} + local PY_VER_MIN=${BASH_REMATCH[2]} + # local PY_VER_PAT=${BASH_REMATCH[3]} + + # Only support python 3 + if ! list_include_item '3' "$PY_VER_MAJ"; then + echo "Python major version $PY_VER_MAJ ($PY_VER_ALL) is not supported" + return 1 + fi + # Only support 3.7+ + if ! list_include_item '7 8 9 10 11' "$PY_VER_MIN"; then + echo "Python minor version $PY_VER_MIN ($PY_VER_ALL) is not supported" + return 1 + fi + return 0 +} + +function will_get_stub_popup { + # https://stackoverflow.com/a/71150139/1313872 but modified for all stubs + echo "Checking if $1 is a stub" + if [[ $(which "$1") == "/usr/bin/$1"* ]]; then + if [ -d "/Applications/Xcode.app/Contents/Developer/usr/bin/$1" ]; then + return 1 # won't get a popup if we try to launch + else + return 0 # not installed, we'll get a popup + fi + else + return 1 # won't get a popup if we try to launch + fi +} + +function set_supported_python_path { + if [ -n "${PYTHON+x}" ]; then + # PYTHON is being set from the CLI + echo "PYTHON overridden: $PYTHON" + if check_py_version; then + return 0 + fi + echo "Overridden PYTHON not supported. Checking system python versions." + fi + # We already checked that python3 isn't a stub + if command -v python3 > /dev/null; then + PYTHON=$(command -v python3) + if ! check_py_version; then + # check_py_version already gives an error message + echo "python3 version is not valid" + exit 1 + fi + fi +} + +# Main script logic +# "readlink -f" not available: https://unix.stackexchange.com/a/690000 +SCRIPT_DIR=$( cd "$(dirname "$0")" ; pwd -P ) +echo "Script dir: $SCRIPT_DIR" +pushd "$SCRIPT_DIR" > /dev/null # relative paths can now be used + +if will_get_stub_popup python3; then + echo '' + echo 'python3 is not installed. The quickest and least intrusive way to install is https://www.python.org/downloads/release/python-3114/' + echo '(download links are at the bottom)' + echo "Note that you do not need to install \"Python Documentation\" or \"GUI Applications\"" + echo "(click \"Customize\" during the \"Installation Type\" step)" + echo '' + exit 1 +fi + +if will_get_stub_popup git; then + echo '' + echo 'git is not installed. The quickest and least intrusive way to install is https://sourceforge.net/projects/git-osx-installer/files/' + echo '' + exit 1 +fi + +VENV_PATH='./.venv_OATFWGUI' +if [ ! -d "$VENV_PATH" ]; then + echo "$VENV_PATH is not present, installing virtual environment" + + set_supported_python_path # This sets $PYTHON + echo "Python command is $PYTHON" + # check venv is available + if ! $PYTHON -c 'import venv' > /dev/null; then + echo "Python 'venv' module is not installed. Please install it into the $PYTHON environment" + exit 1 + fi + + $PYTHON -m venv --prompt 'OATFWGUI>' "$VENV_PATH" + echo "Upgrading pip" + $VENV_PATH/bin/pip install --upgrade pip + echo "Installing requirements" + $VENV_PATH/bin/pip install --requirement ./requirements.txt +fi +# activate virtual environment +source $VENV_PATH/bin/activate +# now can can just run python -- no need to use system $PYTHON +python3 OATFWGUI/main.py "$@" +popd >> /dev/null