-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rfc-dtsh 28/28]: west: west integration
West command to open the devicetree shell (dtsh). West command implementation: - class dtsh in zephyr/scripts/west_commands/dtshell.py - packages dtsh and devicetree imported with os.sys.insert() statements Add dtsh extension to West in zephyr/scripts/west-commands.yml. Add dtsh's requirements to "used by west_commands" in zephyr/scripts/requirements-base.txt: - rich (https://github.com/Textualize/rich) - Pygments (https://github.com/pygments/pygments) Add support for West completion in: - zephyr/scripts/west_commands/completion/west-completion.bash - zephyr/scripts/west_commands/completion/west-completion.zsh Signed-off-by: Christophe Dufaza <chris@openmarl.org>
- Loading branch information
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ psutil | |
pylink-square | ||
pyserial | ||
requests | ||
rich | ||
Pygments | ||
|
||
# for ram/rom reports | ||
anytree | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Copyright (c) 2023 Christophe Dufaza <chris@openmarl.org> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""West command to open the devicetree shell (dtsh).""" | ||
|
||
|
||
from typing import Optional, List | ||
|
||
import argparse | ||
import sys | ||
|
||
from west.commands import WestCommand | ||
from west import log | ||
|
||
from zephyr_ext_common import ZEPHYR_SCRIPTS | ||
|
||
|
||
# DtSh dependencies that are not installed within the West workspace's | ||
# Python virtual environment. | ||
sys.path.insert(0, str(ZEPHYR_SCRIPTS / "dts" / "python-devicetree" / "src")) | ||
sys.path.insert(1, str(ZEPHYR_SCRIPTS / "dts" / "dtsh" / "src")) | ||
|
||
from dtsh.shell import DtShError | ||
from dtsh.rich.session import DtShRichSession | ||
|
||
|
||
DTSH_DESCRIPTION = """\ | ||
Shell-like interface with a devicetree. | ||
- browse the devicetree through a familiar hierarchical file-system metaphor | ||
- retrieve nodes and bindings with accustomed command names | ||
and command line syntax | ||
- generate simple documentation artifacts by redirecting commands output | ||
to files (text, HTML, SVG) | ||
- common command line interface paradigms (auto-completion, history) | ||
and keybindings | ||
By default, dtsh will try to retrieve, or work out, the binding files | ||
Zephyr has used at build-time to generate the DTS file, | ||
or would use if it were to generate the DTS "now". | ||
The --bindings-search-path option overrides this behavior by explicitly | ||
setting the bindings search directories. | ||
If the command line does not specify a DTS file path, | ||
dtsh will try to open the devicetree at build/zephy/zephyr.dts, | ||
allowing for a simple work-flow: | ||
$ west build | ||
$ west dtsh | ||
""" | ||
|
||
|
||
class dtsh(WestCommand): | ||
"""Devicetree shell West command.""" | ||
|
||
def __init__(self) -> None: | ||
super().__init__( | ||
"dtsh", | ||
"devicetree shell", | ||
DTSH_DESCRIPTION, | ||
accepts_unknown_args=False | ||
) | ||
|
||
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( | ||
"dts", | ||
help="path to the Devicetree source file", | ||
nargs="?", | ||
metavar="DTS", | ||
default="build/zephyr/zephyr.dts" | ||
) | ||
parser.add_argument( | ||
"--bindings-search-path", | ||
help="directories to search for the binding files", | ||
required=False, | ||
nargs="+", | ||
metavar="PATH" | ||
) | ||
|
||
return parser | ||
|
||
def do_run(self, args, unknown) -> None: | ||
del unknown # Unused. | ||
dts: str = args.dts | ||
binding_dirs: Optional[List[str]] = args.bindings_search_path | ||
|
||
try: | ||
# Initialize DT model, shell, etc. | ||
session = DtShRichSession.create(dts, binding_dirs) | ||
except DtShError as e: | ||
log.die(e.msg) | ||
|
||
# Enter the devicetree shell interactive session loop. | ||
session.run() |