Skip to content

Commit 915fb6f

Browse files
authored
Merge pull request #404 from nipreps/maint/tox
MAINT: Automate testing with tox
2 parents 9e4438a + 2c039c9 commit 915fb6f

File tree

3 files changed

+186
-24
lines changed

3 files changed

+186
-24
lines changed

.github/workflows/pytest.yml

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ name: Pytest
22

33
on:
44
push:
5-
branches: [ '*' ]
6-
tags: [ '*' ]
5+
branches: ['*']
6+
tags: ['*']
77
pull_request:
8-
branches: [ master, 'maint/*' ]
8+
branches: [master, 'maint/*']
99

1010
defaults:
1111
run:
1212
shell: bash
1313

14+
env:
15+
FORCE_COLOR: true
16+
1417
concurrency:
1518
group: ${{ github.workflow }}-${{ github.ref }}
1619
cancel-in-progress: true
@@ -19,32 +22,50 @@ permissions:
1922
contents: read
2023

2124
jobs:
22-
build:
23-
if: "!contains(github.event.head_commit.message, '[skip ci]')"
24-
runs-on: ubuntu-latest
25+
test:
26+
runs-on: ${{ matrix.os }}
2527
strategy:
2628
matrix:
27-
python-version: ['3.10', '3.11']
29+
os: ['ubuntu-latest']
30+
python-version: ['3.10', '3.11', '3.12']
31+
dependencies: ['latest', 'pre']
32+
include:
33+
- os: ubuntu-latest
34+
python-version: '3.10'
35+
dependencies: 'min'
36+
37+
env:
38+
DEPENDS: ${{ matrix.dependencies }}
2839

2940
steps:
30-
- name: Set up Python ${{ matrix.python-version }}
31-
uses: actions/setup-python@v5
32-
with:
33-
python-version: ${{ matrix.python-version }}
3441
- uses: actions/checkout@v4
3542
with:
43+
submodules: recursive
3644
fetch-depth: 0
37-
- name: Install nibabies
45+
- uses: actions/cache@v4
46+
with:
47+
path: ~/.cache/templateflow
48+
key: templateflow-v1
49+
- name: Install dependencies
3850
run: |
39-
python -m venv /tmp/venv
40-
source /tmp/venv/bin/activate
41-
python -m pip install -U pip
42-
python -m pip install ".[test]"
43-
- name: Run Pytest
51+
sudo apt update
52+
sudo apt install -y --no-install-recommends graphviz
53+
- name: Set up Python ${{ matrix.python-version }}
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: ${{ matrix.python-version }}
57+
- name: Display Python version
58+
run: python -c "import sys; print(sys.version)"
59+
- name: Install tox
4460
run: |
45-
source /tmp/venv/bin/activate
46-
pytest -sv --doctest-modules --cov nibabies --cov-report xml nibabies
47-
- name: Submit coverage
48-
uses: codecov/codecov-action@v3
61+
python -m pip install --upgrade pip
62+
python -m pip install tox tox-gh-actions
63+
- name: Show tox config
64+
run: tox c
65+
- name: Run tox
66+
run: tox -v --exit-and-dump-after 1200
67+
- uses: codecov/codecov-action@v4
4968
with:
50-
files: coverage.xml
69+
file: coverage.xml
70+
token: ${{ secrets.CODECOV_TOKEN }}
71+
if: ${{ always() }}

pyproject.toml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies = [
3737
"tedana >= 23.0.2",
3838
"templateflow >= 24.2.0",
3939
"toml",
40+
"typing_extensions; python_version<'3.11'",
4041
]
4142
dynamic = ["version"]
4243

@@ -71,10 +72,11 @@ maint = [
7172
"python-Levenshtein",
7273
]
7374
test = [
74-
"coverage",
75+
"coverage[toml]",
7576
"pytest",
7677
"pytest-cov",
7778
"pytest-env",
79+
"pytest-xdist",
7880
]
7981
telemetry = ["migas >= 0.4.0"]
8082
# Aliases
@@ -120,8 +122,22 @@ per-file-ignores = [
120122
]
121123

122124
[tool.pytest.ini_options]
125+
minversion = "6"
126+
testpaths = ["nibabies"]
127+
log_cli_level = "INFO"
128+
xfail_strict = true
123129
norecursedirs = [".git"]
124-
addopts = "-svx --doctest-modules"
130+
addopts = [
131+
"-svx",
132+
"-ra",
133+
"--strict-config",
134+
"--strict-markers",
135+
"--doctest-modules",
136+
# Config pytest-cov
137+
"--cov=nibabies",
138+
"--cov-report=xml",
139+
"--cov-config=pyproject.toml",
140+
]
125141
doctest_optionflags = "ALLOW_UNICODE NORMALIZE_WHITESPACE ELLIPSIS"
126142
env = "PYTHONHASHSEED=0"
127143
filterwarnings = ["ignore::DeprecationWarning"]
@@ -177,3 +193,15 @@ inline-quotes = "single"
177193

178194
[tool.ruff.format]
179195
quote-style = "single"
196+
197+
[tool.coverage.run]
198+
branch = true
199+
omit = [
200+
"*/_version.py"
201+
]
202+
203+
[tool.coverage.paths]
204+
source = [
205+
"nibabies",
206+
"**/site-packages/nibabies"
207+
]

tox.ini

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
[tox]
2+
requires =
3+
tox>=4
4+
envlist =
5+
py3{10,11,12}-latest
6+
py310-min
7+
py3{10,11,12}-pre
8+
skip_missing_interpreters = true
9+
10+
# Configuration that allows us to split tests across GitHub runners effectively
11+
[gh-actions]
12+
python =
13+
3.10: py310
14+
3.11: py311
15+
3.12: py312
16+
17+
[gh-actions:env]
18+
DEPENDS =
19+
min: min
20+
latest: latest
21+
pre: pre
22+
23+
[testenv]
24+
description = Pytest with coverage
25+
labels = test
26+
pip_pre =
27+
pre: true
28+
pass_env =
29+
# getpass.getuser() sources for Windows:
30+
LOGNAME
31+
USER
32+
LNAME
33+
USERNAME
34+
# Pass user color preferences through
35+
PY_COLORS
36+
FORCE_COLOR
37+
NO_COLOR
38+
CLICOLOR
39+
CLICOLOR_FORCE
40+
PYTHON_GIL
41+
extras = test
42+
setenv =
43+
pre: PIP_EXTRA_INDEX_URL=https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
44+
deps =
45+
min: nibabel == 4.0.1
46+
min: nipype == 1.8.5
47+
min: nitransforms == 21.0.0
48+
min: numpy == 1.22
49+
min: psutil == 5.4
50+
min: pybids == 0.15.2
51+
min: tedana == 23.0.2
52+
min: templateflow == 24.1.0
53+
54+
commands_pre =
55+
python scripts/fetch_templates.py
56+
commands =
57+
pytest --cov-report term-missing --durations=20 --durations-min=1.0 {posargs:-n auto}
58+
59+
[testenv:style]
60+
description = Check our style guide
61+
labels = check
62+
deps =
63+
ruff
64+
skip_install = true
65+
commands =
66+
ruff check --diff
67+
ruff format --diff
68+
69+
[testenv:style-fix]
70+
description = Auto-apply style guide to the extent possible
71+
labels = pre-release
72+
deps =
73+
ruff
74+
skip_install = true
75+
commands =
76+
ruff check --fix
77+
ruff format
78+
ruff check --select ISC001
79+
80+
[testenv:spellcheck]
81+
description = Check spelling
82+
labels = check
83+
deps =
84+
codespell[toml]
85+
skip_install = true
86+
commands =
87+
codespell . {posargs}
88+
89+
[testenv:build{,-strict}]
90+
labels =
91+
check
92+
pre-release
93+
deps =
94+
build
95+
twine
96+
skip_install = true
97+
set_env =
98+
# Ignore specific known warnings:
99+
# https://github.com/pypa/pip/issues/11684
100+
# https://github.com/pypa/pip/issues/12243
101+
strict: PYTHONWARNINGS=error,once:pkg_resources is deprecated as an API.:DeprecationWarning:pip._internal.metadata.importlib._envs,once:Unimplemented abstract methods {'locate_file'}:DeprecationWarning:pip._internal.metadata.importlib._dists
102+
commands =
103+
python -m build
104+
python -m twine check dist/*
105+
106+
[testenv:publish]
107+
depends = build
108+
labels = release
109+
deps =
110+
twine
111+
skip_install = true
112+
commands =
113+
python -m twine upload dist/*

0 commit comments

Comments
 (0)