From 1b66482911665ed1d7f99f1f2942cd219f14059b Mon Sep 17 00:00:00 2001 From: Parichit Sharma Date: Thu, 24 May 2018 17:40:01 -0400 Subject: [PATCH 1/8] Display a helpful message when, 1) There is a mismatch between the number of arguments in the doc string and the run method. --- dipy/workflows/base.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dipy/workflows/base.py b/dipy/workflows/base.py index 3708aa129a..45b7b48845 100644 --- a/dipy/workflows/base.py +++ b/dipy/workflows/base.py @@ -115,12 +115,28 @@ def add_workflow(self, workflow): output_args = \ self.add_argument_group('output arguments(optional)') + # This check simply shows a helpful message to the user if there + # is a mismatch in the number of arguments in the run method and + # the doc string. Doc string refers to the parameter help written + # in the workflow python script. + + if len(args) != len(self.doc): + print(self.prog+": Number of parameters in the doc string and " + "run method does not match. Please ensure that" + " the number of parameters in the run method is" + " the same as the doc string.") + exit(1) + + for i, arg in enumerate(args): prefix = '' is_optionnal = i >= len_args - len_defaults if is_optionnal: prefix = '--' + print(i) + print(self.doc[i]) + typestr = self.doc[i][1] dtype, isnarg = self._select_dtype(typestr) help_msg = ''.join(self.doc[i][2]) @@ -268,6 +284,9 @@ def get_flow_args(self, args=None, namespace=None): ns_args = self.parse_args(args, namespace) dct = vars(ns_args) + + print(dct) + return dict((k, v) for k, v in dct.items() if v is not None) def update_argument(self, *args, **kargs): From b1dec1e119a62582c2845fc58214f3679ebbff32 Mon Sep 17 00:00:00 2001 From: Parichit Sharma Date: Thu, 24 May 2018 17:42:34 -0400 Subject: [PATCH 2/8] Removed debugging messages. --- dipy/workflows/base.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/dipy/workflows/base.py b/dipy/workflows/base.py index 45b7b48845..6a1959974f 100644 --- a/dipy/workflows/base.py +++ b/dipy/workflows/base.py @@ -109,9 +109,6 @@ def add_workflow(self, workflow): args, defaults = get_args_default(workflow.run) - len_args = len(args) - len_defaults = len(defaults) - output_args = \ self.add_argument_group('output arguments(optional)') @@ -134,9 +131,6 @@ def add_workflow(self, workflow): if is_optionnal: prefix = '--' - print(i) - print(self.doc[i]) - typestr = self.doc[i][1] dtype, isnarg = self._select_dtype(typestr) help_msg = ''.join(self.doc[i][2]) From cae030adad1a521e3ed452f532552d7aa55a2745 Mon Sep 17 00:00:00 2001 From: Parichit Sharma Date: Thu, 24 May 2018 17:54:04 -0400 Subject: [PATCH 3/8] Removed the extra print statements --- dipy/workflows/base.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dipy/workflows/base.py b/dipy/workflows/base.py index 6a1959974f..ac345abc07 100644 --- a/dipy/workflows/base.py +++ b/dipy/workflows/base.py @@ -124,6 +124,8 @@ def add_workflow(self, workflow): " the same as the doc string.") exit(1) + len_args = len(args) + len_defaults = len(defaults) for i, arg in enumerate(args): prefix = '' @@ -278,9 +280,6 @@ def get_flow_args(self, args=None, namespace=None): ns_args = self.parse_args(args, namespace) dct = vars(ns_args) - - print(dct) - return dict((k, v) for k, v in dct.items() if v is not None) def update_argument(self, *args, **kargs): From 65dcbbca1b39b76192f335b00b5cd0bcabcb9427 Mon Sep 17 00:00:00 2001 From: Parichit Sharma Date: Thu, 24 May 2018 17:55:44 -0400 Subject: [PATCH 4/8] Reshuffled the statements for finding the length of the arguments and doc string. --- dipy/workflows/base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dipy/workflows/base.py b/dipy/workflows/base.py index ac345abc07..713bd23d0b 100644 --- a/dipy/workflows/base.py +++ b/dipy/workflows/base.py @@ -112,20 +112,21 @@ def add_workflow(self, workflow): output_args = \ self.add_argument_group('output arguments(optional)') + len_args = len(args) + len_defaults = len(defaults) + # This check simply shows a helpful message to the user if there # is a mismatch in the number of arguments in the run method and # the doc string. Doc string refers to the parameter help written # in the workflow python script. - if len(args) != len(self.doc): + if len_args != len(self.doc): print(self.prog+": Number of parameters in the doc string and " "run method does not match. Please ensure that" " the number of parameters in the run method is" " the same as the doc string.") exit(1) - len_args = len(args) - len_defaults = len(defaults) for i, arg in enumerate(args): prefix = '' From 564f2126ae860da0845e3f5f922eacaec08dcfe9 Mon Sep 17 00:00:00 2001 From: Parichit Sharma Date: Thu, 31 May 2018 14:54:12 -0400 Subject: [PATCH 5/8] Replaced the exit statement with the a proper error. 1) An error is raised when the number of parameters mismatch between the doc string and the run method. 2) Tetsed the change with dipy_info and a manual workflow and the error is raised properly. --- dipy/workflows/base.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/dipy/workflows/base.py b/dipy/workflows/base.py index 713bd23d0b..2b0ae5b31c 100644 --- a/dipy/workflows/base.py +++ b/dipy/workflows/base.py @@ -121,11 +121,10 @@ def add_workflow(self, workflow): # in the workflow python script. if len_args != len(self.doc): - print(self.prog+": Number of parameters in the doc string and " - "run method does not match. Please ensure that" - " the number of parameters in the run method is" - " the same as the doc string.") - exit(1) + raise ValueError(self.prog+": Number of parameters in the" + " doc string and run method does not match." + " Please ensure that the number of parameters" + " in the run method is same as the doc string.") for i, arg in enumerate(args): From 4cde26d54169c34ad1e6716829a6cdbe4fbd9b77 Mon Sep 17 00:00:00 2001 From: Parichit Sharma Date: Thu, 31 May 2018 15:09:21 -0400 Subject: [PATCH 6/8] Fixed the Pep8 warnings with respect to the change. --- dipy/workflows/base.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dipy/workflows/base.py b/dipy/workflows/base.py index 2b0ae5b31c..4924183c24 100644 --- a/dipy/workflows/base.py +++ b/dipy/workflows/base.py @@ -101,7 +101,7 @@ def add_workflow(self, workflow): ref_text = [text if text else "\n" for text in npds['References']] ref_idx = self.epilog.find('References: \n') + len('References: \n') self.epilog = "{0}{1}\n{2}".format(self.epilog[:ref_idx], - ''.join([text for text in ref_text]), + ''.join([text for text in ref_text]), self.epilog[ref_idx:]) self.outputs = [param for param in npds['Parameters'] if @@ -121,10 +121,12 @@ def add_workflow(self, workflow): # in the workflow python script. if len_args != len(self.doc): - raise ValueError(self.prog+": Number of parameters in the" - " doc string and run method does not match." - " Please ensure that the number of parameters" - " in the run method is same as the doc string.") + raise ValueError( + self.prog + + ": Number of parameters in the " + "doc string and run method does not match. " + "Please ensure that the number of parameters " + "in the run method is same as the doc string.") for i, arg in enumerate(args): From 45f20b3e2b4be7e81fdb18b4d9bb29fec6b31f0e Mon Sep 17 00:00:00 2001 From: Parichit Sharma Date: Tue, 5 Jun 2018 19:02:38 -0400 Subject: [PATCH 7/8] Updated the indentation and other things as pointed in the comments of the PR. --- dipy/workflows/base.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/dipy/workflows/base.py b/dipy/workflows/base.py index 4924183c24..dd6ab2c544 100644 --- a/dipy/workflows/base.py +++ b/dipy/workflows/base.py @@ -101,32 +101,25 @@ def add_workflow(self, workflow): ref_text = [text if text else "\n" for text in npds['References']] ref_idx = self.epilog.find('References: \n') + len('References: \n') self.epilog = "{0}{1}\n{2}".format(self.epilog[:ref_idx], - ''.join([text for text in ref_text]), - self.epilog[ref_idx:]) + ''.join(ref_text), + self.epilog[ref_idx:]) self.outputs = [param for param in npds['Parameters'] if 'out_' in param[0]] args, defaults = get_args_default(workflow.run) - output_args = \ - self.add_argument_group('output arguments(optional)') + output_args = self.add_argument_group('output arguments(optional)') len_args = len(args) len_defaults = len(defaults) - # This check simply shows a helpful message to the user if there - # is a mismatch in the number of arguments in the run method and - # the doc string. Doc string refers to the parameter help written - # in the workflow python script. - if len_args != len(self.doc): raise ValueError( - self.prog + - ": Number of parameters in the " - "doc string and run method does not match. " - "Please ensure that the number of parameters " - "in the run method is same as the doc string.") + self.prog + ": Number of parameters in the " + "doc string and run method does not match. " + "Please ensure that the number of parameters " + "in the run method is same as the doc string.") for i, arg in enumerate(args): From 357a7922f0f4b00228979ec37b049cdab873d1e3 Mon Sep 17 00:00:00 2001 From: Parichit Sharma Date: Mon, 2 Jul 2018 16:59:42 -0400 Subject: [PATCH 8/8] Fixed the PEP8 issues. --- dipy/workflows/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dipy/workflows/base.py b/dipy/workflows/base.py index dd6ab2c544..1a71fc62df 100644 --- a/dipy/workflows/base.py +++ b/dipy/workflows/base.py @@ -102,7 +102,7 @@ def add_workflow(self, workflow): ref_idx = self.epilog.find('References: \n') + len('References: \n') self.epilog = "{0}{1}\n{2}".format(self.epilog[:ref_idx], ''.join(ref_text), - self.epilog[ref_idx:]) + self.epilog[ref_idx:]) self.outputs = [param for param in npds['Parameters'] if 'out_' in param[0]] @@ -121,7 +121,6 @@ def add_workflow(self, workflow): "Please ensure that the number of parameters " "in the run method is same as the doc string.") - for i, arg in enumerate(args): prefix = '' is_optionnal = i >= len_args - len_defaults