Skip to content

Fix Python 3.12 compatibility and add Binder environment testing #4

Fix Python 3.12 compatibility and add Binder environment testing

Fix Python 3.12 compatibility and add Binder environment testing #4

name: Test Binder Environment
on:
pull_request:
paths:
- 'environment.yml'
- '.github/workflows/test-binder-environment.yml'
push:
branches:
- main
paths:
- 'environment.yml'
- '.github/workflows/test-binder-environment.yml'
jobs:
test-binder-build:
runs-on: ubuntu-latest
name: Test Binder Environment Build
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true
python-version: "3.12"
channels: conda-forge,defaults
channel-priority: flexible
- name: Display environment info
shell: bash -l {0}
run: |
conda info
conda list
conda config --show-sources
conda config --show channels
- name: Create environment from environment.yml
shell: bash -l {0}
run: |
echo "Creating conda environment from environment.yml..."
mamba env create -n test-binder-env -f environment.yml
- name: Verify environment
shell: bash -l {0}
run: |
echo "Activating environment..."
conda activate test-binder-env
echo "Python version:"
python --version
echo "Installed packages:"
conda list
echo "Verifying binary solvers:"
which glpsol
which cbc
echo "Environment created successfully!"
- name: Test basic imports and functionality
shell: bash -l {0}
run: |
conda activate test-binder-env
python << 'EOF'
import sys
print('Python:', sys.version)
print('Testing core dependencies...')
failed = []
# Test openTEPES
try:
import openTEPES
print('✓ openTEPES imported successfully')
except Exception as e:
print(f'✗ openTEPES import failed: {e}')
failed.append('openTEPES')
# Test tsam
try:
import tsam
print('✓ tsam imported successfully')
except Exception as e:
print(f'✗ tsam import failed: {e}')
failed.append('tsam')
# Test highspy
try:
import highspy
print('✓ highspy imported successfully')
except Exception as e:
print(f'✗ highspy import failed: {e}')
failed.append('highspy')
# Test scikit-learn-extra
try:
import sklearn_extra
print('✓ scikit-learn-extra imported successfully')
except Exception as e:
print(f'✗ scikit-learn-extra import failed: {e}')
failed.append('scikit-learn-extra')
if failed:
print(f'\n❌ {len(failed)} package(s) failed to import: {", ".join(failed)}')
sys.exit(1)
else:
print('\n✅ All core dependencies are working!')
EOF
- name: Summary
if: success()
shell: bash -l {0}
run: |
echo "✅ Binder environment build test PASSED"
echo "The environment.yml configuration is valid and all dependencies can be installed."
echo "This indicates that Binder should be able to build this environment successfully."