Skip to content

Commit d580970

Browse files
committed
Merge branch 'main' into pt-colors
2 parents a02e688 + cc88ca6 commit d580970

4 files changed

Lines changed: 36 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ prompt is displayed.
8181
- `cmd2` no longer sets a default title for a subparsers group. If you desire a title, you will
8282
need to pass one in like this `parser.add_subparsers(title="subcommands")`. This is standard
8383
`argparse` behavior.
84-
- Added `HelpFormatterRenderable` protocol and `HelpContent` type alias to support context-aware
85-
help content in `argparse`.
86-
- `TextGroup` now implements `HelpFormatterRenderable`.
84+
- `TextGroup` now implements `HelpFormatterRenderable` (see Enhancements section below for more
85+
details).
8786
- Removed `formatter_creator` parameter from `TextGroup.__init__()`.
8887
- Removed `Cmd2ArgumentParser.create_text_group()` method.
8988
- `argparse` and `Rich` integration refactoring:
@@ -145,6 +144,8 @@ prompt is displayed.
145144
full type hints and IDE autocompletion for `self._cmd` without needing to override and cast
146145
the property.
147146
- Added `traceback_kwargs` attribute to allow customization of Rich-based tracebacks.
147+
- Added `HelpFormatterRenderable` protocol and `HelpContent` type alias to support context-aware
148+
help content in `argparse`.
148149
- The `print()` function available in a `pyscript` writes to `self.stdout` and respects the
149150
`allow_style` setting. It also supports printing `Rich` objects.
150151
- Added `Cmd2ArgumentParser.output_to()` context manager to temporarily set the output stream

cmd2/cmd2.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,20 +1272,20 @@ def always_prefix_settables(self) -> bool:
12721272
return self._always_prefix_settables
12731273

12741274
@always_prefix_settables.setter
1275-
def always_prefix_settables(self, new_value: bool) -> None:
1275+
def always_prefix_settables(self, value: bool) -> None:
12761276
"""Set whether CommandSet settable values should always be prefixed.
12771277
1278-
:param new_value: True if CommandSet settable values should always be prefixed. False if not.
1278+
:param value: True if CommandSet settable values should always be prefixed. False if not.
12791279
:raises ValueError: If a registered CommandSet does not have a defined prefix
12801280
"""
1281-
if not self._always_prefix_settables and new_value:
1281+
if not self._always_prefix_settables and value:
12821282
for cmd_set in self._installed_command_sets:
12831283
if not cmd_set.settable_prefix:
12841284
raise ValueError(
12851285
f"Cannot force settable prefixes. CommandSet {cmd_set.__class__.__name__} does "
12861286
f"not have a settable prefix defined."
12871287
)
1288-
self._always_prefix_settables = new_value
1288+
self._always_prefix_settables = value
12891289

12901290
@property
12911291
def settables(self) -> Mapping[str, Settable]:
@@ -1389,14 +1389,20 @@ def allow_style(self) -> ru.AllowStyle:
13891389
return ru.ALLOW_STYLE
13901390

13911391
@allow_style.setter
1392-
def allow_style(self, new_val: ru.AllowStyle) -> None:
1392+
def allow_style(self, value: ru.AllowStyle) -> None:
13931393
"""Setter property needed to support do_set when it updates allow_style."""
1394-
ru.ALLOW_STYLE = new_val
1394+
ru.ALLOW_STYLE = value
13951395

13961396
@property
13971397
def traceback_show_locals(self) -> bool:
13981398
"""Property needed to support do_set when it reads traceback_show_locals."""
1399-
return cast(bool, self.traceback_kwargs.get("show_locals", False))
1399+
if "show_locals" in self.traceback_kwargs:
1400+
return cast(bool, self.traceback_kwargs["show_locals"])
1401+
1402+
# If setting is not present, then return its default value.
1403+
traceback_sig = inspect.signature(Traceback.__init__)
1404+
show_locals = traceback_sig.parameters["show_locals"].default
1405+
return cast(bool, show_locals)
14001406

14011407
@traceback_show_locals.setter
14021408
def traceback_show_locals(self, value: bool) -> None:

mkdocs.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,15 @@ markdown_extensions:
125125

126126
# Validation
127127
validation:
128-
nav:
129-
omitted_files: info
130-
not_found: warn
131-
absolute_links: info
132-
links:
133-
not_found: warn
134-
absolute_links: ignore
135-
unrecognized_links: info
128+
invalid_link_anchors: true
129+
invalid_links: true
130+
shadowed_definitions: true
131+
shadowed_footnotes: true
132+
unresolved_footnotes: true
133+
# bug with mkdocstrings autorefs: https://github.com/zensical/zensical/issues/600
134+
unresolved_references: false
135+
unused_definitions: true
136+
unused_footnotes: true
136137

137138
not_in_nav: |
138139
**/download/*.md

tests/test_cmd2.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,22 @@ def test_set_allow_style(base_app, new_val, is_valid, expected) -> None:
241241

242242

243243
def test_set_traceback_show_locals(base_app: cmd2.Cmd) -> None:
244-
# Use the set command to alter traceback_show_locals
244+
"""Test the set command for reading and setting traceback_show_locals."""
245+
import inspect
246+
247+
from rich.traceback import Traceback
248+
249+
# Get Traceback's default value for "show_locals"
250+
traceback_sig = inspect.signature(Traceback.__init__)
251+
default_val = traceback_sig.parameters["show_locals"].default
245252

246253
# Clear any existing value
247254
base_app.traceback_kwargs.pop("show_locals", None)
248255
assert "show_locals" not in base_app.traceback_kwargs
249256

250-
# Test that we receive a default value of False if not present
257+
# Test that we receive the default value if not present
251258
orig_val = base_app.traceback_show_locals
252-
assert orig_val is False
259+
assert orig_val is default_val
253260
assert "show_locals" not in base_app.traceback_kwargs
254261

255262
# Test setting it

0 commit comments

Comments
 (0)