contributing.md
This file
Path
docs/contributing.md
248 lines · 5.8 KiB · Markdown
Last changed by
🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
History of this fileTake it
The walk stopped after 200 commits: lines older than 8dd7642 point at it.
📝 Update release notesgithub-actionsbefore adoption8dd7642
lines 1–24why, one step back1First, you might want to see the basic ways to [help Typer and get help](help-typer.md){.internal-link target=_blank}.23## Developing45If you already cloned the repository and you know that you need to deep dive in the code, here are some guidelines to set up your environment.67### Virtual environment with `venv`89You can create a virtual environment in a directory using Python's `venv` module:1011<div class="termy">1213```console14$ python -m venv env15```1617</div>1819That will create a directory `./env/` with the Python binaries and then you will be able to install packages for that isolated environment.2021### Activate the environment2223Activate the new environment with:24🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 25why, one step back25//// tab | Linux, macOS📝 Update release notesgithub-actionsbefore adoption8dd7642
line 26why, one step back26🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 27why, one step back27<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 28why, one step back28🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 29–31why, one step back29```console30$ source ./env/bin/activate31```📝 Update release notesgithub-actionsbefore adoption8dd7642
line 32why, one step back32🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 33why, one step back33</div>📝 Update release notesgithub-actionsbefore adoption8dd7642
line 34why, one step back34🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 35why, one step back35////📝 Update release notesgithub-actionsbefore adoption8dd7642
line 36why, one step back36🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 37why, one step back37//// tab | Windows PowerShell📝 Update release notesgithub-actionsbefore adoption8dd7642
line 38why, one step back38🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 39why, one step back39<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 40why, one step back40🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 41–43why, one step back41```console42$ .\env\Scripts\Activate.ps143```📝 Update release notesgithub-actionsbefore adoption8dd7642
line 44why, one step back44🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 45why, one step back45</div>📝 Update release notesgithub-actionsbefore adoption8dd7642
line 46why, one step back46🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 47why, one step back47////📝 Update release notesgithub-actionsbefore adoption8dd7642
line 48why, one step back48🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 49why, one step back49//// tab | Windows Bash📝 Update release notesgithub-actionsbefore adoption8dd7642
line 50why, one step back50🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 51why, one step back51Or if you use Bash for Windows (e.g. <a href="https://gitforwindows.org/" class="external-link" target="_blank">Git Bash</a>):📝 Update release notesgithub-actionsbefore adoption8dd7642
line 52why, one step back52🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 53why, one step back53<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 54why, one step back54🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 55–62why, one step back55```console56$ source ./env/Scripts/activate57```5859</div>6061////62📝 Update release notesgithub-actionsbefore adoption8dd7642
lines 63–64why, one step back63To check it worked, use:64🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 65why, one step back65//// tab | Linux, macOS, Windows Bash📝 Update release notesgithub-actionsbefore adoption8dd7642
line 66why, one step back66🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 67why, one step back67<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 68why, one step back68🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 69–70why, one step back69```console70$ which pip📝 Update release notesgithub-actionsbefore adoption8dd7642
line 71why, one step back71🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 72–73why, one step back72some/directory/typer/env/bin/pip73```📝 Update release notesgithub-actionsbefore adoption8dd7642
line 74why, one step back74🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 75why, one step back75</div>📝 Update release notesgithub-actionsbefore adoption8dd7642
line 76why, one step back76🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 77why, one step back77////📝 Update release notesgithub-actionsbefore adoption8dd7642
line 78why, one step back78🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 79why, one step back79//// tab | Windows PowerShell📝 Update release notesgithub-actionsbefore adoption8dd7642
line 80why, one step back80🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 81why, one step back81<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 82why, one step back82🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 83–84why, one step back83```console84$ Get-Command pip📝 Update release notesgithub-actionsbefore adoption8dd7642
line 85why, one step back85🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 86–87why, one step back86some/directory/typer/env/bin/pip87```📝 Update release notesgithub-actionsbefore adoption8dd7642
line 88why, one step back88🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 89–92why, one step back89</div>9091////92📝 Update release notesgithub-actionsbefore adoption8dd7642
lines 93–94why, one step back93If it shows the `pip` binary at `env/bin/pip` then it worked. 🎉94🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 95why, one step back95/// tip📝 Update release notesgithub-actionsbefore adoption8dd7642
line 96why, one step back96🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 97why, one step back97Every time you install a new package with `pip` under that environment, activate the environment again.📝 Update release notesgithub-actionsbefore adoption8dd7642
line 98why, one step back98🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 99–102why, one step back99This makes sure that if you use a terminal program installed by that package (like `flit`), you use the one from your local environment and not any other that could be installed globally.100101///102📝 Update release notesgithub-actionsbefore adoption8dd7642
lines 103–122why, one step back103### Flit104105**Typer** uses <a href="https://flit.readthedocs.io/en/latest/index.html" class="external-link" target="_blank">Flit</a> to build, package and publish the project.106107After activating the environment as described above, install `flit`:108109<div class="termy">110111```console112$ pip install flit113114---> 100%115```116117</div>118119Now re-activate the environment to make sure you are using the `flit` you just installed (and not a global one).120121And now use `flit` to install the development dependencies:122🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 123why, one step back123//// tab | Linux, macOS📝 Update release notesgithub-actionsbefore adoption8dd7642
line 124why, one step back124🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 125why, one step back125<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 126why, one step back126🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 127–128why, one step back127```console128$ flit install --deps develop --symlink📝 Update release notesgithub-actionsbefore adoption8dd7642
line 129why, one step back129🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 130–131why, one step back130---> 100%131```📝 Update release notesgithub-actionsbefore adoption8dd7642
line 132why, one step back132🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 133why, one step back133</div>📝 Update release notesgithub-actionsbefore adoption8dd7642
line 134why, one step back134🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 135why, one step back135////📝 Update release notesgithub-actionsbefore adoption8dd7642
line 136why, one step back136🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 137why, one step back137//// tab | Windows📝 Update release notesgithub-actionsbefore adoption8dd7642
line 138why, one step back138🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 139why, one step back139If you are on Windows, use `--pth-file` instead of `--symlink`:📝 Update release notesgithub-actionsbefore adoption8dd7642
line 140why, one step back140🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 141why, one step back141<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 142why, one step back142🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 143–144why, one step back143```console144$ flit install --deps develop --pth-file📝 Update release notesgithub-actionsbefore adoption8dd7642
line 145why, one step back145🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 146–151why, one step back146---> 100%147```148149</div>150151////📝 Update release notesgithub-actionsbefore adoption8dd7642
lines 152–248why, one step back152153It will install all the dependencies and your local Typer in your local environment.154155#### Using your local Typer156157If you create a Python file that imports and uses Typer, and run it with the Python from your local environment, it will use your local Typer source code.158159And if you update that local Typer source code, as it is installed with `--symlink` (or `--pth-file` on Windows), when you run that Python file again, it will use the fresh version of Typer you just edited.160161That way, you don't have to "install" your local version to be able to test every change.162163### Format164165There is a script that you can run that will format and clean all your code:166167<div class="termy">168169```console170$ bash scripts/format.sh171```172173</div>174175It will also auto-sort all your imports.176177For it to sort them correctly, you need to have Typer installed locally in your environment, with the command in the section above using `--symlink` (or `--pth-file` on Windows).178179### Format imports180181There is another script that formats all the imports and makes sure you don't have unused imports:182183<div class="termy">184185```console186$ bash scripts/format-imports.sh187```188189</div>190191As it runs one command after the other and modifies and reverts many files, it takes a bit longer to run, so it might be easier to use `scripts/format.sh` frequently and `scripts/format-imports.sh` only before committing.192193## Docs194195The documentation uses <a href="https://www.mkdocs.org/" class="external-link" target="_blank">MkDocs</a>.196197All the documentation is in Markdown format in the directory `./docs`.198199Many of the tutorials have blocks of code.200201In most of the cases, these blocks of code are actual complete applications that can be run as is.202203In fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs_src/` directory.204205And those Python files are included/injected in the documentation when generating the site.206207### Docs for tests208209Most of the tests actually run against the example source files in the documentation.210211This helps making sure that:212213* The documentation is up to date.214* The documentation examples can be run as is.215* Most of the features are covered by the documentation, ensured by test coverage.216217During local development, there is a script that builds the site and checks for any changes, live-reloading:218219<div class="termy">220221```console222$ bash scripts/docs-live.sh223224<span style="color: green;">[INFO]</span> - Building documentation...225<span style="color: green;">[INFO]</span> - Cleaning site directory226<span style="color: green;">[INFO]</span> - Documentation built in 2.74 seconds227<span style="color: green;">[INFO]</span> - Serving on http://127.0.0.1:8008228```229230</div>231232It will serve the documentation on `http://127.0.0.1:8008`.233234That way, you can edit the documentation/source files and see the changes live.235236## Tests237238There is a script that you can run locally to test all the code and generate coverage reports in HTML:239240<div class="termy">241242```console243$ bash scripts/test-cov-html.sh244```245246</div>247248This 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.