From 77f40595338ca01e173feefdc426b2e0289a515e Mon Sep 17 00:00:00 2001 From: "Xavier(Tianhao) Chi" Date: Sun, 26 May 2024 19:02:59 -0400 Subject: [PATCH] add install and fix workflow --- .github/workflows/macos.yml | 9 ++-- .github/workflows/ubuntu.yml | 9 ++-- install.bash | 97 ++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 install.bash diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 699f264..2aec143 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -28,13 +28,10 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install pip - run: python -m ensurepip --upgrade - - - name: Install dependencies + - name: Run install script run: | - python -m pip install --upgrade pip - python -m pip install hatch + chmod +x ./scripts/install.sh + ./scripts/install.sh - name: Cache packages uses: actions/cache@v3 diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 325f2b6..11d7d12 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -28,11 +28,10 @@ jobs: with: python-version: 3.11 - - name: Install Pip - run: python -m ensurepip --upgrade - - - name: Install Hatch - run: python -m pip install hatch + - name: Run install script + run: | + chmod +x ./scripts/install.bash + ./scripts/install.bash - name: Cache packages uses: actions/cache@v3 diff --git a/install.bash b/install.bash new file mode 100644 index 0000000..acd5d25 --- /dev/null +++ b/install.bash @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# Function to check for "-y" flag to skip prompts +for arg; do + if [ "$arg" = "-y" ]; then + # Set an environment variable when -y is present + export SKIP_PROMPT=true + else + export SKIP_PROMPT=false + fi +done + +# Package installation functions +mbd_install_linux_packages() { + sudo apt-get update + if dpkg -s python3 python3-pip python3-venv libcairo2-dev libgirepository1.0-dev libffi-dev portaudio19-dev python3-gi python3-gi-cairo gir1.2-gtk-3.0 libgirepository1.0-dev >/dev/null 2>&1; then + echo "All required linux packages are already installed." + else + echo "Installing required packages without prompt..." + sudo apt-get install -y python3 python3-pip python3-venv + sudo apt-get install -y libcairo2-dev libgirepository1.0-dev + sudo apt-get install -y libffi-dev + sudo apt-get install -y portaudio19-dev + sudo apt install -y python3-gi python3-gi-cairo gir1.2-gtk-3.0 + sudo apt-get install -y libgirepository1.0-dev + CFLAGS="-march=native" pip install pyaudio + python3 -m pip install hatch + fi +} + +mbd_install_macos_packages() { + export PATH=/usr/local/bin:/usr/local/sbin:$PATH + if command -v brew >/dev/null; then + echo "Homebrew is already installed." + else + echo "Installing Homebrew..." + NONINTERACTIVE=$SKIP_PROMPT /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + fi + if brew list hatch cairo pygobject3 libffi >/dev/null 2>&1; then + echo "All required macos packages are already installed." + else + echo "Installing required packages..." + brew update + brew install hatch + brew install cairo + brew install pygobject3 + brew install libffi + brew install portaudio + + PKG_CONFIG_PATH="$(brew --prefix libffi)/lib/pkgconfig:$PKG_CONFIG_PATH" + export PKG_CONFIG_PATH + LDFLAGS="-L$(brew --prefix libffi)/lib" + export LDFLAGS + CPPFLAGS="-I$(brew --prefix libffi)/include" + export CPPFLAGS + fi +} + +# Detect the operating system +OS=$(uname -s) + +if [[ $OS == "Linux" ]]; then + if [[ "$SKIP_PROMPT" = false ]]; then + read -rp "Install required Linux packages? (y/n) " response + if [[ $response =~ ^[Yy]$ ]]; then + mbd_install_linux_packages + else + echo "Skipping linux package installation." + fi + else + mbd_install_linux_packages + fi + +elif [[ $OS == "Darwin" ]]; then + if [[ "$SKIP_PROMPT" = false ]]; then + read -rp "Install required macOS packages? (y/n) " response + if [[ $response =~ ^[Yy]$ ]]; then + mbd_install_macos_packages + else + echo "Skipping package installation." + fi + else + mbd_install_macos_packages + fi +else + # Unsupported operating system + echo "Unsupported operating system: $OS" + exit 1 +fi + +if [[ -z "$CI" ]]; then + # shellcheck disable=SC1091 + hatch run echo "Sourcing environment..." + source .mbodied/envs/mbodied/bin/activate +else + echo "CI environment detected. Skipping sourcing of environment." +fi