Skip to content

Commit 6b5c23c

Browse files
authored
Merge pull request #370 from python-cmd2/ply
Switch parsing logic from pyparsing to shlex
2 parents d37004d + fa94eed commit 6b5c23c

23 files changed

+993
-789
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
## 0.9.0 (TBD, 2018)
2+
* Bug Fixes
3+
* If self.default_to_shell is true, then redirection and piping are now properly passed to the shell. Previously it was truncated.
4+
* Submenus now call all hooks, it used to just call precmd and postcmd.
25
* Enhancements
36
* Automatic completion of ``argparse`` arguments via ``cmd2.argparse_completer.AutoCompleter``
47
* See the [tab_autocompletion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/tab_autocompletion.py) example for a demonstration of how to use this feature
58
* ``cmd2`` no longer depends on the ``six`` module
69
* ``cmd2`` is now a multi-file Python package instead of a single-file module
710
* New pyscript approach that provides a pythonic interface to commands in the cmd2 application.
11+
* Switch command parsing from pyparsing to custom code which utilizes shlex.
12+
* The object passed to do_* methods has changed. It no longer is the pyparsing object, it's a new Statement object, which is a subclass of ``str``. The statement object has many attributes which give you access to various components of the parsed input. If you were using anything but the string in your do_* methods, this change will require you to update your code.
13+
* ``commentGrammers`` is no longer supported or available. Comments are C-style or python style.
14+
* Input redirection no longer supported. Use the load command instead.
15+
* ``multilineCommand`` attribute is ``now multiline_command``
16+
* ``identchars`` is now ignored. The standardlibrary cmd uses those characters to split the first "word" of the input, but cmd2 hasn't used those for a while, and the new parsing logic parses on whitespace, which has the added benefit of full unicode support, unlike cmd or prior versions of cmd2.
17+
* ``set_posix_shlex`` function and ``POSIX_SHLEX`` variable have been removed. Parsing behavior is now always the more forgiving ``posix=false``.
18+
* ``set_strip_quotes`` function and ``STRIP_QUOTES_FOR_NON_POSIX`` have been removed. Quotes are stripped from arguments when presented as a list (a la ``sys.argv``), and present when arguments are presented as a string (like the string passed to do_*).
19+
* Changes
20+
* ``strip_ansi()`` and ``strip_quotes()`` functions have moved to new utils module
21+
* Several constants moved to new constants module
822
* Deletions (potentially breaking changes)
923
* Deleted all ``optparse`` code which had previously been deprecated in release 0.8.0
1024
* The ``options`` decorator no longer exists

CONTRIBUTING.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ The tables below list all prerequisites along with the minimum required version
4545
| Prerequisite | Minimum Version |
4646
| --------------------------------------------------- | --------------- |
4747
| [Python](https://www.python.org/downloads/) | `3.4` |
48-
| [pyparsing](http://pyparsing.wikispaces.com) | `2.1` |
4948
| [pyperclip](https://github.com/asweigart/pyperclip) | `1.6` |
5049

5150
#### Additional prerequisites to run cmd2 unit tests
@@ -63,15 +62,13 @@ The tables below list all prerequisites along with the minimum required version
6362
### Optional prerequisites for enhanced unit test features
6463
| Prerequisite | Minimum Version |
6564
| ------------------------------------------- | --------------- |
66-
| [pytest-forked](https://pypi.python.org/pypi/pytest-forked)| `0.2` |
67-
| [pytest-xdist](https://pypi.python.org/pypi/pytest-xdist)| `1.15` |
6865
| [pytest-cov](https://pypi.python.org/pypi/pytest-cov) | `1.8` |
6966

7067
If Python is already installed in your machine, run the following commands to validate the versions:
7168

7269
```shell
7370
python -V
74-
pip freeze | grep pyparsing
71+
pip freeze | grep pyperclip
7572
```
7673

7774
If your versions are lower than the prerequisite versions, you should update.
@@ -190,16 +187,16 @@ Once you have cmd2 cloned, before you start any cmd2 application, you first need
190187

191188
```bash
192189
# Install cmd2 prerequisites
193-
pip install -U pyparsing pyperclip
190+
pip install -U pyperclip
194191

195192
# Install prerequisites for running cmd2 unit tests
196193
pip install -U pytest
197194

198195
# Install prerequisites for building cmd2 documentation
199196
pip install -U sphinx sphinx-rtd-theme
200197

201-
# Install optional prerequisites for running unit tests in parallel and doing code coverage analysis
202-
pip install -U pytest-xdist pytest-cov pytest-forked
198+
# Install optional prerequisites for doing code coverage analysis
199+
pip install -U pytest-cov
203200
```
204201

205202
For doing cmd2 development, you actually do NOT want to have cmd2 installed as a Python package.
@@ -259,35 +256,21 @@ py.test
259256

260257
and ensure all tests pass.
261258

262-
If you have the `pytest-xdist` pytest distributed testing plugin installed, then you can use it to
263-
dramatically speed up test execution by running tests in parallel on multiple cores like so:
264-
265-
```shell
266-
py.test -n4
267-
```
268-
where `4` should be replaced by the number of parallel threads you wish to run for testing.
269-
270-
If you have the `pytest-forked` pytest plugin (not avilable on Windows) for running tests in isolated formed processes,
271-
you can speed things up even further:
272-
273-
```shell
274-
py.test -nauto --forked
275-
```
276259

277260
#### Measuring code coverage
278261

279262
Code coverage can be measured as follows:
280263

281264
```shell
282-
py.test -nauto --cov=cmd2 --cov-report=term-missing --cov-report=html --forked
265+
py.test --cov=cmd2 --cov-report=term-missing --cov-report=html
283266
```
284267

285268
Then use your web browser of choice to look at the results which are in `<cmd2>/htmlcov/index.html`.
286269

287270
### Squash Your Commits
288271
When you make a pull request, it is preferable for all of your changes to be in one commit.
289272

290-
If you have made more then one commit, then you will can _squash_ your commits.
273+
If you have made more then one commit, then you can _squash_ your commits.
291274

292275
To do this, see [Squashing Your Commits](http://forum.freecodecamp.com/t/how-to-squash-multiple-commits-into-one-with-git/13231).
293276

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Main Features
2323
- Python scripting of your application with ``pyscript``
2424
- Run shell commands with ``!``
2525
- Pipe command output to shell commands with `|`
26-
- Redirect command output to file with `>`, `>>`; input from file with `<`
26+
- Redirect command output to file with `>`, `>>`
2727
- Bare `>`, `>>` with no filename send output to paste buffer (clipboard)
2828
- `py` enters interactive Python console (opt-in `ipy` for IPython console)
2929
- Option to display long output using a pager with ``cmd2.Cmd.ppaged()``
@@ -57,7 +57,7 @@ pip install -U cmd2
5757
```
5858

5959
cmd2 works with Python 3.4+ on Windows, macOS, and Linux. It is pure Python code with
60-
the only 3rd-party dependencies being on [pyparsing](http://pyparsing.wikispaces.com), and [pyperclip](https://github.com/asweigart/pyperclip).
60+
the only 3rd-party dependencies being on [colorama](https://github.com/tartley/colorama), and [pyperclip](https://github.com/asweigart/pyperclip).
6161
Windows has an additional dependency on [pyreadline](https://pypi.python.org/pypi/pyreadline). Non-Windows platforms
6262
have an additional dependency on [wcwidth](https://pypi.python.org/pypi/wcwidth). Finally, Python
6363
3.4 has an additional dependency on [contextlib2](https://pypi.python.org/pypi/contextlib2).
@@ -91,7 +91,7 @@ Instructions for implementing each feature follow.
9191

9292
- Multi-line commands
9393

94-
Any command accepts multi-line input when its name is listed in `Cmd.multilineCommands`.
94+
Any command accepts multi-line input when its name is listed in `Cmd.multiline_commands`.
9595
The program will keep expecting input until a line ends with any of the characters
9696
in `Cmd.terminators` . The default terminators are `;` and `/n` (empty newline).
9797

@@ -165,7 +165,7 @@ class CmdLineApp(cmd2.Cmd):
165165
MUMBLE_LAST = ['right?']
166166

167167
def __init__(self):
168-
self.multilineCommands = ['orate']
168+
self.multiline_commands = ['orate']
169169
self.maxrepeats = 3
170170

171171
# Add stuff to settable and shortcuts before calling base class initializer

0 commit comments

Comments
 (0)