Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ jobs:
cache: 'pip' # caching pip dependencies
- run: |
echo $GITHUB_WORKSPACE
cd $GITHUB_WORKSPACE/.github
pip install -r requirements.txt
cd $GITHUB_WORKSPACE/Utilities/Python
source setup_python_env.sh --batchmode

- name: Python test
run: |
echo $GITHUB_WORKSPACE
cd $GITHUB_WORKSPACE/Utilities/Python
source $GITHUB_WORKSPACE/.github/fds_python_env/bin/activate
python hello_world.py
: # python FDS_verification_script.py
145 changes: 145 additions & 0 deletions Utilities/Python/setup_python_env.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
@echo off
REM Configure Spyder IDE for FDS (WINDOWS)
REM Usage (WINDOWS):
REM 1. Install Python 3.11 or below and add its "python.exe" folder to the PATH
REM 2. Open normal Windows Command Prompt
REM 3. call ./setup_python_env.bat [--batchmode]

setlocal enabledelayedexpansion

REM === Parse command-line arguments ===
set BATCHMODE=false
for %%a in (%*) do (
if "%%a"=="--batchmode" set BATCHMODE=true
)

REM === Check for python ===
where python >nul 2>nul
if errorlevel 1 (
set ERROR_MSG=python is not installed or not in PATH
call :ERROR_EXIT
)

REM === Ensure Python version >= 3.7 ===
for /f "delims=" %%v in ('python -c "import sys; print(sys.version_info[0])"') do set PY_MAJOR=%%v
for /f "delims=" %%v in ('python -c "import sys; print(sys.version_info[1])"') do set PY_MINOR=%%v

if %PY_MAJOR% LSS 3 (
set ERROR_MSG=Python 3.7 or higher is required. Found %PY_MAJOR%.%PY_MINOR%.
call :ERROR_EXIT
)
if %PY_MAJOR%==3 if %PY_MINOR% LSS 7 (
set ERROR_MSG=Python 3.7 or higher is required. Found %PY_MAJOR%.%PY_MINOR%.
call :ERROR_EXIT
)

echo Python version is OK: %PY_MAJOR%.%PY_MINOR%

REM === Save current directory and navigate to .github folder ===
set CURDIR=%cd%
cd /d "%~dp0..\..\.."
if errorlevel 1 (
set ERROR_MSG=Failed to navigate to repo root
call :ERROR_EXIT
)
set REPOROOT=%cd%
cd /d "%REPOROOT%\fds\.github"
if errorlevel 1 (
set ERROR_MSG=Directory not found: %REPOROOT%\fds\.github
call :ERROR_EXIT
)

REM === Setup virtual environment ===
set VENV_DIR=fds_python_env
set INSTALL_REQUIREMENTS=false

if exist "%VENV_DIR%" (
if "%BATCHMODE%"=="true" (
echo Batch mode: activating existing virtual environment without prompts or deletion.
) else (
echo ⚠ Virtual environment "%VENV_DIR%" already exists.
set /p choice="Do you want to reinstall everything? (y/N): "
if /i "!choice!"=="y" (
REM Deactivate if currently active (only works if environment was manually activated)
if defined VIRTUAL_ENV (
call deactivate
)
echo Removing old environment...
rmdir /s /q "%VENV_DIR%" || (
set ERROR_MSG=Failed to remove existing virtual environment
call :ERROR_EXIT
)
echo Creating new virtual environment...
python -m venv "%VENV_DIR%" || (
set ERROR_MSG=Failed to create virtual environment
call :ERROR_EXIT
)
set INSTALL_REQUIREMENTS=true
) else (
echo Activating existing environment...
)
)
) else (
echo Creating new virtual environment...
python -m venv "%VENV_DIR%" || (
set ERROR_MSG=Failed to create virtual environment
call :ERROR_EXIT
)
set INSTALL_REQUIREMENTS=true
)

REM === Activate environment ===
if not exist "%VENV_DIR%\Scripts\activate.bat" (
set ERROR_MSG=Virtual environment activation script not found
call :ERROR_EXIT
)
call "%VENV_DIR%\Scripts\activate.bat" || (
set ERROR_MSG=Failed to activate virtual environment
call :ERROR_EXIT
)

REM === Upgrade pip and install requirements if flagged ===
if "%INSTALL_REQUIREMENTS%"=="true" (
echo Installing/updating required Python packages...
python -m pip install --upgrade pip || (
set ERROR_MSG=Failed to upgrade pip
call :ERROR_EXIT
)
if exist requirements.txt (
python -m pip install -r requirements.txt || (
set ERROR_MSG=Failed to install requirements
call :ERROR_EXIT
)
)
)

REM === Set PYTHONPATH ===
set PYTHONPATH=%REPOROOT%\fds\Utilities\Python;%PYTHONPATH%

REM === Run test script ===
cd /d "%REPOROOT%\fds\Utilities\Python"
if not exist hello_world.py (
set ERROR_MSG=hello_world.py not found
call :ERROR_EXIT
)
python hello_world.py || (
set ERROR_MSG=hello_world.py failed
call :ERROR_EXIT
)

REM === Return to original directory ===
cd /d "%CURDIR%"

echo.
echo Python environment setup complete.

REM === Error handler ===
:ERROR_EXIT
if "%ERROR_MSG%"=="" (
echo.
) else (
echo *** Error: %ERROR_MSG%
)
exit /b 1

endlocal
94 changes: 94 additions & 0 deletions Utilities/Python/setup_python_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash
# Configure Spyder IDE for FDS
# Usage (Linux and macOS):
# source ./setup_spyder_env.sh

set -e # Exit immediately if a command exits with a non-zero status

BATCHMODE=false

# Parse command-line arguments
for arg in "$@"; do
case $arg in
--batchmode)
BATCHMODE=true
shift
;;
esac
done

function error_exit {
echo "*** Error: $1"
return 1
}


# Check Python version > 3.7
PYTHON_VERSION=$(python3 -c 'import sys; print("{}.{}".format(sys.version_info.major, sys.version_info.minor))')
REQUIRED_VERSION=3.7
if (( $(echo "$PYTHON_VERSION < $REQUIRED_VERSION" | bc -l) )); then
echo "Python 3.7 or higher is required. Found $PYTHON_VERSION."
echo "Stopping python environment setup."
return
else
echo "Python version is OK: $PYTHON_VERSION"
fi

# Save current directory to return later
curdir=$(pwd)

# Go to .github folder
cd "$(dirname "${BASH_SOURCE[0]}")/../../.." || error_exit "Failed to locate repo root"
reporoot=$(pwd)
cd "$reporoot/fds/.github" || error_exit "Directory not found: $reporoot/fds/.github"

VENV_DIR="fds_python_env"
VENV_BIN="$VENV_DIR/bin"
INSTALL_REQUIREMENTS=false

# Check if virtual environment exists
if [ -d "$VENV_DIR" ]; then
if [ "$BATCHMODE" = true ]; then
echo "Batch mode: activating existing virtual environment without prompts."
else
echo "Virtual environment '$VENV_DIR' already exists."
read -p "Do you want to reinstall everything? (y/N): " choice
case "$choice" in
[yY]|[yY][eE][sS])
echo "Removing old environment..."
rm -rf "$VENV_DIR" || error_exit "Failed to remove existing virtual environment"
echo "Creating new virtual environment..."
python3 -m venv "$VENV_DIR" || error_exit "Failed to create virtual environment"
INSTALL_REQUIREMENTS=true
;;
*)
echo "Activating existing environment..."
;;
esac
fi
else
echo "Creating new virtual environment..."
python3 -m venv "$VENV_DIR" || error_exit "Failed to create virtual environment"
INSTALL_REQUIREMENTS=true
fi
source "$VENV_BIN/activate" || error_exit "Failed to activate virtual environment"

# Install requirements only if flagged
if [ "$INSTALL_REQUIREMENTS" = true ]; then
echo "Installing/updating required Python packages..."
pip install --upgrade pip
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt || error_exit "Failed to install requirements"
fi
fi

export PYTHONPATH="$reporoot/fds/Utilities/Python:$PYTHONPATH"

# Run test script to verify environment
cd "$reporoot/fds/Utilities/Python" || error_exit "Failed to find script directory"
python hello_world.py || error_exit "hello_world.py failed"

# Return to original directory
cd "$curdir"

echo "Python environment setup complete."
113 changes: 0 additions & 113 deletions Utilities/Python/setup_spyder_env.bat

This file was deleted.

Loading
Loading