Skip to content

Commit

Permalink
squash commits
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbore committed Jun 8, 2023
1 parent 8e5558f commit 477f00a
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dcm2bids/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from os.path import join as opj

from dcm2bids.utils.utils import DEFAULT
from dcm2bids.utils.tools import __version__
from dcm2bids.version import __version__


class Acquisition(object):
Expand Down
7 changes: 6 additions & 1 deletion dcm2bids/cli/dcm2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dcm2bids.dcm2bids_gen import Dcm2BidsGen
from dcm2bids.utils.tools import check_latest
from dcm2bids.utils.utils import DEFAULT

from dcm2bids.version import __version__

def _build_arg_parser():
p = argparse.ArgumentParser(description=__doc__, epilog=DEFAULT.doc,
Expand Down Expand Up @@ -53,6 +53,11 @@ def _build_arg_parser():
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
help="Set logging level. [%(default)s]")

p.add_argument("-v", "--version",
action="version",
version=f"dcm2bids version:\t{__version__}\nBased on BIDS version:\t{DEFAULT.bids_version}",
help="Report dcm2bids version and the BIDS version.")

return p


Expand Down
2 changes: 1 addition & 1 deletion dcm2bids/cli/dcm2bids_scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def main():
"https://github.com/bids-standard/bids-starter-kit")
# CHANGES
write_txt(opj(args.output_dir, "CHANGES"),
bids_starter_kit.CHANGES.replace('DATA',
bids_starter_kit.CHANGES.replace('DATE',
datetime.date.today().strftime("%Y-%m-%d")))

# dataset_description
Expand Down
4 changes: 2 additions & 2 deletions dcm2bids/dcm2bids_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from dcm2bids.participant import Participant
from dcm2bids.utils.utils import DEFAULT, run_shell_command
from dcm2bids.utils.io import load_json, save_json, valid_path
from dcm2bids.utils.tools import __version__, check_latest, dcm2niix_version

from dcm2bids.utils.tools import check_latest, dcm2niix_version
from dcm2bids.version import __version__

class Dcm2BidsGen(object):
""" Object to handle dcm2bids execution steps
Expand Down
2 changes: 1 addition & 1 deletion dcm2bids/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from os.path import join as opj

from dcm2bids.utils.utils import DEFAULT
from dcm2bids.utils.tools import __version__
from dcm2bids.version import __version__


class Participant(object):
Expand Down
2 changes: 1 addition & 1 deletion dcm2bids/utils/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ def check(path):

def add_overwrite_arg(parser):
parser.add_argument(
'-f', dest='overwrite', action='store_true',
'--force', dest='overwrite', action='store_true',
help='Force overwriting of the output files.')
5 changes: 2 additions & 3 deletions dcm2bids/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ def save_json(filename, data):


def write_txt(filename, lines):
with open(filename, "a") as f:
for row in lines:
f.write("%s\n" % row)
with open(filename, "a+") as f:
f.write(f"{lines}\n")


def get_scaffold_dir():
Expand Down
15 changes: 5 additions & 10 deletions dcm2bids/utils/scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

class bids_starter_kit(object):

CHANGES = """
Revision history for your dataset
CHANGES = """Revision history for your dataset
1.0.0 DATE
- Initialized study directory
"""

dataset_description = """
{
dataset_description = """{
"Name": "",
"BIDSVersion": "BIDS_VERSION",
"License": "",
Expand All @@ -29,8 +27,7 @@ class bids_starter_kit(object):
}
"""

participants_json = """
{
participants_json = """{
"age": {
"LongName": "",
"Description": "age of the participant",
Expand Down Expand Up @@ -63,15 +60,13 @@ class bids_starter_kit(object):
}
"""

participants_tsv = """
participant_id age sex group
participants_tsv = """participant_id age sex group
sub-01 34 M control
sub-02 12 F control
sub-03 33 F patient
"""

README = """
# README
README = """# README
The README is usually the starting point for researchers using your data
and serves as a guidepost for users of your data. A clear and informative
Expand Down
9 changes: 3 additions & 6 deletions dcm2bids/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

"""This module take care of the versioning"""

# dcm2bids version
__version__ = "2.1.9"


import logging
import shlex
from packaging import version
from distutils.version import LooseVersion
from subprocess import check_output, CalledProcessError, TimeoutExpired
from shutil import which

from dcm2bids.version import __version__

logger = logging.getLogger(__name__)

Expand All @@ -38,7 +35,7 @@ def check_github_latest(githubRepo, timeout=3):
Returns:
A string of the version
"""
url = "https://github.com/{}/releases/latest".format(githubRepo)
url = f"https://github.com/{githubRepo}/releases/latest"
try:
output = check_output(shlex.split("curl -L --silent " + url), timeout=timeout)
except CalledProcessError:
Expand All @@ -52,7 +49,7 @@ def check_github_latest(githubRepo, timeout=3):
# The output should have this format
# <html><body>You are being <a href="https://github.com/{gitRepo}/releases/tag/{version}">redirected</a>.</body></html>
try:
version = output.decode().split("{}/releases/tag/".format(githubRepo))[1].split('"')[0]
version = output.decode().split(f"{githubRepo}/releases/tag/")[1].split('"')[0]

# Versions are X.X.X
if len(version) > 5:
Expand Down
1 change: 0 additions & 1 deletion dcm2bids/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class DEFAULT(object):

# dcm2niix.py
dcm2niixOptions = "-b y -ba y -z y -f '%3s_%f_%p_%t'"
dcm2niixVersion = "v1.0.20181125"

# sidecar.py
compKeys = ["SeriesNumber", "AcquisitionTime", "SidecarFilename"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ def test_help_option(script_runner):
assert ret.success

def test_run_scaffold(script_runner):
ret = script_runner.run(['dcm2bids_scaffold', '-o', 'o_scaffold', '-f'])
ret = script_runner.run(['dcm2bids_scaffold', '-o', 'o_scaffold', '--force'])
assert ret.success

0 comments on commit 477f00a

Please sign in to comment.