Skip to content

NRPyPN 2.0: Modernized and validated against original NRPyPN (in http… #9

NRPyPN 2.0: Modernized and validated against original NRPyPN (in http…

NRPyPN 2.0: Modernized and validated against original NRPyPN (in http… #9

Workflow file for this run

name: Python CI
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ['3.6.7', '3.x'] # runs jobs on python 3.6.7 and the latest python version
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python --version
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install mypy pylint black clang-format ipython
- name: Display sympy version
run: echo "Running CI tests with SymPy version = $(isympy --version)"
- name: Check mypy and black versions when Python != 3.6.7 chosen (they are too broken in that Python version).
if: matrix.python-version != '3.6.7'
run: |
mypy --version
black --version
- name: Run doctests, black, mypy, and pylint on each file.
run: |
failed_tests=()
# Use find to locate python files based on pattern or directory structure.
# Don't analyze Python scripts in tests/ (though they should pass!)
# Ignore CarpetX infrastructure for now as well...
python_files=$(find . -name '*.py' -not -name '__init__.py' -not -path './build/*' -not -path './nrpy/infrastructures/CarpetX/*' -not -path '*/tests/*')
for python_file in $python_files; do
echo ""
echo "-={ $python_file }=-"
echo "-={ Step 1: Doctests/run Python module }=-"
DOCTEST_MODE=1 PYTHONPATH=.:$PYTHONPATH python $python_file || { failed_tests+=("doctest in $python_file"); break; }
if [ "${{ matrix.python-version }}" != "3.6.7" ]; then
# Turns out that black in Python 3.6.7 has a heart attack when parsing equations/general_relativity/BSSN_quantities.py:
# INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug on .... [HOW ABOUT NO. BEGGING FOR WONTFIX]
echo "-={ Step 2: black $python_file }=-"
black --check $python_file || { failed_tests+=("black in $python_file"); break; }
echo "-={ Step 3: mypy }=-"
PYTHONPATH=.:$PYTHONPATH mypy --strict --pretty --allow-untyped-calls $python_file || { failed_tests+=("mypy in $python_file"); break; }
fi
echo "-={ Step 4: pylint }=-"
if [ "${{ matrix.python-version }}" != "3.6.7" ]; then
PYTHONPATH=.:$PYTHONPATH pylint_score=$(pylint --rcfile=.pylintrc $python_file | tail -2 | grep -Eo '[0-9\.]+' | head -1 || echo "0")
else
PYTHONPATH=.:$PYTHONPATH pylint_score=$(pylint --rcfile=.pylintrc_python36 $python_file | tail -2 | grep -Eo '[0-9\.]+' | head -1 || echo "0")
fi
echo "Pylint score is $pylint_score"
if (( $(echo "$pylint_score < 9.5" | bc -l) )); then
PYTHONPATH=.:$PYTHONPATH pylint --rcfile=.pylintrc $python_file || true
echo "Pylint score is below 9.5, failing..."
failed_tests+=("pylint in $python_file")
break
fi
PYTHONPATH=.:$PYTHONPATH pylint --rcfile=.pylintrc $python_file || true
done
if [ ${#failed_tests[@]} -ne 0 ]; then
echo "The following tests failed: ${failed_tests[*]}"
exit 1
fi
- name: Run validation tests, comparing p_t and p_r against trusted values from original implementation of NRPyPN.
run: |
python -c "import nrpypn.eval_p_t_and_p_r as ev; ev.test_results_against_trusted()"