Skip to content

Prepare PyGAD 3.8.1 #102

Prepare PyGAD 3.8.1

Prepare PyGAD 3.8.1 #102

Workflow file for this run

# PyGAD GitHub Actions Workflow
# This workflow uses a Matrix Strategy to test PyGAD across multiple Python versions in parallel.
name: PyGAD PyTest Matrix
permissions:
contents: read
on:
push:
# Trigger the workflow on pushes to the 'github-actions' branch.
branches:
- github-actions
# - master
# Only run the workflow if changes are made in these directories.
paths:
- 'pygad/**'
- 'tests/**'
- 'examples/**'
- 'requirements.txt'
- 'pyproject.toml'
- 'setup.py'
- 'MANIFEST.in'
- '.github/workflows/main.yml'
- '.github/workflows/release.yml'
- 'tools/release.py'
# Test relevant pull requests, including fork contributions, against master.
pull_request:
branches:
- master
paths:
- 'pygad/**'
- 'tests/**'
- 'examples/**'
- 'requirements.txt'
- 'pyproject.toml'
- 'setup.py'
- 'MANIFEST.in'
- '.github/workflows/main.yml'
- '.github/workflows/release.yml'
- 'tools/release.py'
# Allows manual triggering of the workflow from the GitHub Actions tab.
workflow_dispatch:
# Release tags run this same matrix before publishing.
workflow_call:
jobs:
numpy-windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
include:
- python-version: "3.9"
numpy-requirement: "numpy==1.24.4"
numpy-label: "NumPy 1.24.4"
- python-version: "3.14"
numpy-requirement: "numpy"
numpy-label: "Latest NumPy"
name: Windows / Python ${{ matrix.python-version }} / ${{ matrix.numpy-label }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install PyGAD and NumPy
run: python -m pip install . pytest "${{ matrix.numpy-requirement }}"
- name: Verify Installed Versions
working-directory: ${{ runner.temp }}
run: python -c "import numpy, pygad; print('NumPy:', numpy.__version__); print('Testing installed package:', pygad.__file__)"
# Windows used 32-bit storage for dtype=int before NumPy 2.0.
# Run the same regression tests on older and current NumPy releases.
- name: Test Gene Storage and Integer Mutation
working-directory: ${{ runner.temp }}
run: >-
python -m pytest
"${{ github.workspace }}/tests/test_python_int_storage.py"
"${{ github.workspace }}/tests/test_gene_type_conversion.py"
"${{ github.workspace }}/tests/test_initial_population.py"
"${{ github.workspace }}/tests/test_mutation_integer_limits.py"
"${{ github.workspace }}/tests/test_nsga3_population_growth.py"
"${{ github.workspace }}/tests/test_sbx_polynomial.py"
"${{ github.workspace }}/tests/test_parent_selection_regressions.py"
"${{ github.workspace }}/tests/test_permutation_mutation.py"
-q -W error::DeprecationWarning
pytest:
# Use the latest Ubuntu runner for all jobs.
runs-on: ubuntu-latest
# The Strategy Matrix defines the environments to test.
# GitHub Actions will spawn a separate, parallel job for each version in the list.
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
# Dynamic name that appears in the GitHub Actions UI for each parallel job.
name: PyTest / Python ${{ matrix.python-version }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
# Setup the specific Python version defined in the current matrix iteration.
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Install project dependencies from requirements.txt.
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
# Added timeout and no-cache to prevent SSL/Network decryption errors
pip install --default-timeout=100 --no-cache-dir -r requirements.txt
if [ "${{ matrix.python-version }}" != "3.14" ] && [ "${{ matrix.python-version }}" != "3.8" ]; then
# This block runs if the version IS NOT 3.14 or 3.8
# Using a retry loop for large DL frameworks to handle transient network issues
echo "Installing deep learning libraries."
for i in {1..3}; do
pip install --default-timeout=100 --no-cache-dir tensorflow && break || \
(echo "Retry $i failed, waiting 10s..." && sleep 10)
done
pip install --upgrade keras
pip install torch
else
# This block runs if the version IS 3.14 or 3.8
echo "Skipping heavy deep learning libraries for Python ${{ matrix.python-version }}."
fi
# Verify the core deep learning frameworks
echo "Verifying installations..."
python -c "import tensorflow; print('TensorFlow version:', tensorflow.__version__)" || echo "TensorFlow not installed"
python -c "import keras; print('Keras version:', keras.__version__)" || echo "Keras not installed"
python -c "import torch; print('PyTorch version:', torch.__version__)" || echo "PyTorch not installed"
# Build the PyGAD package distribution (generating .tar.gz and .whl files).
# This ensures the package build process is valid on this Python version.
- name: Build PyGAD
run: |
python3 -m pip install --upgrade build
python3 -m build
# Install the newly built .whl file to verify the package is installable.
# Install with the 'visualize' extra so matplotlib is available for the
# plotting tests (tests/test_visualize.py). This also validates that the
# optional 'visualize' extra resolves correctly.
- name: Install PyGAD from Wheel
run: |
WHEEL=$(ls dist/*.whl)
pip install "${WHEEL}[visualize,report]"
- name: Install PyTest
run: |
pip install pytest responses
if [ "${{ matrix.python-version }}" != "3.8" ]; then
pip install 'vilvik>=0.5.4'
fi
# Run the entire test suite using PyTest.
# PyTest automatically discovers all test files in the 'tests/' directory.
# This includes our new tests for visualization, operators, parallel processing, etc.
- name: Run Tests
run: |
# Run outside the checkout so imports exercise the installed wheel.
cd "$RUNNER_TEMP"
python -c "import pygad; print('Testing installed package:', pygad.__file__)"
if [ "${{ matrix.python-version }}" == "3.14" ] || [ "${{ matrix.python-version }}" == "3.8" ]; then
python -m pytest "$GITHUB_WORKSPACE/tests" \
--ignore="$GITHUB_WORKSPACE/tests/test_kerasga.py" \
--ignore="$GITHUB_WORKSPACE/tests/test_torchga.py"
else
python -m pytest "$GITHUB_WORKSPACE/tests"
fi