Any pipe breaks inv -l when the task name is too long

Open
#865 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
38/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
cli

Research direction

Start at invoke/terminals.py around line 56, then follow the traceback through program.py's list_tasks, display_with_columns, and print_columns. Reproduce the issue with a 74-character task name and inv -l | grep a; done means the piped listing completes without the invalid-width error.

Written by the indexing model from the issue text.

Description

My config is:

  • macOS 12.4 (21F79)
  • Python 3.9.12
  • invoke 1.7.1

When the task reaches 74 characters, it's not possible to use a pipe with inv -l(the command still works on its own).
While it is unlikely to have a name as long as 74 characters, it is possible to have something like {collection_name}.{task_name}.{action} which goes up to 74 characters.

I suspect the issue to be in there: https://github.com/pyinvoke/invoke/blob/main/invoke/terminals.py#L56

Example:

from invoke import task

name = 'a' * 74

@task(name=name)
def my_task(ctx):
    pass
inv -l | grep a
Traceback (most recent call last):
  File "/Users/florent/PycharmProjects/test/.venv/bin/inv", line 8, in <module>
Available tasks:
    sys.exit(program.run())
  File "/Users/florent/PycharmProjects/test/.venv/lib/python3.9/site-packages/invoke/program.py", line 377, in run
    self.parse_cleanup()
  File "/Users/florent/PycharmProjects/test/.venv/lib/python3.9/site-packages/invoke/program.py", line 516, in parse_cleanup
    self.list_tasks()
  File "/Users/florent/PycharmProjects/test/.venv/lib/python3.9/site-packages/invoke/program.py", line 790, in list_tasks
    getattr(self, "list_{}".format(self.list_format))()
  File "/Users/florent/PycharmProjects/test/.venv/lib/python3.9/site-packages/invoke/program.py", line 794, in list_flat
    self.display_with_columns(pairs=pairs)
  File "/Users/florent/PycharmProjects/test/.venv/lib/python3.9/site-packages/invoke/program.py", line 901, in display_with_columns
    self.print_columns(pairs)
  File "/Users/florent/PycharmProjects/test/.venv/lib/python3.9/site-packages/invoke/program.py", line 936, in print_columns
    help_chunks = wrapper.wrap(help_str)
  File "/Users/florent/.pyenv/versions/3.9.12/lib/python3.9/textwrap.py", line 354, in wrap
    return self._wrap_chunks(chunks)
  File "/Users/florent/.pyenv/versions/3.9.12/lib/python3.9/textwrap.py", line 248, in _wrap_chunks
    raise ValueError("invalid width %r (must be > 0)" % self.width)
ValueError: invalid width 0 (must be > 0)
Dominant language
Python
Stars
4.8k
Forks
412
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pyinvoke/invoke

All issues in pyinvoke/invoke

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.