How to use handle_provision method in tox

Best Python code snippet using tox_python

provision.py

Source:provision.py Github

copy

Full Screen

...46 parser.add_argument("--add_client", type=str, default="", help="yaml file for added client")47def has_no_arguments() -> bool:48 last_item = sys.argv[-1]49 return last_item.endswith("provision") or last_item.endswith("provision.py")50def handle_provision(args):51 file_path = pathlib.Path(__file__).parent.absolute()52 current_path = os.getcwd()53 custom_folder_path = os.path.join(current_path, args.custom_folder)54 sys.path.append(custom_folder_path)55 print("\nPath list (sys.path) for python codes loading: {} \n".format(sys.path))56 # main project file57 project_file = args.project_file58 current_project_yml = os.path.join(current_path, "project.yml")59 if has_no_arguments() and not os.path.exists(current_project_yml):60 files = {"1": "ha_project.yml", "2": "dummy_project.yml", "3": None}61 print("No project.yml found in current folder.\nThere are two types of templates for project.yml.")62 print(63 "1) project.yml for HA mode\n2) project.yml for non-HA mode\n3) Don't generate project.yml. Exit this program."64 )65 answer = input(f"Which type of project.yml should be generated at {current_project_yml} for you? (1/2/3) ")66 answer = answer.strip()67 src_project = files.get(answer, None)68 if src_project:69 shutil.copyfile(os.path.join(file_path, src_project), current_project_yml)70 print(71 f"{current_project_yml} was created. Please edit it to fit your FL configuration. "72 + "Once done please run nvflare provision command again with newly edited project.yml file"73 )74 else:75 print(f"{answer} was selected. No project.yml was created.")76 exit(0)77 workspace = args.workspace78 workspace_full_path = os.path.join(current_path, workspace)79 project_full_path = os.path.join(current_path, project_file)80 print(f"Project yaml file: {project_full_path}.")81 project_dict = load_yaml(project_full_path)82 api_version = project_dict.get("api_version")83 if api_version not in [3]:84 raise ValueError(f"API version expected 3 but found {api_version}")85 project_name = project_dict.get("name")86 project_description = project_dict.get("description", "")87 participants = list()88 for p in project_dict.get("participants"):89 participants.append(Participant(**p))90 if args.add_user:91 try:92 extra = load_yaml(os.path.join(current_path, args.add_user))93 extra.update({"type": "admin"})94 participants.append(Participant(**extra))95 except BaseException:96 print("** Error during adding user **")97 print("The yaml file format is")98 print(adding_user_error_msg)99 exit(0)100 if args.add_client:101 try:102 extra = load_yaml(os.path.join(current_path, args.add_client))103 extra.update({"type": "client"})104 participants.append(Participant(**extra))105 except BaseException as e:106 print("** Error during adding client **")107 print("The yaml file format is")108 print(adding_client_error_msg)109 exit(0)110 project = Project(name=project_name, description=project_description, participants=participants)111 n_servers = len(project.get_participants_by_type("server", first_only=False))112 if n_servers > 2:113 print(114 f"Configuration error: Expect 2 or 1 server to be provisioned. {project_full_path} contains {n_servers} servers."115 )116 return117 builders = list()118 for b in project_dict.get("builders"):119 path = b.get("path")120 args = b.get("args")121 builders.append(instantiate_class(path, args))122 provisioner = Provisioner(workspace_full_path, builders)123 provisioner.provision(project)124def main():125 print("*****************************************************************************")126 print("** provision command is deprecated, please use 'nvflare provision' instead **")127 print("*****************************************************************************")128 parser = argparse.ArgumentParser()129 define_provision_parser(parser)130 args = parser.parse_args()131 handle_provision(args)132if __name__ == "__main__":...

Full Screen

Full Screen

cli.py

Source:cli.py Github

copy

Full Screen

1# Copyright (c) 2021-2022, NVIDIA CORPORATION. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import argparse15import os16import sys17from nvflare.cli_exception import CLIException18from nvflare.dashboard.cli import define_dashboard_parser, handle_dashboard19from nvflare.fuel.hci.tools.authz_preview import define_authz_preview_parser, run_command20from nvflare.lighter.poc_commands import def_poc_parser, handle_poc_cmd21from nvflare.lighter.provision import define_provision_parser, handle_provision22from nvflare.private.fed.app.simulator.simulator import define_simulator_parser, run_simulator23from nvflare.tool.preflight_check import check_packages, define_preflight_check_parser24CMD_POC = "poc"25CMD_PROVISION = "provision"26CMD_PREFLIGHT_CHECK = "preflight_check"27CMD_SIMULATOR = "simulator"28CMD_DASHBOARD = "dashboard"29CMD_AUTHZ_PREVIEW = "authz_preview"30def check_python_version():31 if sys.version_info >= (3, 9):32 raise RuntimeError("Python versions 3.9 and above are not yet supported. Please use Python 3.8 or 3.7.")33 if sys.version_info < (3, 7):34 raise RuntimeError("Python versions 3.6 and below are not supported. Please use Python 3.8 or 3.7.")35def def_provision_parser(sub_cmd):36 cmd = CMD_PROVISION37 provision_parser = sub_cmd.add_parser(cmd)38 define_provision_parser(provision_parser)39 return {cmd: [provision_parser]}40def def_dashboard_parser(sub_cmd):41 cmd = CMD_DASHBOARD42 dashboard_parser = sub_cmd.add_parser(cmd)43 define_dashboard_parser(dashboard_parser)44 return {cmd: [dashboard_parser]}45def def_preflight_check_parser(sub_cmd):46 cmd = CMD_PREFLIGHT_CHECK47 checker_parser = sub_cmd.add_parser(cmd)48 define_preflight_check_parser(checker_parser)49 return {cmd: checker_parser}50def def_simulator_parser(sub_cmd):51 cmd = CMD_SIMULATOR52 simulator_parser = sub_cmd.add_parser(cmd)53 define_simulator_parser(simulator_parser)54 return {cmd: simulator_parser}55def handle_simulator_cmd(simulator_args):56 status = run_simulator(simulator_args)57 # make sure the script terminate after run58 if status:59 sys.exit(status)60def def_authz_preview_parser(sub_cmd):61 cmd = CMD_AUTHZ_PREVIEW62 authz_preview_parser = sub_cmd.add_parser(cmd)63 define_authz_preview_parser(authz_preview_parser)64 return {cmd: authz_preview_parser}65def handle_authz_preview(args):66 run_command(args)67def parse_args(prog_name: str):68 _parser = argparse.ArgumentParser(description=prog_name)69 _parser.add_argument("--version", "-V", action="store_true", help="print nvflare version")70 sub_cmd = _parser.add_subparsers(description="sub command parser", dest="sub_command")71 sub_cmd_parsers = {}72 sub_cmd_parsers.update(def_poc_parser(sub_cmd))73 sub_cmd_parsers.update(def_preflight_check_parser(sub_cmd))74 sub_cmd_parsers.update(def_provision_parser(sub_cmd))75 sub_cmd_parsers.update(def_simulator_parser(sub_cmd))76 sub_cmd_parsers.update(def_dashboard_parser(sub_cmd))77 sub_cmd_parsers.update(def_authz_preview_parser(sub_cmd))78 return _parser, _parser.parse_args(), sub_cmd_parsers79handlers = {80 CMD_POC: handle_poc_cmd,81 CMD_PROVISION: handle_provision,82 CMD_PREFLIGHT_CHECK: check_packages,83 CMD_SIMULATOR: handle_simulator_cmd,84 CMD_DASHBOARD: handle_dashboard,85 CMD_AUTHZ_PREVIEW: handle_authz_preview,86}87def run(prog_name):88 cwd = os.getcwd()89 sys.path.append(cwd)90 prog_parser, prog_args, sub_cmd_parsers = parse_args(prog_name)91 sub_cmd = None92 try:93 sub_cmd = prog_args.sub_command94 if sub_cmd:95 handlers[sub_cmd](prog_args)96 elif prog_args.version:97 print_nvflare_version()98 else:99 prog_parser.print_help()100 except CLIException as e:101 print(e)102 sys.exit(1)103 except Exception as e:104 print(f"unable to handle command: {sub_cmd} due to: {e}, please check syntax ")105 print_help(prog_parser, sub_cmd, sub_cmd_parsers)106def print_help(prog_parser, sub_cmd, sub_cmd_parsers):107 if sub_cmd:108 sub_parser = sub_cmd_parsers[sub_cmd]109 if sub_parser:110 sub_parser.print_help()111 else:112 prog_parser.print_help()113 else:114 prog_parser.print_help()115def print_nvflare_version():116 import nvflare117 print(f"NVFlare version is {nvflare.__version__}")118def main():119 check_python_version()120 run("nvflare")121if __name__ == "__main__":...

Full Screen

Full Screen

provisioncheck.py

Source:provisioncheck.py Github

copy

Full Screen

...32 if needpro:33 phone_number = yield get_bindphone(userid)34 if phone_number:35 logging.info("new user %s provision" % phone_number)36 yield handle_provision(token, userid, phone_number)37 self.finish()...

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 tox 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