Skip to content

Commit

Permalink
Merge pull request #7 from khaeru/setup-ci
Browse files Browse the repository at this point in the history
Set up continuous integration
  • Loading branch information
khaeru committed Jan 10, 2021
2 parents 3eadf46 + 7b2fcb8 commit 5386340
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 4 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: pytest

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: "0 5 * * *"


env:
GAMS_VERSION: 25.1.1
# See description in lint.yml
depth: 100

jobs:
pytest:
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
python-version:
- "3.7" # Earliest version supported by genno; matches xarray
- "3.8" # Latest version testable on GitHub Actions

# For development versions of Python, compiled binary wheels are not
# available for some dependencies, e.g. llvmlite, numba, numpy, and/or
# pandas. Compiling these on the job runner requires a more elaborate
# build environment, currently out of scope for the ixmp project.
# - "3.9" # Latest Python release
# - "3.10.0-alpha.1" # Development version

exclude:
# This job triggers error when importing ixmp.testing: no module named
# ixmp.backend. Not critical, since it's upstream.
- os: windows-latest
python-version: "3.7"

fail-fast: false

runs-on: ${{ matrix.os }}
name: ${{ matrix.os }}-py${{ matrix.python-version }}

steps:
- uses: actions/checkout@v2
with:
path: genno
fetch-depth: ${{ env.depth }}

- name: Fetch tags (for setuptools-scm)
working-directory: genno
run: git fetch --tags --depth=${{ env.depth }}

- name: Check out ixmp
uses: actions/checkout@v2
with:
repository: iiasa/ixmp
path: ixmp
fetch-depth: ${{ env.depth }}

- name: Fetch tags (for setuptools-scm)
working-directory: ixmp
run: git fetch --tags --depth=${{ env.depth }}

- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Use OpenJDK 14 (macOS only)
# Using the default OpenJDK 1.8 on the macos-latest runner produces
# "Abort trap: 6" when JPype1 starts the JVM
if: ${{ startsWith(matrix.os, 'macos') }}
uses: actions/setup-java@v1
with:
java-version: '14'

- name: Cache GAMS installer, Python packages, and R packages
uses: actions/cache@v2
with:
path: |
gams
~/.cache/pip
~/Library/Caches/pip
~/appdata/local/pip/cache
${{ env.R_LIBS_USER }}
key: ${{ matrix.os }}-gams${{ env.GAMS_VERSION }}-py${{ matrix.python-version }}
restore-keys: |
${{ matrix.os }}-gams${{ env.GAMS_VERSION }}-
${{ matrix.os }}-
- name: Install GAMS and Graphviz
env:
CI_OS: ${{ matrix.os }}
working-directory: genno
shell: bash
run: |
ci/install-gams.sh
ci/install-graphviz.sh
- name: Check GAMS
run: gams
shell: bash

- name: Upgrade pip, wheel, setuptools-scm
run: python -m pip install --upgrade pip wheel setuptools-scm

- name: Install ixmp and dependencies, including testing dependencies
working-directory: ixmp
run: pip install .[tests]

- name: Install Python package and dependencies
working-directory: genno
run: pip install .[docs,tests]

- name: Run test suite using pytest
working-directory: genno
run: pytest genno --trace-config --verbose --cov-report=xml --color=yes

- name: Test documentation build using Sphinx
if: ${{ startsWith(matrix.os, 'ubuntu') }}
working-directory: genno/doc
run: make html

- name: Upload test coverage to Codecov.io
uses: codecov/codecov-action@v1.2.1
with:
root_dir: genno
10 changes: 10 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2

python:
version: 3.8
install:
- method: pip
path: .
extra_requirements:
- docs
- tests
18 changes: 17 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
genno: efficient, transparent calculation on N-D data
*****************************************************

.. image:: https://img.shields.io/pypi/v/genno.svg
:target: https://pypi.python.org/pypi/genno/
:alt: PyPI version

.. image:: https://readthedocs.org/projects/genno/badge/?version=latest
:target: https://genno.readthedocs.io/en/latest/?badge=latest
:alt: Documentation build

.. image:: https://github.com/khaeru/genno/workflows/pytest/badge.svg
:target: https://github.com/khaeru/genno/actions?query=workflow:pytest
:alt: Build status

.. image:: https://codecov.io/gh/khaeru/genno/branch/master/graph/badge.svg
:target: https://codecov.io/gh/khaeru/genno
:alt: Test coverage

**genno** is a Python package for describing and executing complex calculations on labelled, multi-dimensional data.
It aims to make these calculations efficient, transparent, and easily validated as part of scientific research.

Expand All @@ -13,6 +29,6 @@ The package name is warning, by reference, to the adage “When you hold a hamme
License
=======

Copyright © 2018–2020 genno developers.
Copyright © 2018–2021 genno developers.

Licensed under the GNU General Public License, version 3.0.
66 changes: 66 additions & 0 deletions ci/install-gams.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh
# Install GAMS.
#
# The environment variables CI_OS and GAMS_VERSION must be set.

BASE=$PWD/gams
mkdir -p $BASE

# GAMS source URL fragment, and path fragment for extracted files
case $CI_OS in
linux* | ubuntu*)
GAMS_OS=linux
FRAGMENT=${GAMS_OS}_x64_64_sfx
;;
macos*)
GAMS_OS=macosx
FRAGMENT=osx_x64_64_sfx
;;
windows*)
GAMS_OS=windows
FRAGMENT=${GAMS_OS}_x64_64
;;
esac

# Retrieve
BASE_URL=https://d37drm4t2jghv5.cloudfront.net/distributions
URL=$BASE_URL/$GAMS_VERSION/$GAMS_OS/$FRAGMENT.exe

if [ -x $BASE/gams.exe ]; then
# Don't retrieve if the remote file is older than the cached one
TIME_CONDITION=--remote-time --time-cond $BASE/gams.exe
fi

curl --silent $URL --output $BASE/gams.exe $TIME_CONDITION

# TODO confirm checksum

# Path fragment for extraction or install
DEST=gams$(echo $GAMS_VERSION | cut -d. -f1-2)_$FRAGMENT

if [ $GAMS_OS = "windows" ]; then
cat << EOF >install-gams.ps1
# Windows-format equivalent of BASE
\$BASE = "\$PWD\gams"
# Install to the same directory as Linux/macOS unzip
Start-Process "\$BASE\gams.exe" "/SP-", "/SILENT", "/DIR=\$BASE\\$DEST", \`
"/NORESTART" -Wait
EOF
cat install-gams.ps1
pwsh install-gams.ps1
else
# Extract files
unzip -q -d $BASE $BASE/gams.exe
fi

# Update PATH
export PATH=$BASE/$DEST:$PATH

# For GitHub Actions
echo "$BASE/$DEST" >> $GITHUB_PATH

# Show location
which gams
18 changes: 18 additions & 0 deletions ci/install-graphviz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
# Install Graphviz.

case $CI_OS in
linux* | ubuntu*)
sudo apt install --quiet graphviz
;;
macos*)
brew install graphviz
;;
windows*)
# Temporary; see https://github.com/iiasa/ixmp/pull/387
choco install --no-progress --version 2.38.0.20190211 graphviz
;;
esac

# Print version
dot -V
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Include ixmp test fixtures, e.g. pre-populated Scenario objects
# TODO remove this dependency
# NB genno must follow ixmp, since pytest prefers fixtures etc. from later in the list
pytest_plugins = ["ixmp.testing", "genno.testing"]
pytest_plugins = ("ixmp.testing", "genno.testing")
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers =
Topic :: Scientific/Engineering :: Information Analysis

[options]
packages = find:
packages = genno
python_requires = >=3.7
include_package_data = True
install_requires =
Expand Down Expand Up @@ -51,7 +51,7 @@ tests =
test = pytest

[tool:pytest]
addopts = --cov genno --cov-report=
addopts = --cov=genno --cov-report=

[isort]
profile = black
Expand Down

0 comments on commit 5386340

Please sign in to comment.