Skip to content

Commit

Permalink
Merge b93c9bb into 9973d7e
Browse files Browse the repository at this point in the history
  • Loading branch information
fepegar committed Oct 24, 2021
2 parents 9973d7e + b93c9bb commit d62bf25
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 19 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint

on: [push]

jobs:
Build:
runs-on: ubuntu-latest

steps:
- name: Clone the repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install dependencies
run: pip install tox pre-commit flake8

- name: Run lint
run: tox -e lint
66 changes: 66 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Tests

on:
push:
schedule:
- cron: "0 4 * * *"

jobs:
unit:
strategy:
matrix:
# TODO: add windows-latest
os: [ubuntu-latest, macos-latest]
python: ['3.6', '3.7', '3.8', '3.9']

runs-on: ${{ matrix.os }}
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python }}

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

- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install dev requirements
run: pip install -r requirements-dev.txt

- name: Run unit tests
run: tox -e py

- name: Upload coverage
uses: codecov/codecov-action@v1.0.7
with:
env_vars: OS,PYTHON

cli:
runs-on: ubuntu-latest

steps:
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: "3.9"

- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install project
run: pip install .

- name: Test CLI
run: |
tiotr --help
tiohd --help
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ repos:
pep8-naming, # check PEP-8 naming conventions
]
args: [
'--ignore=N813,E123,W503', # import SimpleITK as sitk, brackets indentation, line break before binary operator
'--ignore=N813,E123,W503,B902', # import SimpleITK as sitk, brackets indentation, line break before binary operator
]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.6.0 # Use the ref you want to point at
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ at [OpenAI](https://openai.com/) ([link](https://jack-clark.net/2020/03/17/)).
<a href="https://codecov.io/github/fepegar/torchio">
<img src="https://codecov.io/gh/fepegar/torchio/branch/master/graphs/badge.svg" alt="Coverage status">
</a>
<a href="https://github.com/fepegar/torchio/actions/workflows/lint.yml">
<img src="https://github.com/fepegar/torchio/actions/workflows/lint.yml/badge.svg" alt="Linting status">
</a>
</td>
</tr>
<tr>
Expand Down
6 changes: 5 additions & 1 deletion docs/source/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TorchIO
#######

|PyPI-downloads| |PyPI-version| |Conda-version| |Google-Colab-notebook| |Docs-status|
|Build-status| |Coverage-codecov| |Code-Quality|
|Lint-status| |Build-status| |Coverage-codecov| |Code-Quality|
|Code-Maintainability| |pre-commit| |Slack|


Expand Down Expand Up @@ -124,6 +124,10 @@ which is no longer maintained.
:target: https://travis-ci.com/fepegar/torchio
:alt: Build status

.. |Lint-status| image:: https://github.com/fepegar/torchio/actions/workflows/lint.yml/badge.svg
:target: https://github.com/fepegar/torchio/actions/workflows/lint.yml
:alt: Build status

.. |Coverage-codecov| image:: https://codecov.io/gh/fepegar/torchio/branch/master/graphs/badge.svg
:target: https://codecov.io/github/fepegar/torchio
:alt: Coverage status
Expand Down
2 changes: 1 addition & 1 deletion tests/data/test_subjects_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class TestSubjectsDataset(TorchioTestCase):

def test_indexing_nonint(self):
dset = SubjectsDataset(self.subjects_list)
dset[torch.tensor(0)]
Expand Down
10 changes: 0 additions & 10 deletions tests/transforms/test_transforms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import copy
import torch
import numpy as np
import nibabel as nib
import torchio as tio
import SimpleITK as sitk
from ..utils import TorchioTestCase
Expand Down Expand Up @@ -100,15 +99,6 @@ def test_transforms_sitk(self):
transformed = transform(image)
self.assertIsInstance(transformed, sitk.Image)

def test_transforms_nib(self):
data = torch.rand(1, 4, 5, 8).numpy()
affine = np.diag((1, -2, 3, 1))
image = nib.Nifti1Image(data, affine)
transform = self.get_transform(
channels=('default_image_name',), labels=False)
transformed = transform(image)
self.assertIsInstance(transformed, nib.Nifti1Image)

def test_transforms_subject_3d(self):
transform = self.get_transform(channels=('t1', 't2'), is_3d=True)
transformed = transform(self.sample_subject)
Expand Down
8 changes: 6 additions & 2 deletions torchio/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ def __getitem__(self, index: int) -> Subject:
try:
index = int(index)
except (RuntimeError, TypeError):
raise ValueError(f'Index "{index}" must be int or compatible dtype, not {type(index)}')

message = (
f'Index "{index}" must be int or compatible dtype,'
f' but an object of type "{type(index)}" was passed'
)
raise ValueError(message)

subject = self._subjects[index]
subject = copy.deepcopy(subject) # cheap since images not loaded yet
if self.load_getitem:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def add_artifact(
def _parse_restore(restore):
try:
restore = float(restore)
except Exception as e:
except ValueError as e:
raise TypeError(f'Restore must be a float, not "{restore}"') from e
if not 0 <= restore <= 1:
message = (
Expand Down
2 changes: 1 addition & 1 deletion torchio/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def plot_subject(
fig.savefig(output_path)
if show:
plt.show()
plt.close(fig)
plt.close(fig)


def color_labels(arrays, cmap_dict):
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ passenv =
CI
TRAVIS
TRAVIS_*
GITHUB_*
setenv =
PYTHONPATH = {toxinidir}

Expand All @@ -31,11 +32,9 @@ requires =
pre-commit
deps =
flake8 >= 3.8
mypy
commands =
pre-commit run --all-files
flake8
mypy


[flake8]
Expand Down

0 comments on commit d62bf25

Please sign in to comment.