Skip to content

Commit 488bb23

Browse files
committed
auto_load_commands now defaults to False
Also: - The `tests_isolated` directory has been deleted and all tests underneath there have been moved under `tests`
1 parent 26ca1f9 commit 488bb23

File tree

15 files changed

+174
-368
lines changed

15 files changed

+174
-368
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ plugins/* @anselor
5959

6060
# Unit and Integration Tests
6161
tests/* @kmvanbrunt @tleonhardt
62-
tests_isolated/* @anselor
6362

6463
# Top-level project stuff
6564
.coveragerc @tleonhardt

.github/CONTRIBUTING.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,9 @@ This bit is up to you!
346346

347347
The cmd2 project directory structure is pretty simple and straightforward. All actual code for cmd2
348348
is located underneath the `cmd2` directory. The code to generate the documentation is in the `docs`
349-
directory. Unit tests are in the `tests` directory. Integration tests are in the `tests_isolated`
350-
directory. The `examples` directory contains examples of how to use cmd2. There are various other
351-
files in the root directory, but these are primarily related to continuous integration and release
352-
deployment.
349+
directory. Unit and integration tests are in the `tests` directory. The `examples` directory
350+
contains examples of how to use cmd2. There are various other files in the root directory, but these
351+
are primarily related to continuous integration and release deployment.
353352

354353
#### Changes to the documentation files
355354

.github/workflows/tests.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ jobs:
3838
- name: Run tests
3939
run: uv run python -Xutf8 -m pytest --cov --cov-config=pyproject.toml --cov-report=xml tests
4040

41-
- name: Run isolated tests
42-
run:
43-
uv run python -Xutf8 -m pytest --cov --cov-config=pyproject.toml --cov-report=xml
44-
tests_isolated
45-
4641
- name: Upload test results to Codecov
4742
if: ${{ !cancelled() }}
4843
uses: codecov/test-results-action@v1

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ time reading the [rich documentation](https://rich.readthedocs.io/).
2424
`value` property
2525
- Removed redundant setting of a parser's `prog` value in the `with_argparser()` decorator, as
2626
this is now handled centrally in `Cmd._build_parser()`
27+
- The `auto_load_commands` argument to `cmd2.Cmd.__init__` now defaults to `False`
2728

2829
- Enhancements
2930
- Enhanced all print methods (`poutput()`, `perror()`, `ppaged()`, etc.) to natively render

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ typecheck: ## Perform type checking
3434
test: ## Test the code with pytest.
3535
@echo "🚀 Testing code: Running pytest"
3636
@uv run python -Xutf8 -m pytest --cov --cov-config=pyproject.toml --cov-report=xml tests
37-
@uv run python -Xutf8 -m pytest --cov --cov-config=pyproject.toml --cov-report=xml tests_isolated
3837

3938
.PHONY: docs-test
4039
docs-test: ## Test if documentation can be built without warnings or errors

cmd2/cmd2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def __init__(
323323
terminators: list[str] | None = None,
324324
shortcuts: dict[str, str] | None = None,
325325
command_sets: Iterable[CommandSet] | None = None,
326-
auto_load_commands: bool = True,
326+
auto_load_commands: bool = False,
327327
allow_clipboard: bool = True,
328328
suggest_similar_command: bool = False,
329329
) -> None:

codecov.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ component_management:
1414
ignore:
1515
- "examples" # ignore example code folder
1616
- "tests" # ignore unit test code folder
17-
- "tests_isolated" # ignore integration test code folder

docs/features/modular_commands.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44

55
Cmd2 also enables developers to modularize their command definitions into
66
[CommandSet][cmd2.CommandSet] objects. CommandSets represent a logical grouping of commands within a
7-
`cmd2` application. By default, all `CommandSet` objects will be discovered and loaded automatically
8-
when the [cmd2.Cmd][] class is instantiated with this mixin. This also enables the developer to
9-
dynamically add/remove commands from the cmd2 application. This could be useful for loadable plugins
10-
that add additional capabilities. Additionally, it allows for object-oriented encapsulation and
11-
garbage collection of state that is specific to a CommandSet.
7+
`cmd2` application. By default, `CommandSet` objects need to be manually registered. However, it is
8+
possible for all `CommandSet` objects to be discovered and loaded automatically when the
9+
[cmd2.Cmd][] class is instantiated with this mixin by setting `auto_load_commands=True`. This also
10+
enables the developer to dynamically add/remove commands from the `cmd2` application. This could be
11+
useful for loadable plugins that add additional capabilities. Additionally, it allows for
12+
object-oriented encapsulation and garbage collection of state that is specific to a CommandSet.
1213

1314
### Features
1415

1516
- Modular Command Sets - Commands can be broken into separate modules rather than in one god class
1617
holding all commands.
1718
- Automatic Command Discovery - In your application, merely defining and importing a CommandSet is
18-
sufficient for `cmd2` to discover and load your command. No manual registration is necessary.
19+
sufficient for `cmd2` to discover and load your command if you set `auto_load_commands=True`. No
20+
manual registration is necessary.
1921
- Dynamically Loadable/Unloadable Commands - Command functions and CommandSets can both be loaded
2022
and unloaded dynamically during application execution. This can enable features such as
2123
dynamically loaded modules that add additional commands.
@@ -70,7 +72,7 @@ class ExampleApp(cmd2.Cmd):
7072
"""
7173
CommandSets are automatically loaded. Nothing needs to be done.
7274
"""
73-
def __init__(self, *args, **kwargs):
75+
def __init__(self, *args, auto_load_commands=True, **kwargs):
7476
super().__init__(*args, **kwargs)
7577

7678
def do_something(self, arg):
@@ -104,7 +106,7 @@ class ExampleApp(cmd2.Cmd):
104106
"""
105107
CommandSets with initializer parameters are provided in the initializer
106108
"""
107-
def __init__(self, *args, **kwargs):
109+
def __init__(self, *args, auto_load_commands=True, **kwargs):
108110
# gotta have this or neither the plugin or cmd2 will initialize
109111
super().__init__(*args, **kwargs)
110112

@@ -289,7 +291,7 @@ class LoadableVegetables(CommandSet):
289291

290292
class ExampleApp(cmd2.Cmd):
291293
"""
292-
CommandSets are automatically loaded. Nothing needs to be done.
294+
CommandSets are loaded dynamically at runtime via other commands.
293295
"""
294296

295297
def __init__(self, *args, **kwargs):

docs/upgrades.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,11 @@ however it now inherits from `argparse.HelpFormatter`. If you want RawText behav
106106
The benefit is that your `cmd2` applications now have more aesthetically pleasing help which
107107
includes color to make it quicker and easier to visually parse help text. This works for all
108108
supported versions of Python.
109+
110+
### Other Changes
111+
112+
- The `auto_load_commands` argument to `cmd2.Cmd.__init__` now defaults to `False`
113+
- Replaced `Settable.get_value()` and `Settable.set_value()` methods with a more Pythonic `value`
114+
property
115+
- Removed redundant setting of a parser's `prog` value in the `with_argparser()` decorator, as this
116+
is now handled centrally in `Cmd._build_parser()`

pyproject.toml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,16 @@ disallow_untyped_defs = true
8383
exclude = [
8484
"^.git/",
8585
"^.venv/",
86-
"^build/", # .build directory
87-
"^docs/", # docs directory
86+
"^build/", # .build directory
87+
"^docs/", # docs directory
8888
"^dist/",
89-
"^examples/", # examples directory
90-
"^plugins/*", # plugins directory
91-
"^noxfile\\.py$", # nox config file
92-
"setup\\.py$", # any files named setup.py
89+
"^examples/", # examples directory
90+
"^plugins/*", # plugins directory
91+
"^noxfile\\.py$", # nox config file
92+
"setup\\.py$", # any files named setup.py
9393
"^site/",
94-
"^tasks\\.py$", # tasks.py invoke config file
95-
"^tests/", # tests directory
96-
"^tests_isolated/", # tests_isolated directory
94+
"^tasks\\.py$", # tasks.py invoke config file
95+
"^tests/", # tests directory
9796
]
9897
files = ['.']
9998
show_column_numbers = true
@@ -270,7 +269,7 @@ mccabe.max-complexity = 49
270269
"plugins/*.py" = ["INP001"] # Module is part of an implicit namespace
271270

272271
# Ingore various rulesets in test and plugins directories
273-
"{plugins,tests,tests_isolated}/*.py" = [
272+
"{plugins,tests}/*.py" = [
274273
"ANN", # Ignore all type annotation rules in test folders
275274
"ARG", # Ignore all unused argument warnings in test folders
276275
"D", # Ignore all pydocstyle rules in test folders

0 commit comments

Comments
 (0)