Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Run pytest through GitHub actions #2529

Merged
merged 7 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Pre-release checks

on:
push:
branches:
- master
- maint/*
pull_request:
branches:
- master
- maint/*

defaults:
run:
shell: bash

jobs:
pre-release:
# Check pre-releases of dependencies on stable Python
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
matrix:
os: ['ubuntu-latest']
python-version: [3.8, 3.9]
install: ['pip']
check: ['tests']
pip-flags: ['PRE_PIP_FLAGS']
env:
INSTALL_TYPE: ${{ matrix.install }}
CHECK_TYPE: ${{ matrix.check }}
EXTRA_PIP_FLAGS: ${{ matrix.pip-flags }}
OS_TYPE: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0
- name: Install dependencies
run: .maint/ci/install_dependencies.sh
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Create virtual environment
run: .maint/ci/create_venv.sh
- name: Build archive
run: |
source .maint/ci/build_archive.sh
echo "ARCHIVE=$ARCHIVE" >> $GITHUB_ENV
- name: Install fMRIPrep
run: .maint/ci/install.sh
- name: Install extras
run: .maint/ci/install_extras.sh
- name: Run tests
run: .maint/ci/check.sh
- uses: codecov/codecov-action@v1
with:
file: coverage.xml
if: ${{ always() }}
62 changes: 62 additions & 0 deletions .github/workflows/stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Stable tests

on:
push:
branches:
- master
- maint/*
pull_request:
branches:
- master
- maint/*

defaults:
run:
shell: bash

jobs:
stable:
# Check each OS, all supported Python, minimum versions and latest releases
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest']
python-version: [3.7, 3.8, 3.9]
install: ['pip']
check: ['tests']
pip-flags: ['']
env:
INSTALL_TYPE: ${{ matrix.install }}
CHECK_TYPE: ${{ matrix.check }}
EXTRA_PIP_FLAGS: ${{ matrix.pip-flags }}
OS_TYPE: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0
- name: Install dependencies
run: .maint/ci/install_dependencies.sh
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Create virtual environment
run: .maint/ci/create_venv.sh
- name: Build archive
run: |
source .maint/ci/build_archive.sh
echo "ARCHIVE=$ARCHIVE" >> $GITHUB_ENV
- name: Install fMRIPrep
run: .maint/ci/install.sh
- name: Install extras
run: .maint/ci/install_extras.sh
- name: Run tests
run: .maint/ci/check.sh
- uses: codecov/codecov-action@v1
with:
file: coverage.xml
if: ${{ always() }}
9 changes: 9 additions & 0 deletions .maint/ci/activate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if [ -e virtenv/bin/activate ]; then
source virtenv/bin/activate
elif [ -e virtenv/Scripts/activate ]; then
source virtenv/Scripts/activate
else
echo Cannot activate virtual environment
ls -R virtenv
false
fi
33 changes: 33 additions & 0 deletions .maint/ci/build_archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

echo "Building archive"

source .maint/ci/activate.sh

set -eu

# Required dependencies
echo "INSTALL_TYPE = $INSTALL_TYPE"

set -x

if [ "$INSTALL_TYPE" == "sdist" ]; then
python setup.py egg_info # check egg_info while we're here
python setup.py sdist
export ARCHIVE=$( ls dist/*.tar.gz )
elif [ "$INSTALL_TYPE" == "wheel" ]; then
python setup.py bdist_wheel
export ARCHIVE=$( ls dist/*.whl )
elif [ "$INSTALL_TYPE" == "archive" ]; then
export ARCHIVE="package.tar.gz"
git archive -o $ARCHIVE HEAD
elif [ "$INSTALL_TYPE" == "pip" ]; then
export ARCHIVE="."
fi

if [ "${ARCHIVE:0:5}" = "dist/" ]; then
python -m pip install twine
python -m twine check $ARCHIVE
fi

set +eux
26 changes: 26 additions & 0 deletions .maint/ci/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

echo Running tests

source .maint/ci/activate.sh

set -eu

# Required variables
echo CHECK_TYPE = $CHECK_TYPE

set -x

if [ "${CHECK_TYPE}" == "doc" ]; then
cd doc
make html && make doctest
elif [ "${CHECK_TYPE}" == "tests" ]; then
pytest --doctest-modules --cov fmriprep --cov-report xml \
--junitxml=test-results.xml -v fmriprep
else
false
fi

set +eux

echo Done running tests
24 changes: 24 additions & 0 deletions .maint/ci/create_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

echo Creating isolated virtual environment

source .maint/ci/env.sh

set -eu

# Required variables
echo SETUP_REQUIRES = $SETUP_REQUIRES

set -x

python -m pip install --upgrade pip virtualenv
virtualenv --python=python virtenv
source .maint/ci/activate.sh
python --version
python -m pip install -U $SETUP_REQUIRES
which python
which pip

set +eux

echo Done creating isolated virtual environment
6 changes: 6 additions & 0 deletions .maint/ci/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SETUP_REQUIRES="pip setuptools>=40.8 wheel"

# Numpy and scipy upload nightly/weekly/intermittent wheels
NIGHTLY_WHEELS="https://pypi.anaconda.org/scipy-wheels-nightly/simple"
STAGING_WHEELS="https://pypi.anaconda.org/multibuild-wheels-staging/simple"
PRE_PIP_FLAGS="--pre --extra-index-url $NIGHTLY_WHEELS --extra-index-url $STAGING_WHEELS"
38 changes: 38 additions & 0 deletions .maint/ci/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

echo Installing fmriprep

source .maint/ci/activate.sh
source .maint/ci/env.sh

set -eu

# Required variables
echo INSTALL_TYPE = $INSTALL_TYPE
echo CHECK_TYPE = $CHECK_TYPE
echo EXTRA_PIP_FLAGS = $EXTRA_PIP_FLAGS

set -x

if [ -n "$EXTRA_PIP_FLAGS" ]; then
EXTRA_PIP_FLAGS=${!EXTRA_PIP_FLAGS}
fi

if [ "$INSTALL_TYPE" == "setup" ]; then
python setup.py install
else
pip install $EXTRA_PIP_FLAGS $ARCHIVE
fi

# Basic import check
python -c 'import fmriprep; print(fmriprep.__version__)'

if [ "$CHECK_TYPE" == "skiptests" ]; then
exit 0
fi

pip install $EXTRA_PIP_FLAGS "fmriprep[$CHECK_TYPE]"

set +eux

echo Done installing fmriprep
21 changes: 21 additions & 0 deletions .maint/ci/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

echo "Installing dependencies"

set -eu

# Required variables
echo OS_TYPE = $OS_TYPE

if [ "$OS_TYPE" = "ubuntu-latest" ]; then
sudo apt update
sudo apt install -y graphviz
elif [ "$OS_TYPE" = "macos-latest" ]; then
brew install graphviz
else
echo "Unknown OS_TYPE: $OS_TYPE"
fi

set +eux

echo Done installing dependencies
24 changes: 24 additions & 0 deletions .maint/ci/install_extras.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

echo Installing dependencies

source .maint/ci/activate.sh
source .maint/ci/env.sh

set -eu

# Required variables
echo EXTRA_PIP_FLAGS = $EXTRA_PIP_FLAGS
echo CHECK_TYPE = $CHECK_TYPE

set -x

if [ -n "$EXTRA_PIP_FLAGS" ]; then
EXTRA_PIP_FLAGS=${!EXTRA_PIP_FLAGS}
fi

pip install $EXTRA_PIP_FLAGS "fmriprep[$CHECK_TYPE]"

set +eux

echo Done installing dependencies
18 changes: 17 additions & 1 deletion fmriprep/cli/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
#
"""Test parser."""
from packaging.version import Version
from pkg_resources import resource_filename as pkgrf
import pytest
from ..parser import _build_parser
from ..parser import _build_parser, parse_args
from .. import version as _version
from ... import config
from ...tests.test_config import _reset_config

MIN_ARGS = ["data/", "out/", "participant"]

Expand Down Expand Up @@ -136,3 +138,17 @@ def _mock_is_bl(*args, **kwargs):
assert ("FLAGGED" in captured) is flagged[0]
if flagged[0]:
assert (flagged[1] or "reason: unknown") in captured


def test_parse_args(tmp_path):
"""Basic smoke test showing that our parse_args() function
implements the BIDS App protocol"""
bids_dir = pkgrf('fmriprep', 'data/tests/ds000005')
out_dir = tmp_path / "out"
work_dir = tmp_path / "work"

parse_args(args=[bids_dir, str(out_dir), "participant", # BIDS App
"-w", str(work_dir), # Don't pollute CWD
"--skip-bids-validation"]) # Empty files make BIDS sad
assert config.execution.layout.root == bids_dir
_reset_config()
4 changes: 3 additions & 1 deletion fmriprep/utils/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import os
import re
from niworkflows.utils.misc import read_crashfile
import sentry_sdk
from nibabel.optpkg import optional_package

from .. import config

sentry_sdk = optional_package("sentry_sdk")[0]

CHUNK_SIZE = 16384
# Group common events with pre specified fingerprints
KNOWN_ERRORS = {
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ tests =
coverage
codecov
pytest
pytest-cov
pytest-env
all =
%(datalad)s
Expand Down