Skip to content
Myr

contributing.md

This file

Path

docs/contributing.md

166 lines · 4.9 KiB · Markdown

Last changed by

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

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

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

lines 11–13why, one step back
11```console
12$ python -m venv env13```

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

line 14why, one step back
14

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

lines 15–22why, one step back
15That will create a directory `./env/` with the Python binaries and then you will be able to install packages for that isolated environment.
1617### Activate the environment1819Activate the new environment with:2021```console22$ source ./env/bin/activate

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

lines 23–24why, one step back
23```
24

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

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

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

line 26why, one step back
26

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

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

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

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

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

line 31why, one step back
31Or 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 32why, one step back
32

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

lines 33–35why, one step back
33```console
34$ source ./env/Scripts/activate35```

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

line 36why, one step back
36

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

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

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

line 38why, one step back
38

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

lines 39–40why, one step back
39```console
40$ which pip

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

line 41why, one step back
41

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

lines 42–43why, one step back
42some/directory/typer/env/bin/pip
43```

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

line 44why, one step back
44

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

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

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

line 46why, one step back
46

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

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

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

line 48why, one step back
48

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

lines 49–50why, one step back
49```console
50$ Get-Command pip

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

line 51why, one step back
51

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

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

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

lines 53–54why, one step back
53```
54

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

lines 55–56why, one step back
55!!! tip
56 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 57why, one step back
57

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

line 58why, one step back
58 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 59why, one step back
59

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

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

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

line 61why, one step back
61

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

line 62why, one step back
62**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 63why, one step back
63

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

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

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

line 65why, one step back
65

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

lines 66–68why, one step back
66```console
67$ pip install flit68```

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

line 69why, one step back
69

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

line 70why, one step back
70Now 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 71why, one step back
71

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

lines 72–87why, one step back
72And now use `flit` to install the development dependencies:
7374```console75$ flit install --deps develop --symlink76```7778It will install all the dependencies and your local Typer in your local environment.7980#### Using your local Typer8182If 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.8384And 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.8586That way, you don't have to "install" your local version to be able to test every change.87

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

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

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

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

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

lines 94–97why, one step back
94```
9596It will also auto-sort all your imports.97

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

line 98why, one step back
98For it to sort them correctly, you need to have Typer installed locally in your environment, with the command in the section above:

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

line 99why, one step back
99

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

lines 100–101why, one step back
100```console
101$ flit install --symlink

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

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

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

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

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

line 105why, one step back
105

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

line 106why, one step back
106There 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 107why, one step back
107

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

lines 108–110why, one step back
108```console
109$ bash scripts/format-imports.sh110```

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

line 111why, one step back
111

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

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

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

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

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

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

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

lines 129–135why, one step back
129
130Most of the tests actually run against the example source files in the documentation.131132This helps making sure that:133134* The documentation is up to date.135* The documentation examples can be run as is.

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

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

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

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

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

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

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

lines 142–143why, one step back
142```
143

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

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

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

lines 145–147why, one step back
145
146That way, you can edit the documentation/source files and see the changes live.147

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

line 148why, one step back
148## Tests

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

line 149why, one step back
149

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

line 150why, one step back
150There 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 151why, one step back
151

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

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

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

lines 154–155why, one step back
154```
155

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

line 156why, one step back
156This 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 157why, one step back
157

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

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

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

line 159why, one step back
159

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

line 160why, one step back
160If 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 161why, one step back
161

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

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

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

line 163why, one step back
163

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

lines 164–165why, one step back
164```env
165PYTHONPATH=./docs/src

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

line 166why, one step back
166```