-
Notifications
You must be signed in to change notification settings - Fork 124
Add methods to register hooks, for better plugin support #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
# Conflicts: # cmd2/cmd2.py
| """.splitlines()))) | ||
|
|
||
| INSTALL_REQUIRES = ['pyperclip >= 1.5.27', 'colorama'] | ||
| INSTALL_REQUIRES = ['pyperclip >= 1.5.27', 'colorama', 'attrs'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anytime we add a dependency we should updated the README.md accordingly since we have a section which discusses the required dependencies.
| parser = StatementParser() | ||
| return parser | ||
|
|
||
| def test_parse_empty_string_default(default_parser): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the extra unit tests
| backwards compatibility with the standard library version of cmd. | ||
| """ | ||
| statement = self.statement_parser.parse(line) | ||
| statement = self.statement_parser.parse(self.preparse(line)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making sure preparse now properly gets called
| """Hook method executed just before the command line is interpreted, but after the input prompt is generated. | ||
| """Hook method executed before user input is parsed. | ||
| WARNING: If it's a multiline command, `preparse()` may not get all the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good comment
|
@kotfu @kmvanbrunt I know you are pretty busy at work, but if you get a chance, I would value your feedback for this PR. |
Also: - Bumped version to 0.9.4 - Updated info in Readme and Sphinx docs to reflect new dependency on attrs
|
I stared updating the CHANGELOG for you and bumped the version to 0.9.4. I also updated the README and Sphinx docs to reflect the new dependency on |
| ## 0.9.4 (TBD, 2018) | ||
| * Bug Fixes | ||
| * Fixed bug where ``preparse`` wasn't getting called | ||
| * Enhancements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fill in a better description of your changes
tleonhardt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to merge whenever. Lets give it a couple days to see if @kmvanbrunt can find some time to give it a look.
| * Fixed bug where ``preparse`` wasn't getting called | ||
| * Enhancements | ||
| * Improved implementation of lifecycle hooks to to support a plugin | ||
| framework, see ``docs/hooks.rst`` for details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description looks good. Thanks for updating.
|
I manually merged master into this PR because a conflict in test_parsing.py needed to be resolved. @kotfu @kmvanbrunt I will need to add a bug fix or two to this PR to get the VSTS builds passing. |
|
Sorry for temporarily breaking the build system. I should have it fixed sometime this evening. |
Currently this represents VSTS Hosted Linux builds - But it is a placeholder for eventual VSTS Hosted macOS builds
| [](https://pypi.python.org/pypi/cmd2/) | ||
| [](https://travis-ci.org/python-cmd2/cmd2) | ||
| [](https://ci.appveyor.com/project/FedericoCeratto/cmd2) | ||
| [](https://python-cmd2.visualstudio.com/cmd2/_build/latest?definitionId=1&branch=master) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cmd2 PR build/test CI system is now also integrated with Visual Studio Team Services (VSTS). Currently it is doing builds for Python 3.6 and 3.7 on Linux VMs on a Windows host which is redundant with the TravisCI testing. But the idea is that eventually we will use VSTS to do our macOS testing once Microsoft's support for that feature is more complete.
|
@kotfu The one thing this PR could really benefit from is a new example called something like hooks.py demonstrating the new methods for registering hooks. |
Added typing backport dependency for Python 3.4
VSTS is now running unit tests for Python 3.6.5 on macOS - In the future we will be able to test on multiple versions of Python on macOS using VSTS, but there is currently a limitation to testing with Python installed from Homebrew
|
@kmvanbrunt @anselor |
|
Ok @kmvanbrunt wouldn’t have time to review this for another week and a half, so I’m just going to merge this PR. |
Add methods which allow multiple application and command processing lifecycle hooks to be registered. All registered hooks are called at the appropriate point of the application or command processing lifecycle.
The primary driver for this change is better support for plugins. Prior to this PR, if a plugin implements an application or command processing hook, the plugin will break if the
cmd2.Cmdapplication also implements the same hook.This PR deprecates all of the current application and command processing lifecycle hooks, except those required to retain backwards compatibility with
cmd.Cmd. Complete documentation of the new system, including the now deprecated methods can be found inhooks.rst.I have created a new plugin which implements the recently removed abbreviation behavior. The plugin can be found at https://github.com/python-cmd2/cmd2-abbrev. The plugin utilizes the hook methods in this PR.
I have also created a plugin template project (https://github.com/python-cmd2/cmd2-plugin-template) which implements a sample plugin and includes best practices and recommendations for plugin developers.
TODO:
preparsegets called for backwards compatibility reasonspreparse