Skip to content

Commit

Permalink
Migrate to GitHub Actions (#187)
Browse files Browse the repository at this point in the history
* Create test_pysteps.yml

* Install gcc for macos

* Do not install pygrib on win

* Add black check

* Run black on PR

* Run only on pushes to master

* Upload to codecov

Co-authored-by: Andres Perez Hortal <andresperezcba@gmail.com>
Co-authored-by: Andres Perez Hortal <aperezhortal@gmail.com>
Co-authored-by: Ruben Imhoff <31476760+RubenImhoff@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 24, 2020
1 parent 4c988ad commit 221a28f
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 204 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will test the code base using the LATEST version of black

# IMPORTANT: Black is under development. Hence, minor fommatting changes between
# different version are expected.
# If this test fails, install the latest version of black and then run black.
# Preferably, run black only on the files that you have modified.
# This will faciliate the revision of the proposed changes.

name: Black

on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black
- name: Black version
run: black --version

- name: Black check
working-directory: ${{github.workspace}}
run: black --check .
108 changes: 108 additions & 0 deletions .github/workflows/test_pysteps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Test Pysteps installation

env:
MINIMAL_DEPENDENCIES: cython numpy jsmin jsonschema matplotlib netCDF4 opencv pillow pyproj scipy dask
OPTIONAL_DEPENDENCIES: dask pyfftw cartopy h5py PyWavelets
TEST_DEPENDENCIES: pytest pytest-cov codecov

on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
unit_tests:
name: Unit Tests (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
python-version: [ "3.6", "3.8" ]
max-parallel: 6

defaults:
run:
shell: bash -l {0}

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

- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v2.0.0
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
channels: conda-forge
channel-priority: flexible
activate-environment: test-environment

- name: Install dependencies
env:
PACKAGES: ${{env.MINIMAL_DEPENDENCIES}} ${{env.OPTIONAL_DEPENDENCIES}} ${{env.TEST_DEPENDENCIES}}
PYSTEPS_DATA_PATH: ${{github.workspace}}/pysteps_data
run: |
conda install --quiet ${{env.PACKAGES}}
- name: Install pysteps for MacOS
if: matrix.os == 'macos-latest'
working-directory: ${{github.workspace}}
env:
CC: gcc-9
CXX: g++-9
CXX1X: g++-9
HOMEBREW_NO_INSTALL_CLEANUP: 1
run: |
brew update-reset
brew update
brew install gcc@9
gcc-9 --version
pip install .
- name: Install pygrib (not win)
if: matrix.os != 'windows-latest'
run: conda install --quiet pygrib

- name: Install pysteps
if: matrix.os != 'macos-latest'
working-directory: ${{github.workspace}}
run: pip install .

- name: Download pysteps data
env:
PYSTEPS_DATA_PATH: ${{github.workspace}}/pysteps_data
working-directory: ${{github.workspace}}/ci
run: python fetch_pysteps_data.py

- name: Check imports
working-directory: ${{github.workspace}}/pysteps_data
run: |
python -c "import pysteps; print(pysteps.__file__)"
python -c "from pysteps import motion"
python -c "from pysteps.motion import vet"
python -c "from pysteps.motion import proesmans"
- name: Run tests and coverage report
working-directory: ${{github.workspace}}/pysteps_data
env:
PYSTEPSRC: ${{github.workspace}}/pysteps_data/pystepsrc
run: pytest --pyargs pysteps --cov=pysteps --cov-report=xml --cov-report=term -ra

- name: Upload coverage to Codecov (Linux only)
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v1
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
with:
file: ${{github.workspace}}/pysteps_data/coverage.xml
flags: unit_tests
env_vars: OS,PYTHON
fail_ci_if_error: true
verbose: true
142 changes: 0 additions & 142 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions ci/fetch_pysteps_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
Script used to install the pysteps data in a test environment and set a pystepsrc
configuration file that points to that data.
The test data is downloaded in the `PYSTEPS_DATA_DIR` environmental variable.
The test data is downloaded in the `PYSTEPS_DATA_PATH` environmental variable.
After this script is run, the `PYSTEPSRC` environmental variable should be set to
PYSTEPSRC=$PYSTEPS_DATA_DIR/pystepsrc for pysteps to use that configuration file.
PYSTEPSRC=$PYSTEPS_DATA_PATH/pystepsrc for pysteps to use that configuration file.
"""

import os

from pysteps.datasets import create_default_pystepsrc, download_pysteps_data

tox_test_data_dir = os.environ["PYSTEPS_DATA_DIR"]
tox_test_data_dir = os.environ["PYSTEPS_DATA_PATH"]

download_pysteps_data(tox_test_data_dir, force=True)

Expand Down
19 changes: 0 additions & 19 deletions ci/run_tests.sh

This file was deleted.

7 changes: 4 additions & 3 deletions pysteps/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ def download_pysteps_data(dir_path, force=True):
pbar = ShowProgress()
print("Downloading pysteps-data from github.")
tmp_file_name, _ = request.urlretrieve(
"https://github.com/pySTEPS/pysteps-data/archive/master.zip", reporthook=pbar,
"https://github.com/pySTEPS/pysteps-data/archive/master.zip",
reporthook=pbar,
)
pbar.end(message="Download complete\n")

Expand Down Expand Up @@ -354,7 +355,7 @@ def create_default_pystepsrc(
pystepsrc, pystepsrc.1, pystepsrc.2, etc. exist, they are renamed to respectively
pystepsrc.1, pystepsrc.2, pystepsrc.2, etc. Finally, after the existing files are
backed up, the new configuration file is written.
Parameters
----------
Expand Down Expand Up @@ -414,7 +415,7 @@ def create_default_pystepsrc(
with open(dest_path, "w") as f:
json.dump(rcparams_json, f, indent=4)

return dest_path
return os.path.normpath(dest_path)


def load_dataset(case="fmi", frames=14):
Expand Down
7 changes: 6 additions & 1 deletion pysteps/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ def _default_path():

@pytest.mark.parametrize("config_dir, file_name, expected_path", test_params_paths)
def test_params_file_creation_path(config_dir, file_name, expected_path):
"""Test that the default pysteps parameters file is create in the right place."""
"""Test that the default pysteps parameters file is created in the right place."""

# For windows compatibility
if config_dir is not None:
config_dir = os.path.normpath(config_dir)
expected_path = os.path.normpath(expected_path)

pysteps_data_dir = "dummy/path/to/data"
params_file_path = create_default_pystepsrc(
Expand Down
Loading

0 comments on commit 221a28f

Please sign in to comment.