Skip to content

Commit

Permalink
TEMP MacOS WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
julianneswinoga committed Jul 1, 2024
1 parent 8435efe commit b899ec2
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 7 deletions.
50 changes: 48 additions & 2 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!**
Expand Down
2 changes: 1 addition & 1 deletion scripts/OATFWGUI_Linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
126 changes: 126 additions & 0 deletions scripts/OATFWGUI_Mac.command
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b899ec2

Please sign in to comment.