How to use add_cli_args method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

cli.py

Source:cli.py Github

copy

Full Screen

...62def pformat4help(obj,indent=0):63 help_str = pformat(obj, compact=False, indent=indent). \64 replace('"', '').replace("'", "").replace("{", "").replace("}", "")65 return help_str66def add_cli_args(arg_parser: argparse.ArgumentParser, arg_group_list):67 assert set(arg_group_list).issubset(68 ["conda_env_yaml_transform", "conda_env_yaml_transform_cmd", "conda_env_path", "yes_no_confirm",69 "conda_env_update_mode"]70 )71 if "conda_env_path" in arg_group_list:72 arg_parser.add_argument(73 "--conda_env_path",74 help="Full path to conda environment",75 type=check_if_abs_path2dir,76 required=False,77 default=get_current_conda_env_path(),78 )79 if "conda_env_yaml_transform_cmd" in arg_group_list:80 help_str = pformat4help(TRANSFORM_DESCRIPTION_DICT)81 arg_parser.add_argument(82 "conda_env_yaml_transform_cmd",83 metavar="transform",84 help=f"Name of the conda yaml file transform to apply. The following transforms are supported:\n\n{help_str}",85 choices=TRANSFORM_DESCRIPTION_DICT.keys(),86 type=str,87 )88 if "conda_env_yaml_transform" in arg_group_list:89 arg_parser.add_argument(90 "--in_yaml_file",91 help="Input conda environment yaml file path",92 type=check_if_yaml_file_to_path,93 required=False,94 default=MLDEVENV_CONDA_REQA_FILE_NAME95 )96 arg_parser.add_argument(97 "--out_yaml_file",98 help="Output conda environment yaml file path",99 type=check_if_yaml_file_to_path,100 required=False,101 default=None,102 )103 arg_parser.add_argument(104 "--except_package_list",105 nargs="+",106 metavar="PACKAGE_NAME",107 help="Packages to exclude from transformation",108 required=False,109 default=None,110 )111 if "yes_no_confirm" in arg_group_list:112 arg_parser.add_argument(113 "-y",114 help="Suppresses prompt for confirmation",115 action='store_true',116 required=False,117 default=False118 )119 if "conda_env_update_mode" in arg_group_list:120 help_str = pformat4help(ENV_UPDATE_MODE2CMD_DICT)121 arg_parser.add_argument(122 "--update_mode",123 help="What to update\n"124 f"The following modes are supported:\n\n{help_str}",125 choices=ENV_UPDATE_MODE2CMD_DICT.keys(),126 default="all",127 metavar="",128 required=False129 )130 arg_parser.add_argument(131 "-d", "--debug", action="store_true", help="update with debug logs"132 )133def confirm(arg_dict, op_name):134 is_confirmed = arg_dict.pop('y')135 msg = f"Operation '{op_name}' is going to be applied with the following parameters:\n"136 print(f"{msg}")137 param_str = pformat4help(arg_dict, indent=3)138 print(f"{param_str}\n")139 if not is_confirmed:140 confirm_answer = input(":: Proceed with applying the transformation? [Y/n]")141 if confirm_answer.lower() != 'y':142 sys.exit(1)143def conda_env_yaml_transform_cli():144 arg_parser = argparse.ArgumentParser(145 prog=get_prog_name(1),146 description=STRATEGY_DESCRIPTION_DICT["conda_env_yaml_transform"],147 formatter_class=argparse.RawTextHelpFormatter,148 )149 add_cli_args(arg_parser, ["conda_env_yaml_transform_cmd"])150 args = arg_parser.parse_args(args=sys.argv[2:3])151 conda_env_yaml_transform_cmd = args.conda_env_yaml_transform_cmd152 arg_parser = argparse.ArgumentParser(153 prog=get_prog_name(2),154 description=TRANSFORM_DESCRIPTION_DICT[conda_env_yaml_transform_cmd],155 formatter_class=argparse.RawTextHelpFormatter,156 )157 add_cli_args(arg_parser, ["conda_env_yaml_transform", "yes_no_confirm"])158 if conda_env_yaml_transform_cmd == "version_capture":159 add_cli_args(arg_parser, ["conda_env_path"])160 args = arg_parser.parse_args(args=sys.argv[3:])161 transform_func = TRANSFORM_CMD2FUNC_MAP_DICT[conda_env_yaml_transform_cmd]162 if args.out_yaml_file is None:163 args.out_yaml_file = args.in_yaml_file164 arg_dict = dict(args._get_kwargs())165 confirm(arg_dict, conda_env_yaml_transform_cmd)166 transform_func(**arg_dict)167def conda_env_cur_update_cli():168 arg_parser: argparse.ArgumentParser = argparse.ArgumentParser(169 prog=get_prog_name(),170 formatter_class=argparse.RawTextHelpFormatter,171 description=STRATEGY_DESCRIPTION_DICT["conda_env_cur_update"],172 )173 add_cli_args(arg_parser, ["conda_env_update_mode", "yes_no_confirm"])174 args = arg_parser.parse_args(args=sys.argv[2:])175 arg_dict = dict(args._get_kwargs())176 update_mode = args.update_mode177 confirm(arg_dict, update_mode)178 update_current_conda_env(MLDEVENV_CONDA_REQ_FILE_ABS_PATH, **arg_dict)179def cli_strategy():180 argument_parser = argparse.ArgumentParser(181 prog=MAIN_CMD_NAME,182 formatter_class=argparse.RawTextHelpFormatter,183 description="MLDevEnv management tool",184 )185 help_str = pformat4help(STRATEGY_DESCRIPTION_DICT)186 argument_parser.add_argument(187 "strategy",...

Full Screen

Full Screen

context.py

Source:context.py Github

copy

Full Screen

2import os3from . import connection4class Context(object):5 @staticmethod6 def add_cli_args(config_file, parser, search_path=None):7 """ add configuration specific CLI arguments to8 argument parser9 """10 ret = []11 if not os.path.isabs(config_file) and search_path is not None:12 config_file = os.path.normpath(os.path.join(search_path,13 config_file))14 with open(config_file) as fp:15 config = json.load(fp)16 for k, cfg in config.items():17 klass = Context.get_connection_class(cfg)18 if klass is not None and hasattr(klass, 'add_cli_args'):19 gr = klass.add_cli_args(parser)20 if gr is not None:21 ret.append(gr)22 return ret23 @staticmethod24 def get_connection_class(cfg):25 """ determine connection class from configuration entry26 """27 if '_connection' not in cfg:28 return None29 connection_class_name = cfg.pop('_connection')30 try:31 if hasattr(connection, connection_class_name):32 connection_class = getattr(connection,33 connection_class_name)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful