-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(install): download and install MacOS dependencies
* add messages * add download python line * created cleanup func * helper functions created * partially down python downloading * python installation script complete * added git (and brew) * added git (and brew) * add tesseract and refactor * works on current macbook * install python with brew * install python with brew * check if pyenv is needed * merge2 * merge2 * simplify brew call * finished testing * Less output * split line * Revert adding svg file This reverts commit 5601407. * remove unnecessary things * remove ps1 edit * remove ps1 edits * make the ps1 the same * Remove space * add poetry and aesthetic changes * small changes * add brew to path if needed * switch to pip3 * switch to pip3.10
- Loading branch information
Showing
1 changed file
with
118 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,134 @@ | ||
#!/bin/bash | ||
set -e | ||
set -x | ||
|
||
# TODO: Add Tesseract OCR installation: https://tesseract-ocr.github.io/tessdoc/Installation.html | ||
################################ PARAMETERS ################################ | ||
|
||
# Change these if a different version of Python is required | ||
pythonCmd="python3.10" | ||
pythonVerStr="Python 3.10*" | ||
pythonInstallerLoc="https://www.python.org/ftp/python/3.10.11/python-3.10.11-macos11.pkg" | ||
|
||
################################ HELPER FUNCTIONS ################################ | ||
|
||
# Remove OpenAdapt if it exists | ||
Cleanup() { | ||
if [ -d "../OpenAdapt" ]; then | ||
cd .. | ||
rm -rf OpenAdapt | ||
echo "Deleted OpenAdapt directory" | ||
fi | ||
} | ||
|
||
# Run a command and ensure it did not fail | ||
RunAndCheck() { | ||
res=$($1) | ||
|
||
if [[ -z $res ]] || [[ $res == 0 ]]; then | ||
echo "Success: $2 : $res" | ||
if $1 ; then | ||
echo "Success: $2" | ||
else | ||
echo "Failed: $2 : $res" | ||
echo "Failed: $2" | ||
Cleanup | ||
exit 1 | ||
fi | ||
} | ||
[ -d "OpenAdapt" ] && mv OpenAdapt OpenAdapt-$(date +%Y-%m-%d_%H-%M-%S) | ||
RunAndCheck "git clone https://github.com/MLDSAI/OpenAdapt.git" "clone git repo" | ||
|
||
cd OpenAdapt | ||
# Install a command using brew | ||
BrewInstall() { | ||
dependency=$1 | ||
|
||
brew install "$dependency" | ||
if ! CheckCMDExists "$dependency"; then | ||
echo "Failed to download $dependency" | ||
Cleanup | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Return true if a command/exe is available | ||
CheckCMDExists() { | ||
command=$1 | ||
|
||
if command -v "$command" >/dev/null 2>&1; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
CheckPythonExists() { | ||
# Use Python alias of required version if it exists | ||
if CheckCMDExists $pythonCmd; then | ||
return | ||
fi | ||
|
||
RunAndCheck "python3.10 -m venv .venv" "create python virtual environment" | ||
source .venv/bin/activate | ||
pip install wheel | ||
# Use Python exe if it exists and is the required version | ||
pythonGenCmd="python" | ||
if CheckCMDExists $pythonGenCmd; then | ||
res=$(python3 --version) | ||
if echo "$res" | grep -q "$pythonVerStr"; then | ||
return | ||
fi | ||
fi | ||
|
||
# the following line generates a warning: | ||
# Ignoring pywin32: markers 'sys_platform == "win32"' don't match your environment | ||
pip install -r requirements.txt | ||
# Install required Python version | ||
echo Installing Python | ||
brew install [email protected] | ||
|
||
# the following line generates a warning: | ||
# [notice] To update, run: pip install --upgrade pip | ||
pip install -e . | ||
# Make sure python is now available and the right version | ||
if CheckCMDExists $pythonCmd; then | ||
res=$(python3.10 --version) | ||
if [[ "$res" =~ $pythonVerStr ]]; then | ||
return | ||
fi | ||
fi | ||
|
||
# Otherwise, Python is not available | ||
echo "Error after installing python" | ||
Cleanup | ||
exit 1 | ||
} | ||
|
||
################################ INSTALLATION ################################ | ||
|
||
# Download brew | ||
if ! CheckCMDExists "brew"; then | ||
echo Downloading brew, follow the instructions | ||
bash -c "`curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh`" | ||
|
||
# Check the type of chip | ||
cpu=$(sysctl machdep.cpu.brand_string) | ||
if [[ $cpu == *"Apple"* ]]; then | ||
# Add brew to PATH | ||
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile | ||
eval "$(/opt/homebrew/bin/brew shellenv)" | ||
fi | ||
|
||
brewExists=$(CheckCMDExists "brew") | ||
if ! CheckCMDExists "brew"; then | ||
echo "Failed to download brew" | ||
Cleanup | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if ! CheckCMDExists "git"; then | ||
BrewInstall "git" | ||
fi | ||
|
||
if ! CheckCMDExists "tesseract"; then | ||
BrewInstall "tesseract" | ||
fi | ||
|
||
CheckPythonExists | ||
|
||
[ -d "OpenAdapt" ] && mv OpenAdapt OpenAdapt-$(date +%Y-%m-%d_%H-%M-%S) | ||
RunAndCheck "git clone https://github.com/MLDSAI/OpenAdapt.git" "Clone git repo" | ||
|
||
cd OpenAdapt | ||
|
||
RunAndCheck "alembic upgrade head" | ||
RunAndCheck "python3.10 -m spacy download en_core_web_trf" | ||
RunAndCheck "pytest" | ||
RunAndCheck "pip3.10 install poetry" "Install Poetry" | ||
RunAndCheck "poetry install" "Install Python dependencies" | ||
RunAndCheck "poetry run alembic upgrade head" "Update database" | ||
RunAndCheck "poetry run pytest" "Run tests" | ||
RunAndCheck "poetry shell" "Activate virtual environment" | ||
echo OpenAdapt installed successfully! |