From 4f6673e70308e1f9a9876ab73d25c40e49a66560 Mon Sep 17 00:00:00 2001 From: David Gros Date: Tue, 6 Oct 2020 18:27:42 -0500 Subject: [PATCH 1/5] add a --version flag to the parlai command #3163 --- parlai/core/script.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/parlai/core/script.py b/parlai/core/script.py index e94aaa3839a..f7379aa8b87 100644 --- a/parlai/core/script.py +++ b/parlai/core/script.py @@ -17,6 +17,7 @@ import io import argparse from typing import List, Optional, Dict, Any +import parlai from parlai.core.opt import Opt from parlai.core.params import ParlaiParser, CustomHelpFormatter from abc import abstractmethod @@ -168,6 +169,7 @@ def print_helpall(self): self.print_help() + class _SubcommandParser(ParlaiParser): """ ParlaiParser which always sets add_parlai_args and add_model_args to False. @@ -203,10 +205,18 @@ def superscript_main(args=None): parser = _SupercommandParser( False, False, formatter_class=_SuperscriptHelpFormatter ) + helpall_help_str = 'List all commands, including advanced ones.' parser.add_argument( '--helpall', action='helpall', - help='show all commands, including advanced ones.', + help=helpall_help_str, + ) + versioninfo_help_str = 'Prints version info and exit.srlai ' + parser.add_argument( + '--version', + action='version', + version=get_version_string(), + help=versioninfo_help_str, ) parser.set_defaults(super_command=None) subparsers = parser.add_subparsers( @@ -222,7 +232,7 @@ def superscript_main(args=None): hparser = subparsers.add_parser( 'helpall', help=argparse.SUPPRESS, - description="List all commands, including advanced ones.", + description=helpall_help_str, ) hparser.set_defaults(super_command='helpall') @@ -265,7 +275,13 @@ def superscript_main(args=None): cmd = opt.pop('super_command') if cmd == 'helpall': parser.print_helpall() + elif cmd == 'versioninfo': + exit(0) elif cmd == 'help' or cmd is None: parser.print_help() elif cmd is not None: return SCRIPT_REGISTRY[cmd].klass._run_from_parser_and_opt(opt, parser) + + +def get_version_string() -> str: + return f"ParlAI version {parlai.__version__}" From ab6f036d0c16b3119bff4c6f732178b635ad8e3e Mon Sep 17 00:00:00 2001 From: David Gros Date: Tue, 6 Oct 2020 18:32:37 -0500 Subject: [PATCH 2/5] run autoformatter to fix lint issue --- parlai/core/script.py | 1 - 1 file changed, 1 deletion(-) diff --git a/parlai/core/script.py b/parlai/core/script.py index f7379aa8b87..3a140537fc5 100644 --- a/parlai/core/script.py +++ b/parlai/core/script.py @@ -169,7 +169,6 @@ def print_helpall(self): self.print_help() - class _SubcommandParser(ParlaiParser): """ ParlaiParser which always sets add_parlai_args and add_model_args to False. From ff0a5d1d16cdefd111b0723062ee77c165a88683 Mon Sep 17 00:00:00 2001 From: David Gros Date: Tue, 6 Oct 2020 18:53:34 -0500 Subject: [PATCH 3/5] correct weird typo --- parlai/core/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parlai/core/script.py b/parlai/core/script.py index 3a140537fc5..7fbf518fbe7 100644 --- a/parlai/core/script.py +++ b/parlai/core/script.py @@ -210,7 +210,7 @@ def superscript_main(args=None): action='helpall', help=helpall_help_str, ) - versioninfo_help_str = 'Prints version info and exit.srlai ' + versioninfo_help_str = 'Prints version info and exit.' parser.add_argument( '--version', action='version', From 99be94f85bc1d82faf3ed1aecd0f2e089e2b3625 Mon Sep 17 00:00:00 2001 From: David Gros Date: Tue, 6 Oct 2020 20:09:08 -0500 Subject: [PATCH 4/5] tweak based off PR feedback https://github.com/facebookresearch/ParlAI/pull/3164/files/ff0a5d1d16cdefd111b0723062ee77c165a88683#r500676864 --- parlai/core/script.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/parlai/core/script.py b/parlai/core/script.py index 7fbf518fbe7..f87a54a8801 100644 --- a/parlai/core/script.py +++ b/parlai/core/script.py @@ -204,18 +204,16 @@ def superscript_main(args=None): parser = _SupercommandParser( False, False, formatter_class=_SuperscriptHelpFormatter ) - helpall_help_str = 'List all commands, including advanced ones.' parser.add_argument( '--helpall', action='helpall', - help=helpall_help_str, + help='List all commands, including advanced ones.', ) - versioninfo_help_str = 'Prints version info and exit.' parser.add_argument( '--version', action='version', version=get_version_string(), - help=versioninfo_help_str, + help='Prints version info and exit.', ) parser.set_defaults(super_command=None) subparsers = parser.add_subparsers( @@ -225,13 +223,13 @@ def superscript_main(args=None): 'help', aliases=['h'], help=argparse.SUPPRESS, - description="List the main commands", + description='Prints version info and exit.', ) hparser.set_defaults(super_command='help') hparser = subparsers.add_parser( 'helpall', help=argparse.SUPPRESS, - description=helpall_help_str, + description='List all commands, including advanced ones.', ) hparser.set_defaults(super_command='helpall') From 0f7470ac9a19f0013db6795cc463afc7a57ddccc Mon Sep 17 00:00:00 2001 From: David Gros Date: Tue, 6 Oct 2020 23:22:37 -0500 Subject: [PATCH 5/5] fix sloppy mixup of argument help descriptions introduced in last commit (sorry!) --- parlai/core/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parlai/core/script.py b/parlai/core/script.py index f87a54a8801..4924800998d 100644 --- a/parlai/core/script.py +++ b/parlai/core/script.py @@ -223,7 +223,7 @@ def superscript_main(args=None): 'help', aliases=['h'], help=argparse.SUPPRESS, - description='Prints version info and exit.', + description='List the main commands.', ) hparser.set_defaults(super_command='help') hparser = subparsers.add_parser(