Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than c030668 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 back
1# Development - Contributing
2

📝 Update release notesgithub-actionsbefore adoptionc030668

lines 3–26why, one step back
3First, 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 back
27//// tab | Linux, macOS

📝 Update release notesgithub-actionsbefore adoptionc030668

line 28why, one step back
28

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 29why, one step back
29<div class="termy">

📝 Update release notesgithub-actionsbefore adoptionc030668

line 30why, one step back
30

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 31–33why, one step back
31```console
32$ source ./env/bin/activate33```

📝 Update release notesgithub-actionsbefore adoptionc030668

line 34why, one step back
34

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 35why, one step back
35</div>

📝 Update release notesgithub-actionsbefore adoptionc030668

line 36why, one step back
36

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 37why, one step back
37////

📝 Update release notesgithub-actionsbefore adoptionc030668

line 38why, one step back
38

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 39why, one step back
39//// tab | Windows PowerShell

📝 Update release notesgithub-actionsbefore adoptionc030668

line 40why, one step back
40

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 41why, one step back
41<div class="termy">

📝 Update release notesgithub-actionsbefore adoptionc030668

line 42why, one step back
42

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 43–45why, one step back
43```console
44$ .\env\Scripts\Activate.ps145```

📝 Update release notesgithub-actionsbefore adoptionc030668

line 46why, one step back
46

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 47why, one step back
47</div>

📝 Update release notesgithub-actionsbefore adoptionc030668

line 48why, one step back
48

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 49why, one step back
49////

📝 Update release notesgithub-actionsbefore adoptionc030668

line 50why, one step back
50

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 51why, one step back
51//// tab | Windows Bash

📝 Update release notesgithub-actionsbefore adoptionc030668

line 52why, one step back
52

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 53why, one step back
53Or 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 adoptionc030668

line 54why, one step back
54

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 55why, one step back
55<div class="termy">

📝 Update release notesgithub-actionsbefore adoptionc030668

line 56why, one step back
56

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 57–64why, one step back
57```console
58$ source ./env/Scripts/activate59```6061</div>6263////64

📝 Update release notesgithub-actionsbefore adoptionc030668

lines 65–66why, one step back
65To 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 back
67//// tab | Linux, macOS, Windows Bash

📝 Update release notesgithub-actionsbefore adoptionc030668

line 68why, one step back
68

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 69why, one step back
69<div class="termy">

📝 Update release notesgithub-actionsbefore adoptionc030668

line 70why, one step back
70

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 71–72why, one step back
71```console
72$ which pip

📝 Update release notesgithub-actionsbefore adoptionc030668

line 73why, one step back
73

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 74–75why, one step back
74some/directory/typer/env/bin/pip
75```

📝 Update release notesgithub-actionsbefore adoptionc030668

line 76why, one step back
76

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 77why, one step back
77</div>

📝 Update release notesgithub-actionsbefore adoptionc030668

line 78why, one step back
78

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 79why, one step back
79////

📝 Update release notesgithub-actionsbefore adoptionc030668

line 80why, one step back
80

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 81why, one step back
81//// tab | Windows PowerShell

📝 Update release notesgithub-actionsbefore adoptionc030668

line 82why, one step back
82

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 83why, one step back
83<div class="termy">

📝 Update release notesgithub-actionsbefore adoptionc030668

line 84why, one step back
84

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 85–86why, one step back
85```console
86$ Get-Command pip

📝 Update release notesgithub-actionsbefore adoptionc030668

line 87why, one step back
87

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 88–89why, one step back
88some/directory/typer/env/bin/pip
89```

📝 Update release notesgithub-actionsbefore adoptionc030668

line 90why, one step back
90

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 91–94why, one step back
91</div>
9293////94

📝 Update release notesgithub-actionsbefore adoptionc030668

lines 95–96why, one step back
95If 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 back
97/// tip

📝 Update release notesgithub-actionsbefore adoptionc030668

line 98why, one step back
98

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 99why, one step back
99Every time you install a new package with `pip` under that environment, activate the environment again.

📝 Update release notesgithub-actionsbefore adoptionc030668

line 100why, one step back
100

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 101–104why, one step back
101This 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 adoptionc030668

lines 105–124why, one step back
105### Flit
106107**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 back
125//// tab | Linux, macOS

📝 Update release notesgithub-actionsbefore adoptionc030668

line 126why, one step back
126

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 127why, one step back
127<div class="termy">

📝 Update release notesgithub-actionsbefore adoptionc030668

line 128why, one step back
128

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 129–130why, one step back
129```console
130$ flit install --deps develop --symlink

📝 Update release notesgithub-actionsbefore adoptionc030668

line 131why, one step back
131

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 132–133why, one step back
132---> 100%
133```

📝 Update release notesgithub-actionsbefore adoptionc030668

line 134why, one step back
134

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 135why, one step back
135</div>

📝 Update release notesgithub-actionsbefore adoptionc030668

line 136why, one step back
136

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 137why, one step back
137////

📝 Update release notesgithub-actionsbefore adoptionc030668

line 138why, one step back
138

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 139why, one step back
139//// tab | Windows

📝 Update release notesgithub-actionsbefore adoptionc030668

line 140why, one step back
140

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 141why, one step back
141If you are on Windows, use `--pth-file` instead of `--symlink`:

📝 Update release notesgithub-actionsbefore adoptionc030668

line 142why, one step back
142

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

line 143why, one step back
143<div class="termy">

📝 Update release notesgithub-actionsbefore adoptionc030668

line 144why, one step back
144

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 145–146why, one step back
145```console
146$ flit install --deps develop --pth-file

📝 Update release notesgithub-actionsbefore adoptionc030668

line 147why, one step back
147

🔧 Update tabs and admonitions with new syntax and new MkDocs features (#906)Sebastián Ramírezbefore adoption289b230

lines 148–153why, one step back
148---> 100%
149```150151</div>152153////

📝 Update release notesgithub-actionsbefore adoptionc030668

lines 154–250why, one step back
154
155It 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.