Skip to content

Commit 8bf68da

Browse files
authored
Merge pull request #223 from effigies/py39-types
PY39: Support pre-`__or__` types
2 parents 5aa2473 + 94ec119 commit 8bf68da

File tree

2 files changed

+58
-34
lines changed

2 files changed

+58
-34
lines changed

.github/workflows/travis.yml

+54-30
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,89 @@
11
name: Deps & CI
22

3-
on: [push]
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
pull_request:
7+
branches: [ master, 'maint/*' ]
8+
schedule:
9+
- cron: '0 0 * * 1'
10+
# Allow job to be triggered manually from GitHub interface
11+
workflow_dispatch:
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
permissions:
18+
contents: read
419

520
jobs:
6-
build-linux:
7-
if: "!contains(github.event.head_commit.message, '[skip ci]' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'nipy/nitransforms'))"
21+
cache-test-data:
22+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
823
runs-on: ubuntu-latest
924
env:
1025
TEST_DATA_HOME: /home/runner/testdata/nitransforms-tests
11-
strategy:
12-
max-parallel: 5
13-
matrix:
14-
python-version: ['3.8', '3.9', '3.10', '3.11']
15-
26+
outputs:
27+
SHA: ${{ steps.test-head.outputs.SHA }}
1628
steps:
1729
- name: Git settings (pacify DataLad)
1830
run: |
1931
git config --global user.name 'NiPreps Bot'
2032
git config --global user.email '[email protected]'
21-
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v4
23-
with:
24-
python-version: ${{ matrix.python-version }}
25-
- uses: actions/cache@v3
26-
id: conda
27-
with:
28-
path: |
29-
/usr/share/miniconda/pkgs
30-
/home/runner/.cache/pip
31-
key: python-${{ matrix.python-version }}-v1
32-
restore-keys: |
33-
python-${{ matrix.python-version }}-
3433
- name: Install DataLad
3534
run: |
36-
$CONDA/bin/conda install -c conda-forge git-annex datalad pip pytest
37-
$CONDA/bin/python -m pip install datalad-osf
35+
$CONDA/bin/conda install -c conda-forge git-annex
36+
python -m pip install datalad datalad-next datalad-osf
37+
- name: Check remote HEAD
38+
id: test-head
39+
run: |
40+
git ls-remote https://gin.g-node.org/oesteban/nitransforms-tests \
41+
| awk '/HEAD/{ print "SHA=" $1 }' >> $GITHUB_OUTPUT
3842
3943
- uses: actions/cache@v3
4044
with:
4145
path: ${{ env.TEST_DATA_HOME }}
42-
key: data-cache-v2
46+
key: data-cache-v2-${{ steps.test-head.outputs.SHA }}
4347
restore-keys: |
48+
data-cache-v2-${{ steps.test-head.outputs.SHA }}
4449
data-cache-v2
4550
4651
- name: Install test data
4752
run: |
4853
export PATH=$CONDA/bin:$PATH
4954
mkdir -p /home/runner/testdata
50-
cd /home/runner/testdata
5155
52-
$CONDA/bin/datalad install https://gin.g-node.org/oesteban/nitransforms-tests
53-
$CONDA/bin/datalad update --merge -d nitransforms-tests/
54-
$CONDA/bin/datalad get -d nitransforms-tests/
56+
datalad install -s https://gin.g-node.org/oesteban/nitransforms-tests $TEST_DATA_HOME
57+
datalad update --merge -d $TEST_DATA_HOME
58+
datalad get -J 2 -d $TEST_DATA_HOME
59+
60+
build-linux:
61+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
62+
runs-on: ubuntu-latest
63+
needs: [cache-test-data]
64+
env:
65+
TEST_DATA_HOME: /home/runner/testdata/nitransforms-tests
66+
strategy:
67+
max-parallel: 5
68+
matrix:
69+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
70+
steps:
71+
- name: Set up Python ${{ matrix.python-version }}
72+
uses: actions/setup-python@v4
73+
with:
74+
python-version: ${{ matrix.python-version }}
75+
- uses: actions/cache/restore@v3
76+
with:
77+
path: ${{ env.TEST_DATA_HOME }}
78+
key: data-cache-v2-${{ needs.cache-test-data.outputs.SHA }}
5579

5680
- uses: actions/checkout@v3
5781
- name: Install minimal dependencies
5882
run: |
59-
$CONDA/bin/pip install .[tests]
83+
pip install .[tests]
6084
- name: Run pytest
6185
run: |
62-
$CONDA/bin/pytest -v --cov nitransforms --cov-config .coveragerc --cov-report xml:cov.xml --doctest-modules nitransforms/
86+
pytest -v --cov nitransforms --cov-config .coveragerc --cov-report xml:cov.xml --doctest-modules nitransforms/
6387
6488
- name: Submit code coverage
6589
uses: codecov/codecov-action@v3

nitransforms/resampling.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from os import cpu_count
1313
from functools import partial
1414
from pathlib import Path
15-
from typing import Callable, TypeVar
15+
from typing import Callable, TypeVar, Union
1616

1717
import numpy as np
1818
from nibabel.loadsave import load as _nbload
@@ -144,8 +144,8 @@ async def _apply_serial(
144144

145145
def apply(
146146
transform: TransformBase,
147-
spatialimage: str | Path | SpatialImage,
148-
reference: str | Path | SpatialImage = None,
147+
spatialimage: Union[str, Path, SpatialImage],
148+
reference: Union[str, Path, SpatialImage] = None,
149149
order: int = 3,
150150
mode: str = "constant",
151151
cval: float = 0.0,
@@ -154,7 +154,7 @@ def apply(
154154
dtype_width: int = 8,
155155
serialize_nvols: int = SERIALIZE_VOLUME_WINDOW_WIDTH,
156156
max_concurrent: int = min(cpu_count(), 12),
157-
) -> SpatialImage | np.ndarray:
157+
) -> Union[SpatialImage, np.ndarray]:
158158
"""
159159
Apply a transformation to an image, resampling on the reference spatial object.
160160

0 commit comments

Comments
 (0)