kislyuk / argcomplete

Python and tab completion, better together.
https://kislyuk.github.io/argcomplete/
Apache License 2.0
1.4k stars 133 forks source link

Automatically run activate-global-python-argcomplete #127

Open sedrubal opened 8 years ago

sedrubal commented 8 years ago

It's very nasty to manually run activate-global-python-argcomplete. Is it possible to run this automatically on installing the pypi package or the distro (apt, dnf) package?

kislyuk commented 8 years ago

Thanks for reporting. This is ultimately not the Python package's choice to make. When running install through setuptools, a Python package generally doesn't know where its installation destination is, whether it's being sandboxed in a virtualenv, where the relevant bash-completion installation is, whether installing a global completion hook will trample on another copy of the package, etc.

Conversely, APT (and other system-wide package managers) is in the business of knowing all these things and is in a position to install the global completion hook.

So, please make this request with the distro package maintainers. I'm currently not directly involved in that.

irl commented 7 years ago

I just made a non-maintainer upload for python-argcomplete in Debian as I noticed it was quite outdated.

I'm interested in what you would think would be a good way in which APT might globally enable. I know we have a /etc/bash_completion.d folder but I really have no idea how any of this works.

kislyuk commented 7 years ago

@irl, glad to hear the Debian packagers want to update this. I think it's reasonable to run activate-global-python-argcomplete from postinst. This installs https://github.com/kislyuk/argcomplete/blob/master/argcomplete/bash_completion.d/python-argcomplete.sh into /etc/bash_completion.d/.

irl commented 7 years ago

Ok, I think it's reasonable to install this into the package, from the policy I can't see anything that needs this to happen in a postinst. Are any other shells supported? Are there other files that I can install at the same time that would be useful?

kislyuk commented 7 years ago

At this time other shells are not officially supported.

People have had success running this in zsh, largely because zsh has a compatibility layer for bash completion scripts, but I don't know exactly what needs to be done to activate argcomplete in zsh (at least as of last year someone told me the argcomplete global completion feature doesn't work in zsh at all).

I don't have any other files to install. I could probably come up with a way to use pandoc to generate a man page from the docs, so man argcomplete would work. Is that useful?

irl commented 7 years ago

Binaries without manpages is a bug in Debian, not having a man page for a library isn't a problem. I just wondered if you had files for zsh, etc. hanging around. I'll have to look into this in the future, as I do use zsh, but I don't have time for now.

I'll update this bug once I've done a new upload to Debian automatically installing the file in /etc.

Evidlo commented 5 years ago

It might be nice to provide argcomplete.activate_global_argcomplete so that packages using argcomplete can automatically enable completion if they desire.

kislyuk commented 1 year ago

Update: zsh is now officially supported, in addition to bash.

stefanor commented 9 months ago

I think it's reasonable to run activate-global-python-argcomplete from postinst.

Debian person here. I don't think that's a great solution, shipping static files is usually preferable to running things in postinst.

What's complicated here is that the only place this can be installed is in /etc/bash_completion.d , in /etc/ which means it has special rules around it. Files here may be edited by a sysadmin, and often persist after a package is uninstalled. If there was somewhere in /usr/share/bash_completion to put it, that'd probably be preferable, but there isn't...

I've proposed to install a thin loader shim script in /etc/bash_completion.d: https://salsa.debian.org/python-team/packages/python-argcomplete/-/commit/a8529eb27976da8e5687c5b43295e74e3c8de49b

See some related discussion in https://bugs.debian.org/944469