diff options
-rw-r--r-- | .coveragerc | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | CONTRIBUTING.md | 1 | ||||
-rwxr-xr-x | examples/dynamic_commands.py | 26 | ||||
-rwxr-xr-x | setup.py | 6 |
5 files changed, 26 insertions, 10 deletions
diff --git a/.coveragerc b/.coveragerc index 307e3a9a..96bf5d72 100644 --- a/.coveragerc +++ b/.coveragerc @@ -20,5 +20,5 @@ precision = 1 [html] -# (string, default “htmlcov”): where to write the HTML report files. +# (string, default "htmlcov"): where to write the HTML report files. directory = htmlcov diff --git a/CHANGELOG.md b/CHANGELOG.md index 72dedb06..9dcb2a12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.9.23 (TBD, 2019) * Bug Fixes * Fixed bug where startup script containing a single quote in its file name was incorrectly quoted + * Added missing implicit dependency on `setuptools` due to build with `setuptools_scm` * Breaking changes * Renamed the following `ansi` members for accuracy in what types of ANSI escape sequences are handled * `ansi.allow_ansi` -> `ansi.allow_style` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6055fa7d..96c2d312 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,6 +51,7 @@ The tables below list all prerequisites along with the minimum required version | [attrs](https://github.com/python-attrs/attrs) | `16.3` | | [colorama](https://github.com/tartley/colorama) | `0.3.7` | | [pyperclip](https://github.com/asweigart/pyperclip) | `1.6` | +| [setuptools](https://pypi.org/project/setuptools/) | `34.4` | | [wcwidth](https://pypi.python.org/pypi/wcwidth) | `0.1.7` | diff --git a/examples/dynamic_commands.py b/examples/dynamic_commands.py index 69816d40..620acb7f 100755 --- a/examples/dynamic_commands.py +++ b/examples/dynamic_commands.py @@ -3,13 +3,32 @@ """A simple example demonstrating how do_* commands can be created in a loop. """ import functools + import cmd2 -COMMAND_LIST = ['foo', 'bar', 'baz'] +from cmd2.constants import COMMAND_FUNC_PREFIX, HELP_FUNC_PREFIX + +COMMAND_LIST = ['foo', 'bar'] +CATEGORY = 'Dynamic Commands' class CommandsInLoop(cmd2.Cmd): """Example of dynamically adding do_* commands.""" def __init__(self): + # Add dynamic commands before calling cmd2.Cmd's init since it validates command names + for command in COMMAND_LIST: + # Create command function and add help category to it + cmd_func = functools.partial(self.send_text, text=command) + cmd2.categorize(cmd_func, CATEGORY) + + # Add command function to CLI object + cmd_func_name = COMMAND_FUNC_PREFIX + command + setattr(self, cmd_func_name, cmd_func) + + # Add help function to CLI object + help_func = functools.partial(self.text_help, text=command) + help_func_name = HELP_FUNC_PREFIX + command + setattr(self, help_func_name, help_func) + super().__init__(use_ipython=True) def send_text(self, args: cmd2.Statement, *, text: str): @@ -21,11 +40,6 @@ class CommandsInLoop(cmd2.Cmd): self.poutput("Simulate sending {!r} to a server and printing the response".format(text)) -for command in COMMAND_LIST: - setattr(CommandsInLoop, 'do_{}'.format(command), functools.partialmethod(CommandsInLoop.send_text, text=command)) - setattr(CommandsInLoop, 'help_{}'.format(command), functools.partialmethod(CommandsInLoop.text_help, text=command)) - - if __name__ == '__main__': app = CommandsInLoop() app.cmdloop() @@ -29,9 +29,9 @@ Programming Language :: Python :: Implementation :: CPython Topic :: Software Development :: Libraries :: Python Modules """.splitlines()))) # noqa: E128 -SETUP_REQUIRES = ['setuptools_scm'] +SETUP_REQUIRES = ['setuptools_scm >= 3.0.0'] -INSTALL_REQUIRES = ['pyperclip >= 1.6', 'colorama >= 0.3.7', 'attrs >= 16.3.0', 'wcwidth >= 0.1.7'] +INSTALL_REQUIRES = ['attrs >= 16.3.0', 'colorama >= 0.3.7', 'pyperclip >= 1.6', 'setuptools >= 34.4', 'wcwidth >= 0.1.7'] EXTRAS_REQUIRE = { # Windows also requires pyreadline to ensure tab completion works @@ -39,7 +39,7 @@ EXTRAS_REQUIRE = { # Extra dependencies for running unit tests 'test': ["gnureadline; sys_platform=='darwin'", # include gnureadline on macOS to ensure it is available in tox env "mock ; python_version<'3.6'", # for python 3.5 we need the third party mock module - 'codecov', 'pytest', 'pytest-cov', 'pytest-mock'], + 'codecov', 'coverage', 'pytest', 'pytest-cov', 'pytest-mock'], # development only dependencies: install with 'pip install -e .[dev]' 'dev': ["mock ; python_version<'3.6'", # for python 3.5 we need the third party mock module 'pytest', 'codecov', 'pytest-cov', 'pytest-mock', 'tox', 'flake8', |