Skip to content

Commit 621df39

Browse files
authored
Merge pull request #231 from python-cmd2/pyperclip_version
Added fix for changes in pyperclip project structure in latest version
2 parents b16b912 + 5027f7c commit 621df39

27 files changed

+37
-740
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
## 0.7.8 (TBD, 2017)
1+
## 0.7.8 (November TBD, 2017)
22

33
* Bug Fixes
44
* Fixed ``poutput()`` so it can print an integer zero and other **falsy** things
55
* Fixed a bug which was causing autodoc to fail for building docs on Readthedocs
6+
* Fixed bug due to ``pyperclip`` dependency radically changing its project structure in latest version
67
* Enhancements
78
* Improved documentation for user-settable environment parameters
89
* Improved documentation for overriding the default supported comment styles

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ Tutorials
114114

115115
A couple tutorials on using cmd2 exist:
116116

117-
* A detailed PyCon 2010 talk by [Catherine Devlin](https://github.com/catherinedevlin), the original author
118-
* http://pyvideo.org/pycon-us-2010/pycon-2010--easy-command-line-applications-with-c.html
119-
* A nice brief step-by-step tutorial
120-
* https://kushaldas.in/posts/developing-command-line-interpreters-using-python-cmd2.html
117+
* Florida PyCon 2017 talk: [slides](https://archive.org/details/pyvideo_541___pyohio-2011-interactive-command-line-interpreters-with-cmd-and-cmd2)
118+
* PyCon 2010 talk by Catherine Devlin, the original author: [video](http://pyvideo.org/pycon-us-2010/pycon-2010--easy-command-line-applications-with-c.html)
119+
* A nice brief step-by-step tutorial: [blog](https://kushaldas.in/posts/developing-command-line-interpreters-using-python-cmd2.html)
121120

122121

123122
Example Application

cmd2.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
import pyparsing
4747
import pyperclip
4848

49+
# Newer versions of pyperclip are released as a single file, but older versions had a more complicated structure
50+
try:
51+
from pyperclip.exceptions import PyperclipException
52+
except ImportError:
53+
# noinspection PyUnresolvedReferences
54+
from pyperclip import PyperclipException
55+
4956
# On some systems, pyperclip will import gtk for its clipboard functionality.
5057
# The following code is a workaround for gtk interfering with printing from a background
5158
# thread while the CLI thread is blocking in raw_input() in Python 2 on Linux.
@@ -98,7 +105,7 @@
98105
else:
99106
BROKEN_PIPE_ERROR = IOError
100107

101-
__version__ = '0.7.8a'
108+
__version__ = '0.7.8'
102109

103110
# Pyparsing enablePackrat() can greatly speed up parsing, but problems have been seen in Python 3 in the past
104111
pyparsing.ParserElement.enablePackrat()
@@ -324,13 +331,17 @@ def new_func(instance, arg):
324331
# Can we access the clipboard? Should always be true on Windows and Mac, but only sometimes on Linux
325332
# noinspection PyUnresolvedReferences
326333
try:
327-
if sys.platform.startswith('linux'):
334+
# Get the version of the pyperclip module as a float
335+
pyperclip_ver = float('.'.join(pyperclip.__version__.split('.')[:2]))
336+
337+
# The extraneous output bug in pyperclip on Linux using xclip was fixed in more recent versions of pyperclip
338+
if sys.platform.startswith('linux') and pyperclip_ver < 1.6:
328339
# Avoid extraneous output to stderr from xclip when clipboard is empty at cost of overwriting clipboard contents
329340
pyperclip.copy('')
330341
else:
331342
# Try getting the contents of the clipboard
332343
_ = pyperclip.paste()
333-
except pyperclip.exceptions.PyperclipException:
344+
except PyperclipException:
334345
can_clip = False
335346
else:
336347
can_clip = True
@@ -582,7 +593,7 @@ def poutput(self, msg, end='\n'):
582593
Also handles BrokenPipeError exceptions for when a commands's output has been piped to another process and
583594
that process terminates before the cmd2 command is finished executing.
584595
585-
:param msg: str - message to print to current stdout - anyting convertible to a str with '{}'.format() is OK
596+
:param msg: str - message to print to current stdout - anything convertible to a str with '{}'.format() is OK
586597
:param end: str - string appended after the end of the message if not already present, default a newline
587598
"""
588599
if msg is not None and msg != '':

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
# The short X.Y version.
6363
version = '0.7'
6464
# The full version, including alpha/beta/rc tags.
65-
release = '0.7.7'
65+
release = '0.7.8'
6666

6767
# The language for content autogenerated by Sphinx. Refer to documentation
6868
# for a list of supported languages.

docs/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ Resources
4646
* cmd_
4747
* `cmd2 project page`_
4848
* `project bug tracker`_
49-
* `PyCon 2010 presentation <https://github.com/python-cmd2/cmd2/blob/master/docs/pycon2010/pycon2010.rst>`_,
50-
*Easy Command-Line Applications with cmd and cmd2*:
51-
:doc:`slides <pycon2010/pycon2010>`,
49+
* Florida PyCon 2017: `slides <https://docs.google.com/presentation/d/1LRmpfBt3V-pYQfgQHdczf16F3hcXmhK83tl77R6IJtE/edit?usp=sharing>`_
50+
* PyOhio 2011: `video <https://archive.org/details/pyvideo_541___pyohio-2011-interactive-command-line-interpreters-with-cmd-and-cmd2>`_
51+
* PyCon 2010: `presentation <https://github.com/python-cmd2/cmd2/blob/master/docs/pycon2010/pycon2010.rst>`_,
5252
`video <http://pyvideo.org/pycon-us-2010/pycon-2010--easy-command-line-applications-with-c.html>`_
5353

5454
These docs will refer to ``App`` as your ``cmd2.Cmd``

docs/integrating.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ code like the following::
4646

4747
# Do this within whatever event loop mechanism you wish to run a single command
4848
cmd_line_text = "help history"
49-
app.onecmd_plus_hooks(cmd_line_text)
49+
app.runcmds_plus_hooks([cmd_line_text])
5050

5151
app.postloop()
5252

53+
The **runcmds_plus_hooks()** method is a convenience method to run multiple commands via **onecmd_plus_hooks()**. It
54+
properly deals with ``load`` commands which under the hood put commands in a FIFO queue as it reads them in from a
55+
script file.
56+
5357
The **onecmd_plus_hooks()** method will do the following to execute a single ``cmd2`` command in a normal fashion:
5458

5559
#. Parse the command line text
@@ -70,4 +74,10 @@ several disadvantages, including:
7074
* Does not support transcript testing
7175
* Does not allow commands at invocation via command-line arguments
7276

77+
Here is a little more info on ``runcmds_plus_hooks``:
78+
79+
.. automethod:: cmd2.Cmd.runcmds_plus_hooks
80+
81+
82+
7383

docs/pycon2010/akkad.png

-56.6 KB
Binary file not shown.

docs/pycon2010/apple.jpg

-70.5 KB
Binary file not shown.

docs/pycon2010/hook.jpg

-51.3 KB
Binary file not shown.

docs/pycon2010/pirate.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)