From adc1ba6c8ea1be3969457f14fd13c05cad610de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szczepanik?= Date: Mon, 12 Aug 2024 17:06:47 +0200 Subject: [PATCH 1/2] Unify -o long option to be --store-dir This changes make_studyvisit_archive to use -o / --store-dir, consistent with the other three scripts. The --output-dir argument is marked as deprecated but remains supported for the time being. Use of both long forms is guarded againist by using a mutually exclusive group. A deprecation warning is issued when --output-dir is used. When the deprecated parameter is removed, both the group and the warning can be done away with. As a side note, it seems that Python 3.13 will add "deprecated" to argparse's add_argument: https://docs.python.org/3.13/library/argparse.html#deprecated --- .appveyor.yml | 2 +- bin/make_studyvisit_archive | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 4a328c4..b3b5397 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -80,7 +80,7 @@ install: for s in $STUDIES; do for v in visit_a visit_b; do icf-utils make_studyvisit_archive - --output-dir "$STUDIES_DIR" + --store-dir "$STUDIES_DIR" --id $s $v "$FROM_SCANNER"; done diff --git a/bin/make_studyvisit_archive b/bin/make_studyvisit_archive index 4945b9a..5a31801 100755 --- a/bin/make_studyvisit_archive +++ b/bin/make_studyvisit_archive @@ -22,6 +22,7 @@ from datetime import datetime from hashlib import md5 from pathlib import Path from typing import Dict +import warnings from tqdm import tqdm @@ -178,11 +179,16 @@ def main(input_base_dir: str, if __name__ == '__main__': import argparse p = argparse.ArgumentParser(description=__doc__) - p.add_argument( - "-o", "--output-dir", metavar='PATH', default=os.getcwd(), + g = p.add_mutually_exclusive_group() + g.add_argument( + "-o", "--store-dir", metavar='PATH', default=os.getcwd(), help="Base directory to place the archive structure in. " "The corresponding '/' subdirectory for the " - "study is created automatically, if needed") + "study is created automatically, if needed.") + g.add_argument( + "--output-dir", metavar="PATH", + help="Deprecated, will be removed in the future; " + "use -o/--store-dir instead.") p.add_argument( '--id', nargs=2, metavar=('STUDY-ID', 'VISIT-ID'), required=True, help="The study and visit identifiers, used to name and " @@ -198,8 +204,18 @@ if __name__ == '__main__': "directory with the name '_' is used " "to place all archive content in.") args = p.parse_args() + if args.output_dir is not None: + store_dir = args.output_dir + msg = ( + "--output-dir argument is deprecated and will be removed " + "in the future. Use use -o/--store-dir instead." + ) + warnings.warn(msg, DeprecationWarning) + else: + store_dir = args.store_dir + main(input_base_dir=args.input_dir, - output_base_dir=args.output_dir, + output_base_dir=store_dir, study_id=args.id[0], visit_id=args.id[1], ) From 8aed3919e6c74bc7ba5cca6da445b3eec72594ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szczepanik?= Date: Mon, 19 Aug 2024 11:59:12 +0200 Subject: [PATCH 2/2] Fix docstring typo Co-authored-by: Adina Wagner --- bin/make_studyvisit_archive | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/make_studyvisit_archive b/bin/make_studyvisit_archive index 5a31801..ad970e9 100755 --- a/bin/make_studyvisit_archive +++ b/bin/make_studyvisit_archive @@ -208,7 +208,7 @@ if __name__ == '__main__': store_dir = args.output_dir msg = ( "--output-dir argument is deprecated and will be removed " - "in the future. Use use -o/--store-dir instead." + "in the future. Use -o/--store-dir instead." ) warnings.warn(msg, DeprecationWarning) else: