Skip to content

Commit

Permalink
Merge branch 'master' into etc-removal
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Jan 2, 2015
2 parents a7ae0cf + 3d3a520 commit 42792bf
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 6 deletions.
6 changes: 3 additions & 3 deletions invoke/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from functools import partial
import inspect
import os
import sys
import textwrap
Expand Down Expand Up @@ -213,15 +214,14 @@ def parse(argv, collection=None, version=None):
# Setup
ctx = parser.contexts[name]
tuples = ctx.help_tuples()
docstring = collection[name].__doc__
docstring = inspect.getdoc(collection[name])
header = "Usage: inv[oke] [--core-opts] %s %%s[other tasks here ...]" % name
print(header % ("[--options] " if tuples else ""))
print("")
print("Docstring:")
if docstring:
# Really wish textwrap worked better for this.
doclines = textwrap.dedent(docstring.lstrip('\n').rstrip()+'\n').splitlines()
for line in doclines:
for line in docstring.splitlines():
if line.strip():
print(indent + line)
else:
Expand Down
3 changes: 1 addition & 2 deletions invoke/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def out_filter(text):
return text
else:
return b""
wrapped_cmd = "/bin/bash -c \"%s\"" % command
p = pexpect.spawn(wrapped_cmd)
p = pexpect.spawn("/bin/bash", ["-c", command])
# Ensure pexpect doesn't barf with OSError if we fall off the end of
# the child's input on some platforms (e.g. Linux).
exception = None
Expand Down
7 changes: 7 additions & 0 deletions sites/www/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Changelog
=========

* :bug:`191` Bypass ``pexpect``'s automatic command splitting to avoid issues
running complex nested/quoted commands under a pty. Credit to ``@mijikai``
for noticing the problem.
* :bug:`183` Task docstrings whose first line started on the same line as the
opening quote(s) were incorrectly presented in ``invoke --help <task>``. This
has been fixed by using `inspect.getdoc`. Thanks to Pekka Klärck for the
catch & suggested fix.
* :bug:`180` Empty invocation (e.g. just ``invoke`` with no flags or tasks, and
when no default task is defined) no
longer printed help output, instead complaining about the lack of default
Expand Down
2 changes: 1 addition & 1 deletion sites/www/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ see with ``inv --list``. Some specific tasks of note:
.. _contribution-guide.org: http://contribution-guide.org

.. _our GitHub page:
.. _pyinvoke/invoke: https://github.cm/pyinvoke/invoke
.. _pyinvoke/invoke: https://github.com/pyinvoke/invoke
10 changes: 10 additions & 0 deletions tests/_support/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def foo2():
"""
pass

@task
def foo3():
"""Foo the other bar:
example code
Added in 1.1
"""
pass

@task(default=True)
def biz():
pass
Expand Down
17 changes: 17 additions & 0 deletions tests/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ def per_task_help_dedents_correctly(self):
""".lstrip()
_output_eq('-c decorator -h foo2', expected)

def per_task_help_dedents_correctly_for_alternate_docstring_style(self):
expected = """
Usage: inv[oke] [--core-opts] foo3 [other tasks here ...]
Docstring:
Foo the other bar:
example code
Added in 1.1
Options:
none
""".lstrip()
_output_eq('-c decorator -h foo3', expected)

def version_info(self):
_output_eq('-V', "Invoke %s\n" % invoke.__version__)

Expand Down
10 changes: 10 additions & 0 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ def return_value_indicates_whether_pty_was_used(self):
def pty_defaults_to_off(self):
eq_(run("true").pty, False)

def complex_nesting_doesnt_break(self):
# GH issue 191
substr = " hello\t\t\nworld with spaces"
cmd = """ eval 'echo "{0}" ' """.format(substr)
# TODO: consider just mocking os.execv here (and in the other
# tests) though that feels like too much of a tautology / testing
# pexpect
expected = ' hello\t\t\r\nworld with spaces\r\n'
eq_(run(cmd, pty=True, hide='both').stdout, expected)

class command_echo:
@trap
def does_not_echo_commands_run_by_default(self):
Expand Down

0 comments on commit 42792bf

Please sign in to comment.