|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright (C) 2022, 2024, 2025 David Cattermole. |
| 4 | +# |
| 5 | +# This file is part of mmSolver. |
| 6 | +# |
| 7 | +# mmSolver is free software: you can redistribute it and/or modify it |
| 8 | +# under the terms of the GNU Lesser General Public License as |
| 9 | +# published by the Free Software Foundation, either version 3 of the |
| 10 | +# License, or (at your option) any later version. |
| 11 | +# |
| 12 | +# mmSolver is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU Lesser General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU Lesser General Public License |
| 18 | +# along with mmSolver. If not, see <https://www.gnu.org/licenses/>. |
| 19 | +# --------------------------------------------------------------------- |
| 20 | +# |
| 21 | +# Common Python virtual environment activation script for Linux. |
| 22 | +# |
| 23 | +# This script expects MAYA_VERSION to be set before calling. |
| 24 | +# It reads configuration from scripts/config/maya_settings.py |
| 25 | + |
| 26 | +# Validate that MAYA_VERSION is set. |
| 27 | +if [ -z "$MAYA_VERSION" ]; then |
| 28 | + echo "ERROR: MAYA_VERSION must be set before calling this script" |
| 29 | + return 1 |
| 30 | +fi |
| 31 | + |
| 32 | +# The -e flag causes the script to exit as soon as one command returns |
| 33 | +# a non-zero exit code. |
| 34 | +set -ev |
| 35 | + |
| 36 | +PROJECT_ROOT=$(pwd) |
| 37 | + |
| 38 | +# Use Python to get configuration settings |
| 39 | +PYTHON_CONFIG_SCRIPT="${PROJECT_ROOT}/scripts/config/maya_settings.py" |
| 40 | +if [ ! -f "$PYTHON_CONFIG_SCRIPT" ]; then |
| 41 | + echo "ERROR: Configuration file not found: $PYTHON_CONFIG_SCRIPT" |
| 42 | + return 1 |
| 43 | +fi |
| 44 | + |
| 45 | +# Get settings using Python configuration. |
| 46 | +eval $(python3 -c " |
| 47 | +import sys |
| 48 | +import os |
| 49 | +sys.path.insert(0, os.path.join('$PROJECT_ROOT', 'scripts', 'config')) |
| 50 | +from maya_settings import MayaConfig |
| 51 | +
|
| 52 | +config = MayaConfig('linux') |
| 53 | +python_exe = config.get_python_exe('$MAYA_VERSION') |
| 54 | +venv_dir_name = config.get_python_venv_dir_name('$MAYA_VERSION') |
| 55 | +
|
| 56 | +print(f'PYTHON_EXE={python_exe}') |
| 57 | +print(f'PYTHON_VIRTUAL_ENV_DIR_NAME={venv_dir_name}') |
| 58 | +") |
| 59 | + |
| 60 | +# Validate that we got the required settings. |
| 61 | +if [ -z "$PYTHON_EXE" ]; then |
| 62 | + echo "ERROR: PYTHON_EXE not found for Maya version $MAYA_VERSION" |
| 63 | + return 1 |
| 64 | +fi |
| 65 | + |
| 66 | +if [ -z "$PYTHON_VIRTUAL_ENV_DIR_NAME" ]; then |
| 67 | + echo "ERROR: PYTHON_VIRTUAL_ENV_DIR_NAME not found for Maya version $MAYA_VERSION" |
| 68 | + return 1 |
| 69 | +fi |
| 70 | + |
| 71 | +# Export variables and call the existing internal script. |
| 72 | +export PYTHON_EXE |
| 73 | +export PYTHON_VIRTUAL_ENV_DIR_NAME |
| 74 | + |
| 75 | +echo "Maya Version: $MAYA_VERSION" |
| 76 | +echo "Python Executable: $PYTHON_EXE" |
| 77 | +echo "Virtual Environment: $PYTHON_VIRTUAL_ENV_DIR_NAME" |
| 78 | + |
| 79 | +source "${PROJECT_ROOT}/scripts/internal/python_venv_activate.bash" |
0 commit comments