From e857ce8489f5146f2c3ae40da2d85e0573db4b52 Mon Sep 17 00:00:00 2001 From: "arnaud.bore" Date: Thu, 8 Jun 2023 09:38:14 -0400 Subject: [PATCH] squash commits --- dcm2bids/acquisition.py | 2 +- dcm2bids/cli/dcm2bids.py | 7 ++++++- dcm2bids/cli/dcm2bids_scaffold.py | 12 ++++++++---- dcm2bids/dcm2bids_gen.py | 4 ++-- dcm2bids/participant.py | 2 +- dcm2bids/utils/args.py | 2 +- dcm2bids/utils/io.py | 5 ++--- dcm2bids/utils/scaffold.py | 15 +++++---------- dcm2bids/utils/tools.py | 9 +++------ dcm2bids/utils/utils.py | 1 - tests/test_scaffold.py | 2 +- 11 files changed, 30 insertions(+), 31 deletions(-) diff --git a/dcm2bids/acquisition.py b/dcm2bids/acquisition.py index 30d462cb..cda538cc 100644 --- a/dcm2bids/acquisition.py +++ b/dcm2bids/acquisition.py @@ -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): diff --git a/dcm2bids/cli/dcm2bids.py b/dcm2bids/cli/dcm2bids.py index c333916d..3b3a007f 100644 --- a/dcm2bids/cli/dcm2bids.py +++ b/dcm2bids/cli/dcm2bids.py @@ -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, @@ -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 diff --git a/dcm2bids/cli/dcm2bids_scaffold.py b/dcm2bids/cli/dcm2bids_scaffold.py index ca5b4f80..58824e4e 100644 --- a/dcm2bids/cli/dcm2bids_scaffold.py +++ b/dcm2bids/cli/dcm2bids_scaffold.py @@ -17,7 +17,7 @@ from dcm2bids.utils.io import write_txt from dcm2bids.utils.args import add_overwrite_arg, assert_dirs_empty -from dcm2bids.utils.utils import DEFAULT +from dcm2bids.utils.utils import DEFAULT, run_shell_command from dcm2bids.utils.scaffold import bids_starter_kit @@ -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 @@ -64,8 +64,12 @@ def main(): bids_starter_kit.participants_tsv) # README - write_txt(opj(args.output_dir, "README"), - bids_starter_kit.README) + try: + run_shell_command(['wget', '-q', '-O', opj(args.output_dir, "README"), + 'https://github.com/bids-standard/bids-starter-kit/blob/main/templates/README.MD']) + except: + write_txt(opj(args.output_dir, "README"), + bids_starter_kit.README) if __name__ == "__main__": diff --git a/dcm2bids/dcm2bids_gen.py b/dcm2bids/dcm2bids_gen.py index afd384f6..d49db765 100644 --- a/dcm2bids/dcm2bids_gen.py +++ b/dcm2bids/dcm2bids_gen.py @@ -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 diff --git a/dcm2bids/participant.py b/dcm2bids/participant.py index 6e776a3c..bf6a5827 100644 --- a/dcm2bids/participant.py +++ b/dcm2bids/participant.py @@ -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): diff --git a/dcm2bids/utils/args.py b/dcm2bids/utils/args.py index cb5f300b..153648a5 100644 --- a/dcm2bids/utils/args.py +++ b/dcm2bids/utils/args.py @@ -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.') diff --git a/dcm2bids/utils/io.py b/dcm2bids/utils/io.py index 48e42eb6..f28ed339 100644 --- a/dcm2bids/utils/io.py +++ b/dcm2bids/utils/io.py @@ -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(): diff --git a/dcm2bids/utils/scaffold.py b/dcm2bids/utils/scaffold.py index 5357830f..70cc2e19 100644 --- a/dcm2bids/utils/scaffold.py +++ b/dcm2bids/utils/scaffold.py @@ -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": "", @@ -29,8 +27,7 @@ class bids_starter_kit(object): } """ - participants_json = """ -{ + participants_json = """{ "age": { "LongName": "", "Description": "age of the participant", @@ -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 diff --git a/dcm2bids/utils/tools.py b/dcm2bids/utils/tools.py index 0a80d020..13fbad2a 100644 --- a/dcm2bids/utils/tools.py +++ b/dcm2bids/utils/tools.py @@ -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__) @@ -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: @@ -52,7 +49,7 @@ def check_github_latest(githubRepo, timeout=3): # The output should have this format # You are being redirected. 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: diff --git a/dcm2bids/utils/utils.py b/dcm2bids/utils/utils.py index 59b3a6ea..f2548c98 100644 --- a/dcm2bids/utils/utils.py +++ b/dcm2bids/utils/utils.py @@ -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"] diff --git a/tests/test_scaffold.py b/tests/test_scaffold.py index 056be1e4..f45d98df 100644 --- a/tests/test_scaffold.py +++ b/tests/test_scaffold.py @@ -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