Skip to content
Myr

contributing.md

This file

Path

docs/contributing.md

231 lines · 5.8 KiB · Markdown

Last changed by

⬆ Upgrade Isort to version 5.x.x (#137)Sebastián Ramírezbefore adoption89ddc35

History of this file

Take it

The walk stopped after 200 commits: lines older than 96731c4 point at it.

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 1–10why, 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}.
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: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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

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

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

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

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

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

line 25why, one step back
25=== "Linux, macOS"

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

line 26why, one step back
26

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 28why, one step back
28

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

lines 29–31why, one step back
29 ```console
30 $ source ./env/bin/activate31 ```

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

line 32why, one step back
32

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 34why, one step back
34

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

line 35why, one step back
35=== "Windows PowerShell"

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

line 36why, one step back
36

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 38why, one step back
38

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

lines 39–41why, one step back
39 ```console
40 $ .\env\Scripts\Activate.ps141 ```

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

line 42why, one step back
42

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 44why, one step back
44

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

line 45why, one step back
45=== "Windows Bash"

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

line 46why, one step back
46

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 48why, one step back
48

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

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

line 50why, one step back
50

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

lines 51–56why, one step back
51 ```console
52 $ source ./env/Scripts/activate53 ```5455 </div>56

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 57–58why, one step back
57To check it worked, use:
58

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

line 59why, one step back
59=== "Linux, macOS, Windows Bash"

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

line 60why, one step back
60

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 62why, one step back
62

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

lines 63–64why, one step back
63 ```console
64 $ which pip

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 65why, one step back
65

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

lines 66–67why, one step back
66 some/directory/typer/env/bin/pip
67 ```

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

line 68why, one step back
68

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 70why, one step back
70

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

line 71why, one step back
71=== "Windows PowerShell"

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 72why, one step back
72

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

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

line 74why, one step back
74

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

lines 75–76why, one step back
75 ```console
76 $ Get-Command pip

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 77why, one step back
77

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

lines 78–79why, one step back
78 some/directory/typer/env/bin/pip
79 ```

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 80why, one step back
80

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

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

line 82why, one step back
82

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

lines 83–84why, one step back
83If it shows the `pip` binary at `env/bin/pip` then it worked. 🎉
84

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 85–95why, one step back
85!!! tip
86 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`:95

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

lines 96–97why, one step back
96<div class="termy">
97

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 98–99why, one step back
98```console
99$ pip install flit

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

lines 100–101why, one step back
100
101---> 100%

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 102–103why, one step back
102```
103

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

lines 104–105why, one step back
104</div>
105

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 106–109why, one step back
106Now 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:109

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

line 110why, one step back
110=== "Linux, macOS"

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

line 111why, one step back
111

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

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

line 113why, one step back
113

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

line 116why, one step back
116

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

lines 117–118why, one step back
117 ---> 100%
118 ```

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

line 119why, one step back
119

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

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

line 121why, one step back
121

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

line 122why, one step back
122=== "Windows"

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

line 123why, one step back
123

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

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

line 125why, one step back
125

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

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

line 127why, one step back
127

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

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

line 130why, one step back
130

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

lines 131–135why, one step back
131 ---> 100%
132 ```133134 </div>135

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 136–141why, one step back
136It 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.141

:heavy_plus_sign: Upgrade Material-Mkdocs (#90)Sebastián Ramírezbefore adoptionce9e08d

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 143–149why, one step back
143
144That 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:149

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

lines 150–151why, one step back
150<div class="termy">
151

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 152–155why, one step back
152```console
153$ bash scripts/format.sh154```155

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

lines 156–157why, one step back
156</div>
157

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

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

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

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

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 161–165why, one step back
161
162### Format imports163164There is another script that formats all the imports and makes sure you don't have unused imports:165

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

lines 166–167why, one step back
166<div class="termy">
167

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 168–171why, one step back
168```console
169$ bash scripts/format-imports.sh170```171

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

lines 172–173why, one step back
172</div>
173

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 174–185why, one step back
174As 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.185

⬆ Upgrade Isort to version 5.x.x (#137)Sebastián Ramírezbefore adoption89ddc35

line 186why, one step back
186In fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs_src/` directory.

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 187–201why, one step back
187
188And 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:201

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

lines 202–203why, one step back
202<div class="termy">
203

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

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

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

lines 206–210why, one step back
206
207<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:8008

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 211–212why, one step back
211```
212

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

lines 213–214why, one step back
213</div>
214

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 215–222why, one step back
215It 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:222

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

lines 223–224why, one step back
223<div class="termy">
224

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 225–227why, one step back
225```console
226$ bash scripts/test-cov-html.sh227```

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

lines 228–229why, one step back
228
229</div>

:sparkles: Docs for Typer CLI (#64)Sebastián Ramírezbefore adoption96731c4

lines 230–231why, one step back
230
231This 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.