Skip to content

Commit

Permalink
[RF] Use Black to reformat package (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcieslak authored Feb 22, 2024
1 parent 5b1610a commit 866a878
Show file tree
Hide file tree
Showing 100 changed files with 11,608 additions and 9,336 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Lint code
on:
push:
branches:
- main_
- master
pull_request:
branches:
- main_
- master

defaults:
run:
Expand All @@ -30,8 +30,7 @@ jobs:
run: python -c "import sys; print(sys.version)"
- name: Install flake8 and related packages
run: python -m pip install \
flake8 flake8-absolute-import flake8-black flake8-docstrings \
flake8-isort flake8-pyproject flake8-unused-arguments \
flake8-use-fstring pep8-naming
flake8 flake8-black \
flake8-isort flake8-pyproject
- name: Check qsiprep
run: python -m flake8 qsiprep
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ exclude = '''
| _build
| build
| dist
| qsiprep/niworkflows
)/
| qsiprep/_version.py
)
Expand All @@ -152,9 +153,10 @@ exclude = [
"qsiprep/config.py",
"qsiprep/data/",
"qsiprep/tests/",
"qsiprep/niworkflows/",
"qsiprep/utils/sentry.py",
]
ignore = ["D107", "E203", "E402", "E722", "W503", "N803", "N806", "N815"]
ignore = ["D107", "E203", "E402", "E722", "W503", "N803", "N806", "N815", "W605"]
per-file-ignores = [
"**/__init__.py : F401",
"docs/conf.py : E265",
Expand Down
18 changes: 10 additions & 8 deletions qsiprep/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
except ImportError:
__version__ = "0+unknown"

__packagename__ = 'qsiprep'
__copyright__ = 'Copyright 2019, Brain Behavior Laboratory, University of Pennsylvania'
__credits__ = ('Contributors: please check the ``.zenodo.json`` file at the top-level folder'
'of the repository')
__url__ = 'https://github.com/pennlinc/qsiprep'
__packagename__ = "qsiprep"
__copyright__ = "Copyright 2019, Brain Behavior Laboratory, University of Pennsylvania"
__credits__ = (
"Contributors: please check the ``.zenodo.json`` file at the top-level folder"
"of the repository"
)
__url__ = "https://github.com/pennlinc/qsiprep"

DOWNLOAD_URL = (
'https://github.com/pennbbl/{name}/archive/{ver}.tar.gz'.format(
name=__packagename__, ver=__version__))
DOWNLOAD_URL = "https://github.com/pennbbl/{name}/archive/{ver}.tar.gz".format(
name=__packagename__, ver=__version__
)
12 changes: 6 additions & 6 deletions qsiprep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from .__about__ import __copyright__, __credits__, __packagename__, __version__ # noqa

# cmp is not used by qsiprep, so ignore nipype-generated warnings
warnings.simplefilter('ignore')
warnings.filterwarnings('ignore', r'cmp not installed')
warnings.filterwarnings('ignore', r'Enable tracemalloc')
warnings.filterwarnings('ignore', r"can't resolve package from __spec__ or __package__")
warnings.filterwarnings('ignore', category=ResourceWarning)
warnings.filterwarnings('ignore', r'Using or importing the ABCs from')
warnings.simplefilter("ignore")
warnings.filterwarnings("ignore", r"cmp not installed")
warnings.filterwarnings("ignore", r"Enable tracemalloc")
warnings.filterwarnings("ignore", r"can't resolve package from __spec__ or __package__")
warnings.filterwarnings("ignore", category=ResourceWarning)
warnings.filterwarnings("ignore", r"Using or importing the ABCs from")
156 changes: 90 additions & 66 deletions qsiprep/cli/convertODFs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,92 +13,116 @@ def sink_mask_file(in_file, orig_file, out_dir):
import os

from nipype.utils.filemanip import copyfile, fname_presuffix

os.makedirs(out_dir, exist_ok=True)
out_file = fname_presuffix(orig_file, suffix='_mask', newpath=out_dir)
out_file = fname_presuffix(orig_file, suffix="_mask", newpath=out_dir)
copyfile(in_file, out_file, copy=True, use_hardlink=True)
return out_file


def fib_to_mif():
"""Convert fib to mif."""
parser = ArgumentParser(
description='qsiprep: Convert DSI Studio fib file to MRtrix mif file.',
formatter_class=RawTextHelpFormatter)
description="qsiprep: Convert DSI Studio fib file to MRtrix mif file.",
formatter_class=RawTextHelpFormatter,
)

parser.add_argument('--fib',
required=True,
action='store',
type=os.path.abspath,
default='',
help='DSI Studio fib file to convert')
parser.add_argument('--mif',
type=os.path.abspath,
required=False,
action='store',
default='',
help='output path for a MRtrix mif file')
parser.add_argument('--ref_image',
required=True,
action='store',
type=os.path.abspath,
help='a NIfTI-1 format file with a valid q/sform.')
parser.add_argument('--subtract-iso',
required=False,
action='store_true',
help='subtract ODF min so visualization looks similar in mrview')
parser.add_argument(
"--fib",
required=True,
action="store",
type=os.path.abspath,
default="",
help="DSI Studio fib file to convert",
)
parser.add_argument(
"--mif",
type=os.path.abspath,
required=False,
action="store",
default="",
help="output path for a MRtrix mif file",
)
parser.add_argument(
"--ref_image",
required=True,
action="store",
type=os.path.abspath,
help="a NIfTI-1 format file with a valid q/sform.",
)
parser.add_argument(
"--subtract-iso",
required=False,
action="store_true",
help="subtract ODF min so visualization looks similar in mrview",
)
opts = parser.parse_args()
converter = FIBGZtoFOD(mif_file=opts.mif,
fib_file=opts.fib,
ref_image=opts.ref_image,
subtract_iso=opts.subtract_iso)
converter = FIBGZtoFOD(
mif_file=opts.mif,
fib_file=opts.fib,
ref_image=opts.ref_image,
subtract_iso=opts.subtract_iso,
)
converter.run()


def mif_to_fib():
"""Convert mif to fib."""
parser = ArgumentParser(
description='qsiprep: Convert MRtrix mif file to DSI Studio fib file',
formatter_class=RawTextHelpFormatter)
description="qsiprep: Convert MRtrix mif file to DSI Studio fib file",
formatter_class=RawTextHelpFormatter,
)

parser.add_argument('--mif',
type=os.path.abspath,
required=True,
action='store',
default='',
help='MRtrix mif file to convert')
parser.add_argument('--fib',
required=True,
action='store',
type=os.path.abspath,
default='',
help='the output path for the DSI Studio fib file')
parser.add_argument('--mask',
required=False,
action='store',
type=os.path.abspath,
help='a NIfTI-1 format mask file.')
parser.add_argument('--num_fibers',
required=False,
action='store',
type=int,
default=5,
help='maximum number of fixels per voxel.')
parser.add_argument('--unit-odf',
required=False,
action='store_true',
help='force ODFs to sum to 1.')
parser.add_argument(
"--mif",
type=os.path.abspath,
required=True,
action="store",
default="",
help="MRtrix mif file to convert",
)
parser.add_argument(
"--fib",
required=True,
action="store",
type=os.path.abspath,
default="",
help="the output path for the DSI Studio fib file",
)
parser.add_argument(
"--mask",
required=False,
action="store",
type=os.path.abspath,
help="a NIfTI-1 format mask file.",
)
parser.add_argument(
"--num_fibers",
required=False,
action="store",
type=int,
default=5,
help="maximum number of fixels per voxel.",
)
parser.add_argument(
"--unit-odf", required=False, action="store_true", help="force ODFs to sum to 1."
)
opts = parser.parse_args()
if opts.mask is not None:
converter = FODtoFIBGZ(mif_file=opts.mif,
fib_file=opts.fib,
num_fibers=opts.num_fibers,
unit_odf=opts.unit_odf,
mask_file=opts.mask)
converter = FODtoFIBGZ(
mif_file=opts.mif,
fib_file=opts.fib,
num_fibers=opts.num_fibers,
unit_odf=opts.unit_odf,
mask_file=opts.mask,
)
else:
converter = FODtoFIBGZ(mif_file=opts.mif,
fib_file=opts.fib,
num_fibers=opts.num_fibers,
unit_odf=opts.unit_odf)
converter = FODtoFIBGZ(
mif_file=opts.mif,
fib_file=opts.fib,
num_fibers=opts.num_fibers,
unit_odf=opts.unit_odf,
)
converter.run()


Expand Down
20 changes: 11 additions & 9 deletions qsiprep/cli/group_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
def aggregate_reports():
"""Convert fib to mif."""
parser = ArgumentParser(
description='qsiprep: Aggregate single subject reports into a group report.',
formatter_class=RawTextHelpFormatter)
description="qsiprep: Aggregate single subject reports into a group report.",
formatter_class=RawTextHelpFormatter,
)

parser.add_argument('qsiprep_derivatives_dir',
type=Path,
action='store',
help='the root folder containing QSIPrep outputs (sub-XXXXX folders '
'should be found at the top level in this folder).')
parser.add_argument(
"qsiprep_derivatives_dir",
type=Path,
action="store",
help="the root folder containing QSIPrep outputs (sub-XXXXX folders "
"should be found at the top level in this folder).",
)
opts = parser.parse_args()
sys.exit(
generate_interactive_report_summary(opts.qsiprep_derivatives_dir))
sys.exit(generate_interactive_report_summary(opts.qsiprep_derivatives_dir))
Loading

0 comments on commit 866a878

Please sign in to comment.