Skip to content
Myr

contributing.md

This file

Path

docs/contributing.md

337 lines · 9.1 KiB · Markdown

Last changed by

📝 Add contribution instructions about LLM generated code and comments and automated tools for PRs (#1489)Alejandrabefore adoption1dadfa0

History of this file

Take it

The walk stopped after 200 commits: lines older than 9b3857b point at it.

⬆ Update pytest-cov requirement from <7.0.0,>=2.10.0 to >=2.10.0,<8.0.0 (#1301)dependabot[bot]before adoption9b3857b

lines 1–8why, one step back
1# Development - Contributing
23First, you might want to see the basic ways to [help Typer and get help](help-typer.md){.internal-link target=_blank}.45## Developing67If you already cloned the <a href="https://github.com/fastapi/typer" class="external-link" target="_blank">typer repository</a> and you want to deep dive in the code, here are some guidelines to set up your environment.8

⬆️ Migrate to uv (#1472)Jonathan Ehwaldbefore adoption39353af

line 9why, one step back
9### Install Requirements Using `uv`

⬆ Update pytest-cov requirement from <7.0.0,>=2.10.0 to >=2.10.0,<8.0.0 (#1301)dependabot[bot]before adoption9b3857b

line 10why, one step back
10

⬆️ Migrate to uv (#1472)Jonathan Ehwaldbefore adoption39353af

line 11why, one step back
11Create a virtual environment and install the required packages in one command:

⬆ Update pytest-cov requirement from <7.0.0,>=2.10.0 to >=2.10.0,<8.0.0 (#1301)dependabot[bot]before adoption9b3857b

lines 12–15why, one step back
12
13<div class="termy">1415```console

⬆️ Migrate to uv (#1472)Jonathan Ehwaldbefore adoption39353af

line 16why, one step back
16$ uv sync

⬆ Update pytest-cov requirement from <7.0.0,>=2.10.0 to >=2.10.0,<8.0.0 (#1301)dependabot[bot]before adoption9b3857b

lines 17–301why, one step back
17
18---> 100%19```2021</div>2223It will install all the dependencies and your local Typer in your local environment.2425### Using your Local Typer2627If you create a Python file that imports and uses Typer, and run it with the Python from your local environment, it will use your cloned local Typer source code.2829And if you update that local Typer source code when you run that Python file again, it will use the fresh version of Typer you just edited.3031That way, you don't have to "install" your local version to be able to test every change.3233/// note | "Technical Details"3435This only happens when you install using this included `requirements.txt` instead of running `pip install typer` directly.3637That is because inside the `requirements.txt` file, the local version of Typer is marked to be installed in "editable" mode, with the `-e` option.3839///4041### Format4243There is a script that you can run that will format and clean all your code:4445<div class="termy">4647```console48$ bash scripts/format.sh49```5051</div>5253It will also auto-sort all your imports.5455## Tests5657There is a script that you can run locally to test all the code and generate coverage reports in HTML:5859<div class="termy">6061```console62$ bash scripts/test-cov-html.sh63```6465</div>6667This command generates a directory `./htmlcov/`, if you open the file `./htmlcov/index.html` in your browser, you can explore interactively the regions of code that are covered by the tests, and notice if there is any region missing.6869## Completion7071To try and test the completion for different shells and check that they are working you can use a Docker container.7273There's a `Dockerfile` and a Docker Compose file `compose.yaml` at `./scripts/docker/`.7475It has installed `bash`, `zsh`, `fish`, and `pwsh` (PowerShell for Linux).7677It also has installed `nano` and `vim`, so that you can check the modified configuration files for the shells (for example `.bashrc`, `.zshrc`, etc).7879It also has `uv` installed, so you can install the dependencies and the project quickly.8081The Docker Compose file mounts the main directory as `/code` inside the container, so you can change things and try them out.8283Go to the `./scripts/docker/` directory:8485```console86$ cd scripts/docker/87```8889Then run an interactive session with `bash` inside the container:9091```console92$ docker compose run typer bash9394root@79c4b9b70cbe:/code#95```9697Then inside the container, you can install `typer` with:9899```console100$ uv pip install -r requirements.txt101```102103Then, you can start the shell you want to use, the one where you want to try out completion:104105* `bash`106* `fish`107* `pwsh`108* `zsh`109110For example:111112```console113$ zsh114```115116Then install `typer` completion:117118```console119$ typer --install-completion120```121122/// info123124In `pwsh` you will probably get a warning of:125126```plaintext127Set-ExecutionPolicy: Operation is not supported on this platform.128```129130this is because that configuration is only available in Windows (and needed there), not in PowerShell for Linux.131132///133134For completion to take effect, you need to restart the shell. So, exit the current shell:135136```console137$ exit138```139140and start a new shell (for the same shell you installed completion in) again. For example:141142```console143$ zsh144```145146Now you could create a demo file on the same Typer directory in your editor, for example `demo.py`:147148```python149import typer150151app = typer.Typer()152153154@app.command()155def hello():156 print("Hello")157158159@app.command()160def goodbye():161 print("Goodbye")162163164if __name__ == "__main__":165 app()166```167168Because the directory is mounted as a volume, you will be able to access the file from inside the container.169170So, you can try running it with the `typer` command, that will use the installed shell completion:171172```console173$ typer demo.py <TAB>174```175176And you should see the completion working:177178```console179run -- Run the provided Typer app.180utils -- Extra utility commands for Typer apps.181```182183And the same for the commands in your `demo.py` file:184185```console186$ typer demo.py run <TAB>187188hello goodbye189```190191You can also check the configuration file using `nano` or `vim`, for example:192193```bash194nano ~/.zshrc195```196197It will show some content like:198199```bash200fpath+=~/.zfunc; autoload -Uz compinit; compinit201202203zstyle ':completion:*' menu select204```205206If you exit from the container, you can start a new one, you will probably have to install the packages again and install completion again.207208Using 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.209210## Docs211212First, make sure you set up your environment as described above, that will install all the requirements.213214### Docs live215216During local development, there is a script that builds the site and checks for any changes, live-reloading:217218<div class="termy">219220```console221$ python ./scripts/docs.py live222223<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008224<span style="color: green;">[INFO]</span> Start watching changes225<span style="color: green;">[INFO]</span> Start detecting changes226```227228</div>229230It will serve the documentation on `http://127.0.0.1:8008`.231232That way, you can edit the documentation/source files and see the changes live.233234/// tip235236Alternatively, you can perform the same steps that script does manually.237238Go into the docs directory at `docs/`:239240```console241$ cd docs/242```243244Then run `mkdocs` in that directory:245246```console247$ mkdocs serve --dev-addr 8008248```249250///251252#### Typer CLI (optional)253254The instructions here show you how to use the script at `./scripts/docs.py` with the `python` program directly.255256But you can also use <a href="https://typer.tiangolo.com/typer-cli/" class="external-link" target="_blank">Typer CLI</a>, and you will get autocompletion in your terminal for the commands after installing completion.257258If you install Typer CLI, you can install completion with:259260<div class="termy">261262```console263$ typer --install-completion264265zsh completion installed in /home/user/.bashrc.266Completion will take effect once you restart the terminal.267```268269</div>270271### Docs Structure272273The documentation uses <a href="https://www.mkdocs.org/" class="external-link" target="_blank">MkDocs</a>.274275And there are extra tools/scripts in place in `./scripts/docs.py`.276277/// tip278279You don't need to see the code in `./scripts/docs.py`, you just use it in the command line.280281///282283All the documentation is in Markdown format in the directory `./docs`.284285Many of the tutorials have blocks of code.286287In most of the cases, these blocks of code are actual complete applications that can be run as is.288289In fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs_src/` directory.290291And those Python files are included/injected in the documentation when generating the site.292293### Docs for Tests294295Most of the tests actually run against the example source files in the documentation.296297This helps to make sure that:298299* The documentation is up-to-date.300* The documentation examples can be run as is.301* Most of the features are covered by the documentation, ensured by test coverage.

📝 Add contribution instructions about LLM generated code and comments and automated tools for PRs (#1489)Alejandrabefore adoption1dadfa0

lines 302–337why, one step back
302
303## Automated Code and AI304305You are encouraged to use all the tools you want to do your work and contribute as efficiently as possible, this includes AI (LLM) tools, etc. Nevertheless, contributions should have meaningful human intervention, judgement, context, etc.306307If the **human effort** put in a PR, e.g. writing LLM prompts, is **less** than the **effort we would need to put** to **review it**, please **don't** submit the PR.308309Think of it this way: we can already write LLM prompts or run automated tools ourselves, and that would be faster than reviewing external PRs.310311### Closing Automated and AI PRs312313If we see PRs that seem AI generated or automated in similar ways, we'll flag them and close them.314315The same applies to comments and descriptions, please don't copy paste the content generated by an LLM.316317### Human Effort Denial of Service318319Using automated tools and AI to submit PRs or comments that we have to carefully review and handle would be the equivalent of a <a href="https://en.wikipedia.org/wiki/Denial-of-service_attack" class="external-link" target="_blank">Denial-of-service attack</a> on our human effort.320321It would be very little effort from the person submitting the PR (an LLM prompt) that generates a large amount of effort on our side (carefully reviewing code).322323Please don't do that.324325We'll need to block accounts that spam us with repeated automated PRs or comments.326327### Use Tools Wisely328329As Uncle Ben said:330331<blockquote>332With great <strike>power</strike> <strong>tools</strong> comes great responsibility.333</blockquote>334335Avoid inadvertently doing harm.336337You have amazing tools at hand, use them wisely to help effectively.