Skip to content
Myr

Doc Update Resolving Issue #2206

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Update CONTRIBUTING.rst with latest Click version - Add entry_points specification URL - Clarify shell completion description

authored by J Tan · committed by J Tan · parent b54eb6e · Browse files · 4 files+28 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+28 added−15 removed

  • other:+28 added−15 removed

4 files+28 added−15 removed

modified:docs/setuptools.rst+6 added-4 removed
79 unmodified lines
80 ],81 },82 )8384The magic is in the ``entry_points`` parameter. Below85``console_scripts``, each line identifies one console script. The first86part before the equals sign (``=``) is the name of the script that should87be generated, the second part is the import path followed by a colon84The magic is in the ``entry_points`` parameter. Read the full85`entry_points <https://packaging.python.org/en/latest/specifications/entry-points/>`_86specification for more details. Below ``console_scripts``, each87line identifies one console script. The first part before the88equals sign (``=``) is the name of the script that should be89generated, the second part is the import path followed by a colon90(``:``) with the Click command.9192That's it.93
62 unmodified lines
modified:docs/shell-completion.rst+14 added-10 removed
26 unmodified lines
27through an entry point, not through the ``python`` command. See28:doc:`/setuptools`. Once the executable is installed, calling it with29a special environment variable will put Click in completion mode.3031In order for completion to be used, the user needs to register a special32function with their shell. The script is different for every shell, and33Click will output it when called with ``_{PROG_NAME}_COMPLETE`` set to34``{shell}_source``. ``{PROG_NAME}`` is the executable name in uppercase35with dashes replaced by underscores. The built-in shells are ``bash``,36``zsh``, and ``fish``.31To enable shell completion, the user needs to register a special32function with their shell. The exact script varies depending on the33shell you are using. Click will output it when called with34``_{FOO_BAR}_COMPLETE`` set to ``{shell}_source``. ``{FOO_BAR}`` is35the executable name in uppercase with dashes replaced by underscores.36It is conventional but not strictly required for environment variable37names to be in upper case. This convention helps distinguish environment38variables from regular shell variables and commands, making scripts39and configuration files more readable and easier to maintain. The40built-in shells are ``bash``, ``zsh``, and ``fish``.4142Provide your users with the following instructions customized to your43program name. This uses ``foo-bar`` as an example.44
152 unmodified lines
197require implementing some smaller parts.198199First, you'll need to figure out how your shell's completion system200works and write a script to integrate it with Click. It must invoke your197program with the environment variable ``_{PROG_NAME}_COMPLETE`` set to201program with the environment variable ``_{FOO_BAR}_COMPLETE`` set to202``{shell}_complete`` and pass the complete args and incomplete value.203How it passes those values, and the format of the completion response204from Click is up to you.205
4 unmodified lines
210- ``complete_func`` - A safe name for the completion function defined211 in the script.212- ``complete_var`` - The environment variable name for passing the213 ``{shell}_complete`` instruction.210- ``prog_name`` - The name of the executable being completed.214- ``foo_bar`` - The name of the executable being completed.215216The example code is for a made up shell "My Shell" or "mysh" for short.217218.. code-block:: python
2 unmodified lines
221 from click.shell_completion import ShellComplete222223 _mysh_source = """\224 %(complete_func)s {221 response=$(%(complete_var)s=mysh_complete %(prog_name)s)225 response=$(%(complete_var)s=mysh_complete %(foo_bar)s)226 # parse response and set completions somehow227 }224 call-on-complete %(prog_name)s %(complete_func)s228 call-on-complete %(foo_bar)s %(complete_func)s229 """230231 @add_completion_class232 class MyshComplete(ShellComplete):
59 unmodified lines
modified:CHANGES.rst+7 added
1.. currentmodule:: click23Version 8.1.84-------------56Unreleased78- Fix an issue with type hints for ``click.open_file()``. :issue:`2717`910Version 8.1.711-------------1213Released 2023-08-17
1100 unmodified lines
modified:CONTRIBUTING.rst+1 added-1 removed
142 unmodified lines
143144 .. code-block:: text145146 $ git fetch origin147 $ git checkout -b your-branch-name origin/8.0.x147 $ git checkout -b your-branch-name origin/8.1.x148149 If you're submitting a feature addition or change, branch off of the150 "main" branch.151
71 unmodified lines