Skip to content

clean up logic to calculate plot dimensions to always use matplotlib units. added helper function to reduce duplication for logic to convert units #1736

clean up logic to calculate plot dimensions to always use matplotlib units. added helper function to reduce duplication for logic to convert units

clean up logic to calculate plot dimensions to always use matplotlib units. added helper function to reduce duplication for logic to convert units #1736

Workflow file for this run

# This workflow will install Python dependencies, run tests the specified Python version
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python Tests
run-name: ${{ github.event_name == 'workflow_dispatch' && format('{0} vs. {1}', github.ref_name, github.event.inputs.version_to_compare) || github.event.head_commit.message || github.event.pull_request.title }}
on:
push:
branches:
- develop
- develop-ref
- feature_*
- main_*
- bugfix_*
- test_*
paths-ignore:
- 'docs/**'
- '.github/pull_request_template.md'
- '.github/ISSUE_TEMPLATE/**'
- '**/README.md'
- '**/LICENSE.md'
pull_request:
types: [opened, reopened, synchronize]
workflow_dispatch:
inputs:
version_to_compare:
description: 'Name of branch to diff against current branch (default: develop)'
default: 'develop'
jobs:
# New job to determine which branches to test
setup-matrix:
runs-on: ubuntu-latest
outputs:
branches: ${{ steps.set-branches.outputs.branches }}
python-versions: ${{ steps.set-py-versions.outputs.versions }}
steps:
- id: set-py-versions
run: echo "versions=[\"3.12\", \"3.13\"]" >> $GITHUB_OUTPUT
- id: set-branches
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "branches=[\"${{ github.head_ref }}\", \"${{ github.base_ref }}\"]" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "branches=[\"${{ github.ref_name }}\", \"${{ github.event.inputs.version_to_compare }}\"]" >> $GITHUB_OUTPUT
else
echo "branches=[\"${{ github.ref_name }}\"]" >> $GITHUB_OUTPUT
fi
build:
needs: setup-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON(needs.setup-matrix.outputs.python-versions) }}
branch: ${{ fromJSON(needs.setup-matrix.outputs.branches) }}
steps:
# checkout METplotpy
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
# checkout METcalcpy
- uses: actions/checkout@v4
with:
repository: dtcenter/METcalcpy
path: METcalcpy
ref: develop
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# force pandas to be less than 3.0.0 for Python 3.12 to test for backward compatibility
if [ ${{ matrix.python-version }} == "3.12" ]; then pip install "pandas<3"; fi
python -m pip install -e METcalcpy
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install --upgrade kaleido
- name: Test with pytest
run: |
export METPLOTPY_TEST_OUTPUT=${{ runner.workspace }}/output/${{ matrix.branch }}
pytest
- name: Upload output data artifact
uses: actions/upload-artifact@v4
with:
name: test_output_${{ matrix.branch }}_${{ matrix.python-version }}
path: ${{ runner.workspace }}/output/${{ matrix.branch }}/test_output
compare-output:
needs: [setup-matrix, build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON(needs.setup-matrix.outputs.python-versions) }}
# Only run if there are exactly 2 branches to compare
if: fromJSON(needs.setup-matrix.outputs.branches)[1] != null
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ${{ runner.workspace }}/artifacts
- name: Checkout diff_util.py from METplus
uses: actions/checkout@v4
with:
repository: dtcenter/METplus
ref: develop
sparse-checkout: |
metplus/util/diff_util.py
sparse-checkout-cone-mode: false
path: METplus
- name: Set up Python for diff_util.py
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies for diff
run: |
pip install pillow pandas numpy netCDF4
- name: Run diff_util.py
run: |
# Extract branch names from the setup-matrix output
# assumes 1st branch is the current branch and the 2nd branch is the truth data
OUTPUT_BRANCH=$(echo '${{ needs.setup-matrix.outputs.branches }}' | jq -r '.[0]')
TRUTH_BRANCH=$(echo '${{ needs.setup-matrix.outputs.branches }}' | jq -r '.[1]')
# Define paths to the downloaded data
# Note: upload-artifact v4 nested paths differently, usually named by 'name' provided in upload
OUTPUT_DIR="${{ runner.workspace }}/artifacts/test_output_${OUTPUT_BRANCH}_${{ matrix.python-version }}"
TRUTH_DIR="${{ runner.workspace }}/artifacts/test_output_${TRUTH_BRANCH}_${{ matrix.python-version }}"
echo "Comparing $OUTPUT_DIR and $TRUTH_DIR"
# Ensure directories exist before running script
if [ -d "$OUTPUT_DIR" ] && [ -d "$TRUTH_DIR" ]; then
export METPLUS_DIFF_SKIP_KEYWORDS=".html,_rank.png"
python METplus/metplus/util/diff_util.py "$TRUTH_DIR" "$OUTPUT_DIR" --debug --save_diff
else
echo "One or both data directories are missing."
ls ${{ runner.workspace }}/artifacts
exit 1
fi