Skip to content

Commit d65e893

Browse files
Build - Centralise the Python VirtualEnv scripts
1 parent 57f37cf commit d65e893

22 files changed

Lines changed: 218 additions & 203 deletions
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@ECHO OFF
2+
SETLOCAL EnableDelayedExpansion
3+
::
4+
:: Copyright (C) 2021, 2024, 2025 David Cattermole.
5+
::
6+
:: This file is part of mmSolver.
7+
::
8+
:: mmSolver is free software: you can redistribute it and/or modify it
9+
:: under the terms of the GNU Lesser General Public License as
10+
:: published by the Free Software Foundation, either version 3 of the
11+
:: License, or (at your option) any later version.
12+
::
13+
:: mmSolver is distributed in the hope that it will be useful,
14+
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
:: GNU Lesser General Public License for more details.
17+
::
18+
:: You should have received a copy of the GNU Lesser General Public License
19+
:: along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
20+
:: ---------------------------------------------------------------------
21+
::
22+
:: Common Python virtual environment activation script for Windows.
23+
::
24+
:: This script expects MAYA_VERSION to be set before calling.
25+
:: It reads configuration from scripts\config\maya_settings.py
26+
27+
:: Validate that MAYA_VERSION is set.
28+
IF "%MAYA_VERSION%"=="" (
29+
echo ERROR: MAYA_VERSION must be set before calling this script
30+
exit /b 1
31+
)
32+
33+
SET PROJECT_ROOT=%CD%
34+
35+
:: Use Python to get configuration settings.
36+
SET PYTHON_CONFIG_SCRIPT=%PROJECT_ROOT%\scripts\config\maya_settings.py
37+
38+
IF NOT EXIST "%PYTHON_CONFIG_SCRIPT%" (
39+
echo ERROR: Configuration file not found: %PYTHON_CONFIG_SCRIPT%
40+
exit /b 1
41+
)
42+
43+
:: Get settings using Python configuration.
44+
FOR /F "usebackq tokens=1,2 delims==" %%A IN (`python -c "import sys; import os; sys.path.insert(0, os.path.join('%PROJECT_ROOT%', 'scripts', 'config')); from maya_settings import MayaConfig; config = MayaConfig('windows'); print('PYTHON_EXE=' + config.get_python_exe('%MAYA_VERSION%')); print('PYTHON_VIRTUAL_ENV_DIR_NAME=' + config.get_python_venv_dir_name('%MAYA_VERSION%'))"`) DO (
45+
IF "%%A"=="PYTHON_EXE" SET "PYTHON_EXE=%%B"
46+
IF "%%A"=="PYTHON_VIRTUAL_ENV_DIR_NAME" SET "PYTHON_VIRTUAL_ENV_DIR_NAME=%%B"
47+
)
48+
49+
:: Validate required settings.
50+
IF "%PYTHON_EXE%"=="" (
51+
echo ERROR: PYTHON_EXE not found for Maya version %MAYA_VERSION%
52+
exit /b 1
53+
)
54+
55+
IF "%PYTHON_VIRTUAL_ENV_DIR_NAME%"=="" (
56+
echo ERROR: PYTHON_VIRTUAL_ENV_DIR_NAME not found for Maya version %MAYA_VERSION%
57+
exit /b 1
58+
)
59+
60+
:: Print configuration for debugging.
61+
echo Maya Version: %MAYA_VERSION%
62+
echo Python Executable: %PYTHON_EXE%
63+
echo Virtual Environment: %PYTHON_VIRTUAL_ENV_DIR_NAME%
64+
65+
:: Call the existing internal script.
66+
CALL %PROJECT_ROOT%\scripts\internal\python_venv_activate.bat

scripts/python_venv_activate_maya2016.bash

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,8 @@
2424
# $ source scripts/python_venv_activate_maya2016.bash
2525
#
2626

27-
# The -e flag causes the script to exit as soon as one command returns
28-
# a non-zero exit code.
29-
set -ev
27+
# Set Maya version for the common venv activation script.
28+
export MAYA_VERSION=2016
3029

31-
PROJECT_ROOT=`pwd`
32-
33-
MAYA_VERSION=2016
34-
35-
# Python executable - edit this to point to an explicit python
36-
# executable file.
37-
PYTHON_EXE=python
38-
39-
PYTHON_VIRTUAL_ENV_DIR_NAME="python_venv_linux_maya${MAYA_VERSION}"
40-
source "${PROJECT_ROOT}/scripts/internal/python_venv_activate.bash"
30+
# Call the common venv activation script.
31+
source "$(pwd)/scripts/internal/python_venv_activate_common.bash"

scripts/python_venv_activate_maya2016.bat

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
::
2121
:: Activates the Python development environment for Maya 2016.
2222

23-
SET PROJECT_ROOT=%CD%
24-
23+
:: Set Maya version for the common venv activation script.
2524
SET MAYA_VERSION=2016
2625

27-
:: Python executable - edit this to point to an explicit python executable file.
28-
SET PYTHON_EXE=python
29-
30-
SET PYTHON_VIRTUAL_ENV_DIR_NAME=python_venv_windows64_maya%MAYA_VERSION%
31-
CALL %PROJECT_ROOT%\scripts\internal\python_venv_activate.bat
26+
:: Call the common venv activation script.
27+
CALL scripts\internal\python_venv_activate_common.bat

scripts/python_venv_activate_maya2017.bash

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,8 @@
2424
# $ source scripts/python_venv_activate_maya2017.bash
2525
#
2626

27-
# The -e flag causes the script to exit as soon as one command returns
28-
# a non-zero exit code.
29-
set -ev
27+
# Set Maya version for the common venv activation script.
28+
export MAYA_VERSION=2017
3029

31-
PROJECT_ROOT=`pwd`
32-
33-
MAYA_VERSION=2017
34-
35-
# Python executable - edit this to point to an explicit python executable file.
36-
PYTHON_EXE=python
37-
38-
PYTHON_VIRTUAL_ENV_DIR_NAME="python_venv_linux_maya${MAYA_VERSION}"
39-
source "${PROJECT_ROOT}/scripts/internal/python_venv_activate.bash"
30+
# Call the common venv activation script.
31+
source "$(pwd)/scripts/internal/python_venv_activate_common.bash"

scripts/python_venv_activate_maya2017.bat

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
::
2121
:: Activates the Python development environment for Maya 2017.
2222

23-
SET PROJECT_ROOT=%CD%
24-
23+
:: Set Maya version for the common venv activation script.
2524
SET MAYA_VERSION=2017
2625

27-
:: Python executable - edit this to point to an explicit python executable file.
28-
SET PYTHON_EXE=python
29-
30-
SET PYTHON_VIRTUAL_ENV_DIR_NAME=python_venv_windows64_maya%MAYA_VERSION%
31-
CALL %PROJECT_ROOT%\scripts\internal\python_venv_activate.bat
26+
:: Call the common venv activation script.
27+
CALL scripts\internal\python_venv_activate_common.bat

scripts/python_venv_activate_maya2018.bash

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,8 @@
2424
# $ source scripts/python_venv_activate_maya2018.bash
2525
#
2626

27-
# The -e flag causes the script to exit as soon as one command returns
28-
# a non-zero exit code.
29-
set -ev
27+
# Set Maya version for the common venv activation script.
28+
export MAYA_VERSION=2018
3029

31-
PROJECT_ROOT=`pwd`
32-
33-
MAYA_VERSION=2018
34-
35-
# Python executable - edit this to point to an explicit python executable file.
36-
PYTHON_EXE=python
37-
38-
PYTHON_VIRTUAL_ENV_DIR_NAME="python_venv_linux_maya${MAYA_VERSION}"
39-
source "${PROJECT_ROOT}/scripts/internal/python_venv_activate.bash"
30+
# Call the common venv activation script.
31+
source "$(pwd)/scripts/internal/python_venv_activate_common.bash"

scripts/python_venv_activate_maya2018.bat

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
::
2121
:: Activates the Python development environment for Maya 2018.
2222

23-
SET PROJECT_ROOT=%CD%
24-
23+
:: Set Maya version for the common venv activation script.
2524
SET MAYA_VERSION=2018
2625

27-
:: Python executable - edit this to point to an explicit python executable file.
28-
SET PYTHON_EXE=python
29-
30-
SET PYTHON_VIRTUAL_ENV_DIR_NAME=python_venv_windows64_maya%MAYA_VERSION%
31-
CALL %PROJECT_ROOT%\scripts\internal\python_venv_activate.bat
26+
:: Call the common venv activation script.
27+
CALL scripts\internal\python_venv_activate_common.bat

scripts/python_venv_activate_maya2019.bash

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,8 @@
2424
# $ source scripts/python_venv_activate_maya2019.bash
2525
#
2626

27-
# The -e flag causes the script to exit as soon as one command returns
28-
# a non-zero exit code.
29-
set -ev
27+
# Set Maya version for the common venv activation script.
28+
export MAYA_VERSION=2019
3029

31-
PROJECT_ROOT=`pwd`
32-
33-
MAYA_VERSION=2019
34-
35-
# Python executable - edit this to point to an explicit python executable file.
36-
PYTHON_EXE=python
37-
38-
PYTHON_VIRTUAL_ENV_DIR_NAME="python_venv_linux_maya${MAYA_VERSION}"
39-
source "${PROJECT_ROOT}/scripts/internal/python_venv_activate.bash"
30+
# Call the common venv activation script.
31+
source "$(pwd)/scripts/internal/python_venv_activate_common.bash"

scripts/python_venv_activate_maya2019.bat

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
::
2121
:: Activates the Python development environment for Maya 2019.
2222

23-
SET PROJECT_ROOT=%CD%
24-
23+
:: Set Maya version for the common venv activation script.
2524
SET MAYA_VERSION=2019
2625

27-
:: Python executable - edit this to point to an explicit python executable file.
28-
SET PYTHON_EXE=python
29-
30-
SET PYTHON_VIRTUAL_ENV_DIR_NAME=python_venv_windows64_maya%MAYA_VERSION%
31-
CALL %PROJECT_ROOT%\scripts\internal\python_venv_activate.bat
26+
:: Call the common venv activation script.
27+
CALL scripts\internal\python_venv_activate_common.bat

0 commit comments

Comments
 (0)