|
1 | 1 | #!/bin/sh
|
2 | 2 |
|
3 |
| -if [ "$(uname)" = "Darwin" ]; then |
4 |
| - # macOS specific env: |
5 |
| - export PYTORCH_ENABLE_MPS_FALLBACK=1 |
6 |
| - export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 |
| 3 | +set -fa |
| 4 | + |
| 5 | +# Check if Python is installed |
| 6 | +if ! command -v python; then |
| 7 | + echo "Python not found. Please install Python using your package manager or via PyEnv." |
| 8 | + exit 1 |
7 | 9 | fi
|
8 | 10 |
|
9 |
| -if [ -d ".venv" ]; then |
10 |
| - echo "Activate venv..." |
11 |
| - . .venv/bin/activate |
12 |
| -else |
13 |
| - echo "Create venv..." |
14 |
| - requirements_file="requirements/main.txt" |
| 11 | +requirements_file="requirements/main.txt" |
| 12 | +venv_path=".venv" |
15 | 13 |
|
16 |
| - # Check if Python 3.8 is installed |
17 |
| - if ! (command -v python3.8 >/dev/null 2>&1 || pyenv versions --bare | grep -q "3.8"); then |
18 |
| - echo "Python 3 not found. Attempting to install 3.8..." |
19 |
| - if [ "$(uname)" = "Darwin" ] && command -v brew >/dev/null 2>&1; then |
20 |
| - |
21 |
| - elif [ "$(uname)" = "Linux" ] && command -v apt-get >/dev/null 2>&1; then |
22 |
| - sudo apt update |
23 |
| - sudo apt install -y python3.8 |
24 |
| - else |
25 |
| - echo "Please install Python 3.8 manually." |
26 |
| - exit 1 |
27 |
| - fi |
28 |
| - fi |
| 14 | +if [[ ! -d "${venv_path}" ]]; then |
| 15 | + echo "Creating venv..." |
29 | 16 |
|
30 |
| - python3.8 -m venv .venv |
31 |
| - . .venv/bin/activate |
| 17 | + python -m venv "${venv_path}" |
| 18 | + source "${venv_path}/bin/activate" |
32 | 19 |
|
33 |
| - # Check if required packages are installed and install them if not |
34 |
| - if [ -f "${requirements_file}" ]; then |
35 |
| - installed_packages=$(python3.8 -m pip freeze) |
36 |
| - while IFS= read -r package; do |
37 |
| - expr "${package}" : "^#.*" > /dev/null && continue |
38 |
| - package_name=$(echo "${package}" | sed 's/[<>=!].*//') |
39 |
| - if ! echo "${installed_packages}" | grep -q "${package_name}"; then |
40 |
| - echo "${package_name} not found. Attempting to install..." |
41 |
| - python3.8 -m pip install --upgrade "${package}" |
42 |
| - fi |
43 |
| - done < "${requirements_file}" |
44 |
| - else |
45 |
| - echo "${requirements_file} not found. Please ensure the requirements file with required packages exists." |
46 |
| - exit 1 |
47 |
| - fi |
| 20 | + # Check if required packages are up-to-date |
| 21 | + pip install --upgrade -r "${requirements_file}" |
48 | 22 | fi
|
| 23 | +echo "Activating venv..." |
| 24 | +source "${venv_path}/bin/activate" |
49 | 25 |
|
50 | 26 | # Run the main script
|
51 |
| -python3 web.py --pycmd python3 |
| 27 | +python web.py --pycmd python |
0 commit comments