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

Fix testing suite #4

Merged
merged 22 commits into from
Jan 10, 2023
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bids/reports/_version.py export-subst
bids/ext/reports/_version.py export-subst
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# Documentation
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly

- package-ecosystem: gitsubmodule
directory: /
schedule:
interval: monthly
58 changes: 0 additions & 58 deletions .github/workflows/package.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [published]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.7'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
61 changes: 61 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "Run Tests"

on:
push:
branches:
- "main"
pull_request:
branches:
- '*'

concurrency:
group: environment-${{ github.ref }}
cancel-in-progress: true

jobs:
# Determine if tests should be run based on commit message.
check_skip:
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.result_step.outputs.ci-skip }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: result_step
uses: mstachniuk/ci-skip@master
with:
commit-filter: '[skip ci];[ci skip];[skip github]'
commit-filter-separator: ';'

run_tests:
needs: check_skip
if: ${{ needs.check_skip.outputs.skip == 'false' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
name: ${{ matrix.os }} with Python ${{ matrix.python-version }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- name: 'Set up python'
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: 'Display Python version'
shell: bash {0}
run: python -c "import sys; print(sys.version)"
- name: 'Install pybids-reports'
shell: bash {0}
run: pip install -e .[tests]
- name: 'Run tests'
shell: bash {0}
run: python -m pytest --pyargs bids/ext/reports --cov=bids/ext/reports
- name: 'Upload coverage to CodeCov'
uses: codecov/codecov-action@v1
if: success()
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer


- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.991
# hooks:
# - id: mypy
6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include versioneer.py
include bids/reports/_version.py
recursive-include bids/reports/config *.json
recursive-include bids/reports/tests/data *
include bids/ext/reports/_version.py
recursive-include bids/ext/reports/config *.json
recursive-include bids/ext/reports/tests/data *
1 change: 1 addition & 0 deletions bids/ext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
File renamed without changes.
4 changes: 2 additions & 2 deletions bids/reports/__init__.py → bids/ext/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""pybids-reports: A tool for building methods sections for BIDS datasets."""
from . import _version
from . import _version, parameters, parsing, report
from .due import Doi, due
from .report import BIDSReport

__all__ = ["BIDSReport"]
__all__ = ["BIDSReport", "parameters", "parsing", "report"]

due.cite(
Doi("10.1038/sdata.2016.44"),
Expand Down
File renamed without changes.
4 changes: 1 addition & 3 deletions bids/reports/due.py → bids/ext/reports/due.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def _donothing_func(*args, **kwargs):
if type(e).__name__ not in ("ImportError", "ModuleNotFoundError"):
import logging

logging.getLogger("duecredit").error(
"Failed to import duecredit due to %s" % str(e)
)
logging.getLogger("duecredit").error("Failed to import duecredit due to %s" % str(e))
# Initiate due stub
due = InactiveDueCreditCollector()
BibTeX = Doi = Url = Text = _donothing_func
Expand Down
37 changes: 12 additions & 25 deletions bids/reports/parameters.py → bids/ext/reports/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@
import nibabel as nib
from num2words import num2words

from bids.reports.utils import list_to_str, num_to_str, remove_duplicates
from .utils import list_to_str, num_to_str, remove_duplicates

logging.basicConfig()
LOGGER = logging.getLogger("reports.parsing")
LOGGER = logging.getLogger("pybids-reports.parameters")


def describe_slice_timing(img, metadata: dict) -> str:
"""Generate description of slice timing from metadata."""

if "SliceTiming" in metadata:
slice_order = " in {0} order".format(get_slice_info(metadata["SliceTiming"]))
n_slices = len(metadata["SliceTiming"])
else:
slice_order = ""
n_slices = img.shape[2]

return "{n_slices} slices{slice_order}".format(
n_slices=n_slices, slice_order=slice_order
)
return "{n_slices} slices{slice_order}".format(n_slices=n_slices, slice_order=slice_order)


def describe_repetition_time(metadata: dict):
Expand Down Expand Up @@ -63,9 +60,9 @@ def describe_duration(files) -> str:
n_vols = n_vols[0]
dur_str = describe_func_duration(n_vols, tr)

dur_str = (
"Run duration was {0} minutes, during which {1} volumes were acquired."
).format(dur_str, n_vols)
dur_str = ("Run duration was {0} minutes, during which {1} volumes were acquired.").format(
dur_str, n_vols
)
return dur_str


Expand Down Expand Up @@ -93,7 +90,6 @@ def describe_echo_times(files):
me_str : str
Whether the data are multi-echo or single-echo.
"""

echo_times = [f.get_metadata()["EchoTime"] for f in files]
echo_times = sorted(list(set(echo_times)))
if len(echo_times) > 1:
Expand All @@ -108,7 +104,7 @@ def describe_echo_times(files):


def describe_echo_times_fmap(files):
"""Generate description of echo times from metadata field for fmaps
"""Generate description of echo times from metadata field for fmaps.

Parameters
----------
Expand Down Expand Up @@ -160,9 +156,7 @@ def describe_image_size(img):
def describe_inplane_accel(metadata: dict) -> str:
"""Generate description of in-plane acceleration factor, if any."""
return (
"in-plane acceleration factor={}".format(
metadata["ParallelReductionFactorInPlane"]
)
"in-plane acceleration factor={}".format(metadata["ParallelReductionFactorInPlane"])
if metadata.get("ParallelReductionFactorInPlane", 1) > 1
else ""
)
Expand All @@ -184,9 +178,7 @@ def describe_bvals(bval_file) -> str:
with open(bval_file, "r") as file_object:
raw_bvals = file_object.read().splitlines()
# Flatten list of space-separated values
bvals = [
item for sublist in [line.split(" ") for line in raw_bvals] for item in sublist
]
bvals = [item for sublist in [line.split(" ") for line in raw_bvals] for item in sublist]
bvals = sorted([int(v) for v in set(bvals)])
bvals = [num_to_str(v) for v in bvals]
bval_str = list_to_str(bvals)
Expand All @@ -210,9 +202,7 @@ def describe_intendedfor_targets(metadata: dict, layout) -> str:

for scan in scans:
fn = op.basename(scan)
if_file = [
f for f in layout.get(extension=[".nii", ".nii.gz"]) if fn in f.path
][0]
if_file = [f for f in layout.get(extension=[".nii", ".nii.gz"]) if fn in f.path][0]
run_num = int(if_file.run)
target_type = if_file.entities["suffix"].upper()

Expand All @@ -229,9 +219,7 @@ def describe_intendedfor_targets(metadata: dict, layout) -> str:
run_dict[target_type_str].append(run_num)

for scan in run_dict.keys():
run_dict[scan] = [
num2words(r, ordinal=True) for r in sorted(run_dict[scan])
]
run_dict[scan] = [num2words(r, ordinal=True) for r in sorted(run_dict[scan])]

out_list = []

Expand Down Expand Up @@ -320,8 +308,7 @@ def describe_sequence(metadata: dict, config: dict):
seqs += " ({0})".format(os.path.sep.join(seq_abbrs))

variants = [
config["seqvar"].get(var, var)
for var in metadata.get("SequenceVariant", "").split("_")
config["seqvar"].get(var, var) for var in metadata.get("SequenceVariant", "").split("_")
]
variants = list_to_str(variants)

Expand Down
Loading