contributing.md
This file
Path
docs/contributing.md
250 lines · 5.8 KiB · Markdown
Last changed by
🔧 Update MkDocs to have titles in Markdown files instead of config (#913)Sebastián Ramírezbefore adoption6b264ac
History of this fileTake it
The walk stopped after 200 commits: lines older than 8dd7642 point at it.
🔧 Update MkDocs to have titles in Markdown files instead of config (#913)Sebastián Ramírezbefore adoption6b264ac
lines 1–2why, one step back1# Development - Contributing2📝 Update release notesgithub-actionsbefore adoption8dd7642
lines 3–26why, one step back3First, 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 repository and you know that you need to deep dive in the code, here are some guidelines to set up your environment.89### Virtual environment with `venv`1011You can create a virtual environment in a directory using Python's `venv` module:1213<div class="termy">1415```console16$ python -m venv env17```1819</div>2021That will create a directory `./env/` with the Python binaries and then you will be able to install packages for that isolated environment.2223### Activate the environment2425Activate the new environment with:26🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 27why, one step back27//// tab | Linux, macOS📝 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
line 29why, one step back29<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 30why, one step back30🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 31–33why, one step back31```console32$ source ./env/bin/activate33```📝 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</div>📝 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////📝 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//// tab | Windows PowerShell📝 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
line 41why, one step back41<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 42why, one step back42🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 43–45why, one step back43```console44$ .\env\Scripts\Activate.ps145```📝 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</div>📝 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////📝 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 back51//// tab | Windows Bash📝 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 back53Or 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 54why, one step back54🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 55why, one step back55<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 56why, one step back56🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 57–64why, one step back57```console58$ source ./env/Scripts/activate59```6061</div>6263////64📝 Update release notesgithub-actionsbefore adoption8dd7642
lines 65–66why, one step back65To check it worked, use:66🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 67why, one step back67//// tab | Linux, macOS, Windows Bash📝 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
line 69why, one step back69<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 70why, one step back70🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 71–72why, one step back71```console72$ which pip📝 Update release notesgithub-actionsbefore adoption8dd7642
line 73why, one step back73🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 74–75why, one step back74some/directory/typer/env/bin/pip75```📝 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</div>📝 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////📝 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//// tab | Windows PowerShell📝 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
line 83why, one step back83<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 84why, one step back84🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 85–86why, one step back85```console86$ Get-Command pip📝 Update release notesgithub-actionsbefore adoption8dd7642
line 87why, one step back87🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 88–89why, one step back88some/directory/typer/env/bin/pip89```📝 Update release notesgithub-actionsbefore adoption8dd7642
line 90why, one step back90🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 91–94why, one step back91</div>9293////94📝 Update release notesgithub-actionsbefore adoption8dd7642
lines 95–96why, one step back95If it shows the `pip` binary at `env/bin/pip` then it worked. 🎉96🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 97why, one step back97/// tip📝 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
line 99why, one step back99Every time you install a new package with `pip` under that environment, activate the environment again.📝 Update release notesgithub-actionsbefore adoption8dd7642
line 100why, one step back100🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 101–104why, one step back101This 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.102103///104📝 Update release notesgithub-actionsbefore adoption8dd7642
lines 105–124why, one step back105### Flit106107**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.108109After activating the environment as described above, install `flit`:110111<div class="termy">112113```console114$ pip install flit115116---> 100%117```118119</div>120121Now re-activate the environment to make sure you are using the `flit` you just installed (and not a global one).122123And now use `flit` to install the development dependencies:124🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
line 125why, one step back125//// tab | Linux, macOS📝 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
line 127why, one step back127<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 128why, one step back128🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 129–130why, one step back129```console130$ flit install --deps develop --symlink📝 Update release notesgithub-actionsbefore adoption8dd7642
line 131why, one step back131🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 132–133why, one step back132---> 100%133```📝 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</div>📝 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////📝 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 back139//// tab | Windows📝 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 back141If you are on Windows, use `--pth-file` instead of `--symlink`:📝 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
line 143why, one step back143<div class="termy">📝 Update release notesgithub-actionsbefore adoption8dd7642
line 144why, one step back144🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 145–146why, one step back145```console146$ flit install --deps develop --pth-file📝 Update release notesgithub-actionsbefore adoption8dd7642
line 147why, one step back147🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230
lines 148–153why, one step back148---> 100%149```150151</div>152153////📝 Update release notesgithub-actionsbefore adoption8dd7642
lines 154–250why, one step back154155It will install all the dependencies and your local Typer in your local environment.156157#### Using your local Typer158159If 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.160161And 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.162163That way, you don't have to "install" your local version to be able to test every change.164165### Format166167There is a script that you can run that will format and clean all your code:168169<div class="termy">170171```console172$ bash scripts/format.sh173```174175</div>176177It will also auto-sort all your imports.178179For 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).180181### Format imports182183There is another script that formats all the imports and makes sure you don't have unused imports:184185<div class="termy">186187```console188$ bash scripts/format-imports.sh189```190191</div>192193As 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.194195## Docs196197The documentation uses <a href="https://www.mkdocs.org/" class="external-link" target="_blank">MkDocs</a>.198199All the documentation is in Markdown format in the directory `./docs`.200201Many of the tutorials have blocks of code.202203In most of the cases, these blocks of code are actual complete applications that can be run as is.204205In fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs_src/` directory.206207And those Python files are included/injected in the documentation when generating the site.208209### Docs for tests210211Most of the tests actually run against the example source files in the documentation.212213This helps making sure that:214215* The documentation is up to date.216* The documentation examples can be run as is.217* Most of the features are covered by the documentation, ensured by test coverage.218219During local development, there is a script that builds the site and checks for any changes, live-reloading:220221<div class="termy">222223```console224$ bash scripts/docs-live.sh225226<span style="color: green;">[INFO]</span> - Building documentation...227<span style="color: green;">[INFO]</span> - Cleaning site directory228<span style="color: green;">[INFO]</span> - Documentation built in 2.74 seconds229<span style="color: green;">[INFO]</span> - Serving on http://127.0.0.1:8008230```231232</div>233234It will serve the documentation on `http://127.0.0.1:8008`.235236That way, you can edit the documentation/source files and see the changes live.237238## Tests239240There is a script that you can run locally to test all the code and generate coverage reports in HTML:241242<div class="termy">243244```console245$ bash scripts/test-cov-html.sh246```247248</div>249250This 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.