Skip to content
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

Bash completion example: unexpected keyword "autocompletion" #966

Closed
charlesreid1 opened this issue Apr 11, 2018 · 4 comments
Closed

Bash completion example: unexpected keyword "autocompletion" #966

charlesreid1 opened this issue Apr 11, 2018 · 4 comments
Milestone

Comments

@charlesreid1
Copy link

The stock bash completion example here appears to be broken.

Here's my steps to reproduce in a virtualenv:

virtualenv vp
source vp/bin/activate
wget https://raw.githubusercontent.com/pallets/click/master/examples/bashcompletion/setup.py
wget https://raw.githubusercontent.com/pallets/click/master/examples/bashcompletion/bashcompletion.py

Now start following the instructions on the readme:

pip install -e .
eval "$(_BASHCOMPLETION_COMPLETE=source bashcompletion)"

Upon execution of the last statement, however, I see a problem:

$ eval "$(_BASHCOMPLETION_COMPLETE=source bashcompletion)"
Traceback (most recent call last):
  File "/temp/py/vp/bin/bashcompletion", line 11, in <module>
    load_entry_point('click-example-bashcompletion', 'console_scripts', 'bashcompletion')()
  File "/temp/py/vp/lib/python3.6/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/temp/py/vp/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2693, in load_entry_point
    return ep.load()
  File "/temp/py/vp/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2324, in load
    return self.resolve()
  File "/temp/py/vp/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2330, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/temp/py/bashcompletion.py", line 17, in <module>
    @click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)
  File "/temp/py/vp/lib/python3.6/site-packages/click/decorators.py", line 151, in decorator
    _param_memo(f, ArgumentClass(param_decls, **attrs))
  File "/temp/py/vp/lib/python3.6/site-packages/click/core.py", line 1699, in __init__
    Parameter.__init__(self, param_decls, required=required, **attrs)
TypeError: __init__() got an unexpected keyword argument 'autocompletion'

This seems to be related to the autocompletion kwarg used to decorate the cmd1() and subcmd() methods:

@cli.command()
@click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)
def cmd1(envvar):
    click.echo('Environment variable: %s' % envvar)
    click.echo('Value: %s' % os.environ[envvar])

@group.command()
@click.argument("user", type=click.STRING, autocompletion=list_users)
def subcmd(user):
    click.echo('Chosen user is %s' % user)

In fact, the problem is that the version of click I have does not include bash autocompletion!

$ grep "autocompletion" vp/lib/python3.6/site-packages/click/core.py
$ 

(compare to current source).

I have click version 6.7 installed,

$ python --version
Python 3.6.4

$ python -c 'import click; print(click.__version__)'
6.7

The example readme states

This example requires Click 2.0 or higher.

I'm a little confused about why bash completion is missing from Click 6.7 when it was added in 2.0!

@dawranliou
Copy link
Contributor

dawranliou commented May 14, 2018

It appears that the autocompletion feature was broken Click version 6.7. However, it's now fixed in the latest master branch since 8ac004f.

I suppose the fix would come out as part of the 7.0 release

@JosiahDub
Copy link
Contributor

I checked 6.6 and 6.0 and there's no mention of autocomplete. I don't think it's ever been included in a release.

@dawranliou
Copy link
Contributor

Oh right. Agree, it never appeared in the Change Log.

@JosiahDub
Copy link
Contributor

This feature will be added in 7.0 or later.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants