Development - Contributing¶
First, you might want to see the basic ways to help Typer and get help.
Developing¶
To contribute code to the project, please follow the guidelines in tiangolo.com - Contributing.
Completion¶
To try and test the completion for different shells and check that they are working you can use a Docker container.
There's a Dockerfile and a Docker Compose file compose.yaml at ./scripts/docker/.
It has installed bash, zsh, fish, and pwsh (PowerShell for Linux).
It also has installed nano and vim, so that you can check the modified configuration files for the shells (for example .bashrc, .zshrc, etc).
It also has uv installed, so you can install the dependencies and the project quickly.
The Docker Compose file mounts the main directory as /code inside the container, so you can change things and try them out.
Go to the ./scripts/docker/ directory:
$ cd scripts/docker/
Then run an interactive session with bash inside the container:
$ docker compose run typer bash
root@79c4b9b70cbe:/code#
Then inside the container, you can install typer with:
$ uv pip install -r requirements.txt
Then, you can start the shell you want to use, the one where you want to try out completion:
bashfishpwshzsh
For example:
$ zsh
Then install typer completion:
$ typer --install-completion
Note
In pwsh you will probably get a warning of:
Set-ExecutionPolicy: Operation is not supported on this platform.
this is because that configuration is only available in Windows (and needed there), not in PowerShell for Linux.
For completion to take effect, you need to restart the shell. So, exit the current shell:
$ exit
and start a new shell (for the same shell you installed completion in) again. For example:
$ zsh
Now you could create a demo file on the same Typer directory in your editor, for example demo.py:
import typer
app = typer.Typer()
@app.command()
def hello():
print("Hello")
@app.command()
def goodbye():
print("Goodbye")
if __name__ == "__main__":
app()
Because the directory is mounted as a volume, you will be able to access the file from inside the container.
So, you can try running it with the typer command, that will use the installed shell completion:
$ typer demo.py <TAB>
And you should see the completion working:
run -- Run the provided Typer app.
utils -- Extra utility commands for Typer apps.
And the same for the commands in your demo.py file:
$ typer demo.py run <TAB>
hello goodbye
You can also check the configuration file using nano or vim, for example:
nano ~/.zshrc
It will show some content like:
fpath+=~/.zfunc; autoload -Uz compinit; compinit
zstyle ':completion:*' menu select
If you exit from the container, you can start a new one, you will probably have to install the packages again and install completion again.
Using this process, you can test all the shells, with their completions, being able to start from scratch quickly in a fresh container, and verifying that everything works as expected.