contributing.md
This file
Path
docs/contributing.md
231 lines · 5.8 KiB · Markdown
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 83bf2fc point at it.
📝 Update release notesgithub-actionsbefore adoption83bf2fc
lines 1–231why, 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:2425=== "Linux, macOS"2627 <div class="termy">2829 ```console30 $ source ./env/bin/activate31 ```3233 </div>3435=== "Windows PowerShell"3637 <div class="termy">3839 ```console40 $ .\env\Scripts\Activate.ps141 ```4243 </div>4445=== "Windows Bash"4647 Or if you use Bash for Windows (e.g. <a href="https://gitforwindows.org/" class="external-link" target="_blank">Git Bash</a>):4849 <div class="termy">5051 ```console52 $ source ./env/Scripts/activate53 ```5455 </div>5657To check it worked, use:5859=== "Linux, macOS, Windows Bash"6061 <div class="termy">6263 ```console64 $ which pip6566 some/directory/typer/env/bin/pip67 ```6869 </div>7071=== "Windows PowerShell"7273 <div class="termy">7475 ```console76 $ Get-Command pip7778 some/directory/typer/env/bin/pip79 ```8081 </div>8283If it shows the `pip` binary at `env/bin/pip` then it worked. 🎉8485!!! tip86 Every time you install a new package with `pip` under that environment, activate the environment again.8788 This 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.8990### Flit9192**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.9394After activating the environment as described above, install `flit`:9596<div class="termy">9798```console99$ pip install flit100101---> 100%102```103104</div>105106Now re-activate the environment to make sure you are using the `flit` you just installed (and not a global one).107108And now use `flit` to install the development dependencies:109110=== "Linux, macOS"111112 <div class="termy">113114 ```console115 $ flit install --deps develop --symlink116117 ---> 100%118 ```119120 </div>121122=== "Windows"123124 If you are on Windows, use `--pth-file` instead of `--symlink`:125126 <div class="termy">127128 ```console129 $ flit install --deps develop --pth-file130131 ---> 100%132 ```133134 </div>135136It will install all the dependencies and your local Typer in your local environment.137138#### Using your local Typer139140If 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.141142And 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.143144That way, you don't have to "install" your local version to be able to test every change.145146### Format147148There is a script that you can run that will format and clean all your code:149150<div class="termy">151152```console153$ bash scripts/format.sh154```155156</div>157158It will also auto-sort all your imports.159160For 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).161162### Format imports163164There is another script that formats all the imports and makes sure you don't have unused imports:165166<div class="termy">167168```console169$ bash scripts/format-imports.sh170```171172</div>173174As 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.175176## Docs177178The documentation uses <a href="https://www.mkdocs.org/" class="external-link" target="_blank">MkDocs</a>.179180All the documentation is in Markdown format in the directory `./docs`.181182Many of the tutorials have blocks of code.183184In most of the cases, these blocks of code are actual complete applications that can be run as is.185186In fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs_src/` directory.187188And those Python files are included/injected in the documentation when generating the site.189190### Docs for tests191192Most of the tests actually run against the example source files in the documentation.193194This helps making sure that:195196* The documentation is up to date.197* The documentation examples can be run as is.198* Most of the features are covered by the documentation, ensured by test coverage.199200During local development, there is a script that builds the site and checks for any changes, live-reloading:201202<div class="termy">203204```console205$ bash scripts/docs-live.sh206207<span style="color: green;">[INFO]</span> - Building documentation...208<span style="color: green;">[INFO]</span> - Cleaning site directory209<span style="color: green;">[INFO]</span> - Documentation built in 2.74 seconds210<span style="color: green;">[INFO]</span> - Serving on http://127.0.0.1:8008211```212213</div>214215It will serve the documentation on `http://127.0.0.1:8008`.216217That way, you can edit the documentation/source files and see the changes live.218219## Tests220221There is a script that you can run locally to test all the code and generate coverage reports in HTML:222223<div class="termy">224225```console226$ bash scripts/test-cov-html.sh227```228229</div>230231This 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.