Skip to content
Myr

contributing.md

This file

Path

docs/contributing.md

231 lines · 5.8 KiB · Markdown

Last changed by

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

History of this file

Take it

:memo: Refactor docs with internal links #38Sebastián Ramírezbefore adoption8d6b201

line 1why, one step back
1First, you might want to see the basic ways to [help Typer and get help](help-typer.md){.internal-link target=_blank}.

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 2why, one step back
2

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 3why, one step back
3## Developing

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 4–6why, one step back
4
5If 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.6

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 7why, one step back
7### Virtual environment with `venv`

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 8why, one step back
8

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 9why, one step back
9You can create a virtual environment in a directory using Python's `venv` module:

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 10why, one step back
10

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 11–12why, one step back
11<div class="termy">
12

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 13–15why, one step back
13```console
14$ python -m venv env15```

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 16why, one step back
16

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 17–18why, one step back
17</div>
18

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 19–24why, one step back
19That 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

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 25–26why, one step back
25<div class="termy">
26

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 27–28why, one step back
27```console
28$ source ./env/bin/activate

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 29–30why, one step back
29```
30

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 31–32why, one step back
31</div>
32

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 33why, one step back
33Or in Windows' PowerShell:

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 34why, one step back
34

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 35–36why, one step back
35<div class="termy">
36

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 37–38why, one step back
37```console
38$ .\env\Scripts\Activate.ps1

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 39–40why, one step back
39```
40

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 41–42why, one step back
41</div>
42

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 43why, one step back
43Or if you use Bash for Windows (e.g. <a href="https://gitforwindows.org/" class="external-link" target="_blank">Git Bash</a>):

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 44why, one step back
44

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 45–46why, one step back
45<div class="termy">
46

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 47–49why, one step back
47```console
48$ source ./env/Scripts/activate49```

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 50why, one step back
50

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 51–52why, one step back
51</div>
52

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 53why, one step back
53To check it worked, use:

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 54why, one step back
54

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 55–56why, one step back
55<div class="termy">
56

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 57–58why, one step back
57```console
58$ which pip

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 59why, one step back
59

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 60–61why, one step back
60some/directory/typer/env/bin/pip
61```

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 62why, one step back
62

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 63–64why, one step back
63</div>
64

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 65why, one step back
65If it shows the `pip` binary at `env/bin/pip` then it worked. 🎉

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 66why, one step back
66

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 67why, one step back
67Or in Windows PowerShell:

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 68why, one step back
68

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 69–70why, one step back
69<div class="termy">
70

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 71–72why, one step back
71```console
72$ Get-Command pip

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 73why, one step back
73

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 74why, one step back
74some/directory/typer/env/bin/pip

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 75–76why, one step back
75```
76

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 77–78why, one step back
77</div>
78

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 79–80why, one step back
79!!! tip
80 Every time you install a new package with `pip` under that environment, activate the environment again.

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 81why, one step back
81

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 82why, one step back
82 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.

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 83why, one step back
83

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 84why, one step back
84### Flit

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 85why, one step back
85

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 86why, one step back
86**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.

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 87why, one step back
87

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 88why, one step back
88After activating the environment as described above, install `flit`:

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 89why, one step back
89

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 90–91why, one step back
90<div class="termy">
91

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 92–93why, one step back
92```console
93$ pip install flit

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 94–95why, one step back
94
95---> 100%

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 96why, one step back
96```

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 97why, one step back
97

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 98–99why, one step back
98</div>
99

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 100why, one step back
100Now re-activate the environment to make sure you are using the `flit` you just installed (and not a global one).

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 101why, one step back
101

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 102–103why, one step back
102And now use `flit` to install the development dependencies:
103

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 104–105why, one step back
104<div class="termy">
105

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

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

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 108–109why, one step back
108
109---> 100%

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 110–111why, one step back
110```
111

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 112–125why, one step back
112</div>
113114If you are on Windows, use `--pth-file` instead of `--symlink`:115116<div class="termy">117118```console119$ flit install --deps develop --pth-file120121---> 100%122```123124</div>125

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 126–135why, one step back
126It will install all the dependencies and your local Typer in your local environment.
127128#### Using your local Typer129130If 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.131132And if you update that local Typer source code, as it is installed with `--symlink`, when you run that Python file again, it will use the fresh version of Typer you just edited.133134That way, you don't have to "install" your local version to be able to test every change.135

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 136–139why, one step back
136### Format
137138There is a script that you can run that will format and clean all your code:139

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 140–141why, one step back
140<div class="termy">
141

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 142–143why, one step back
142```console
143$ bash scripts/format.sh

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 144–145why, one step back
144```
145

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 146–147why, one step back
146</div>
147

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 148–149why, one step back
148It will also auto-sort all your imports.
149

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

line 150why, one step back
150For 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).

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 151why, one step back
151

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 152why, one step back
152### Format imports

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 153why, one step back
153

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 154why, one step back
154There is another script that formats all the imports and makes sure you don't have unused imports:

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 155why, one step back
155

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 156–157why, one step back
156<div class="termy">
157

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 158–160why, one step back
158```console
159$ bash scripts/format-imports.sh160```

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 161why, one step back
161

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 162–163why, one step back
162</div>
163

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 164–169why, one step back
164As 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.
165166## Docs167168The documentation uses <a href="https://www.mkdocs.org/" class="external-link" target="_blank">MkDocs</a>.169

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 170–179why, one step back
170All the documentation is in Markdown format in the directory `./docs`.
171172Many of the tutorials have blocks of code.173174In most of the cases, these blocks of code are actual complete applications that can be run as is.175176In fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs/src/` directory.177178And those Python files are included/injected in the documentation when generating the site.179

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 180why, one step back
180### Docs for tests

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 181–187why, one step back
181
182Most of the tests actually run against the example source files in the documentation.183184This helps making sure that:185186* The documentation is up to date.187* The documentation examples can be run as is.

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 188why, one step back
188* Most of the features are covered by the documentation, ensured by test coverage.

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 189–191why, one step back
189
190During local development, there is a script that builds the site and checks for any changes, live-reloading:191

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 192–193why, one step back
192<div class="termy">
193

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 194–195why, one step back
194```console
195$ bash scripts/docs-live.sh

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 196–200why, one step back
196
197<span style="color: green;">[INFO]</span> - Building documentation...198<span style="color: green;">[INFO]</span> - Cleaning site directory199<span style="color: green;">[INFO]</span> - Documentation built in 2.74 seconds200<span style="color: green;">[INFO]</span> - Serving on http://127.0.0.1:8008

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 201–202why, one step back
201```
202

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 203–204why, one step back
203</div>
204

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 205why, one step back
205It will serve the documentation on `http://127.0.0.1:8008`.

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

lines 206–208why, one step back
206
207That way, you can edit the documentation/source files and see the changes live.208

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 209why, one step back
209## Tests

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 210why, one step back
210

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 211why, one step back
211There is a script that you can run locally to test all the code and generate coverage reports in HTML:

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 212why, one step back
212

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 213–214why, one step back
213<div class="termy">
214

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 215–216why, one step back
215```console
216$ bash scripts/test-cov-html.sh

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 217why, one step back
217```

:bug: Fix Bash completion install to .bashrc (#81)Sebastián Ramírezbefore adoptiond90344d

lines 218–219why, one step back
218
219</div>

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 220why, one step back
220

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 221why, one step back
221This 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.

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 222why, one step back
222

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 223why, one step back
223### Tests in your editor

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 224why, one step back
224

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 225why, one step back
225If you want to use the integrated tests in your editor add `./docs/src` to your `PYTHONPATH` variable.

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 226why, one step back
226

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

line 227why, one step back
227For example, in VS Code you can create a file `.env` with:

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 228why, one step back
228

:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411

lines 229–230why, one step back
229```env
230PYTHONPATH=./docs/src

:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f

line 231why, one step back
231```