diff --git a/scripts/setup/nrfconnect/zap_common.py b/scripts/setup/nrfconnect/zap_common.py index 01d50b35b3..95d1dec48b 100644 --- a/scripts/setup/nrfconnect/zap_common.py +++ b/scripts/setup/nrfconnect/zap_common.py @@ -17,6 +17,8 @@ from west import log +MATTER_PATH = Path(__file__).parents[3] + def find_zap(root: Path = Path.cwd(), max_depth: int = 1): """ Find *.zap file in the given directory or its subdirectories. diff --git a/scripts/setup/nrfconnect/zap_generate.py b/scripts/setup/nrfconnect/zap_generate.py index fe09e03a2c..ca0357ae18 100644 --- a/scripts/setup/nrfconnect/zap_generate.py +++ b/scripts/setup/nrfconnect/zap_generate.py @@ -2,14 +2,17 @@ # # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +import argparse import os import sys -from textwrap import dedent + from pathlib import Path +from textwrap import dedent from west import log from west.commands import WestCommand -from zap_common import find_zap, ZapInstaller + +from zap_common import find_zap, ZapInstaller, MATTER_PATH class ZapGenerate(WestCommand): @@ -25,11 +28,12 @@ def __init__(self): def do_add_parser(self, parser_adder): parser = parser_adder.add_parser(self.name, help=self.help, + formatter_class=argparse.RawDescriptionHelpFormatter, description=self.description) - - parser.add_argument('-z', '--zap-file', help='Path to the .zap file [optional]') - parser.add_argument('-o', '--output', help='Path where to store the generated files [optional]') - + parser.add_argument('-z', '--zap-file', type=Path, + help='Path to data model configuration file (*.zap)') + parser.add_argument('-o', '--output', type=Path, + help='Path where to store the generated files') return parser def do_run(self, args, unknown_args): @@ -46,8 +50,8 @@ def do_run(self, args, unknown_args): if args.output is None: args.output = args.zap_file.parent.absolute() / "zap-generated" - MATTER_PATH = str(Path(self.manifest.path).parent.absolute() / "../modules/lib/matter") - APP_TEMPLATES = MATTER_PATH + "/src/app/zap-templates/app-templates.json" + app_templates_path = MATTER_PATH / "src/app/zap-templates/app-templates.json" + zap_generate_path = MATTER_PATH / "scripts/tools/zap/generate.py" zap_installer = ZapInstaller(Path(MATTER_PATH)) zap_installer.update_zap_if_needed() @@ -55,9 +59,9 @@ def do_run(self, args, unknown_args): # make sure that the generate.py script uses the proper zap_cli binary (handled by west) os.environ["ZAP_INSTALL_PATH"] = str(zap_installer.get_zap_cli_path().parent.absolute()) - cmd = [MATTER_PATH + "/scripts/tools/zap/generate.py"] + cmd = [str(zap_generate_path)] cmd += ["{}".format(args.zap_file)] - cmd += ["-t", APP_TEMPLATES] + cmd += ["-t", str(app_templates_path)] cmd += ["-o", "{}".format(args.output)] self.check_call(cmd) diff --git a/scripts/setup/nrfconnect/zap_gui.py b/scripts/setup/nrfconnect/zap_gui.py index c6d22e20b1..82ba05e701 100644 --- a/scripts/setup/nrfconnect/zap_gui.py +++ b/scripts/setup/nrfconnect/zap_gui.py @@ -9,12 +9,10 @@ from pathlib import Path from textwrap import dedent -from zap_common import find_zap, ZapInstaller - from west import log from west.commands import WestCommand -MATTER_PATH = Path(__file__).parents[3] +from zap_common import find_zap, ZapInstaller, MATTER_PATH class ZapGui(WestCommand): @@ -30,10 +28,10 @@ def __init__(self): attributes and events are enabled for the given application.''')) def do_add_parser(self, parser_adder): - parser = parser_adder.add_parser( - self.name, help=self.help, - formatter_class=argparse.RawDescriptionHelpFormatter, - description=self.description) + parser = parser_adder.add_parser(self.name, + help=self.help, + formatter_class=argparse.RawDescriptionHelpFormatter, + description=self.description) parser.add_argument('-z', '--zap-file', type=Path, help='Path to data model configuration file (*.zap)') parser.add_argument('-j', '--zcl-json', type=Path,