jaraco / keyring

MIT License
1.24k stars 152 forks source link

25.1.0: generate completion files without installed `keyring` now fails #675

Open kloczek opened 4 months ago

kloczek commented 4 months ago

Describe the bug Up to now as possible to generate completion files without installing keyring after build by

for sh in bash zsh; do
        PYTHONPATH=$PWD/build/lib \
        python3 -m keyring --print-completion ${sh} > keyring.${sh}
done

Now above fails with

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILD/keyring-25.1.0/build/lib
+ /usr/bin/python3 -m keyring --print-completion bash
Install keyring[completion] for completion support.

It was especially useful on packaging.

BTW: Currently code generating those completion files is part od the installed by modules files. If it not would be better to remove that code and maintain just static completion files? 🤔

jaraco commented 4 months ago

In #671 - and the 25.0.1 release (and subsequent 25.1.10 release), keyring was enhanced to return a non-zero exit status if completion generation was failing. It has always required the [completion] extra. Prior to 25.0.1, if you'd executed that command but the requisite dependencies weren't present, you'd get the error message in your keyring.{sh} file (and you probably were). It's probably the case that when the completion was run before, shtab happened to be installed, but along the way, shtab was removed causing the generation to fail quietly.

You should make sure that the dependencies declared in the completion extra are present (currently shtab).

BTW: Currently code generating those completion files is part od the installed by modules files. If it not would be better to remove that code and maintain just static completion files? 🤔

I'm not sure the best practice here. I'd like for the completion files to be derived from the implementation, as the --print-completion tool generates. I'd like to avoid creating a manual process that could cause the completion files to become out of sync with the implementation. I'd also be a little reluctant to add another build step to the keyring build process, mainly because I'm not aware of any good way to have Python generate artifacts during the build, though I wouldn't be opposed to some build-time generation in theory.

kloczek commented 4 months ago

I'm not sure the best practice here. I'd like for the completion files to be derived from the implementation, as the --print-completion tool generates. I'd like to avoid creating a manual process that could cause the completion files to become out of sync with the implementation. I'd also be a little reluctant to add another build step to the keyring build process, mainly because I'm not aware of any good way to have Python generate artifacts during the build, though I wouldn't be opposed to some build-time generation in theory.

Generally speaking I'm not against generate completion files however IMO those files/scripts used to generate completion files should not be installed.