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 fileTake it
:memo: Refactor docs with internal links #38Sebastián Ramírezbefore adoption8d6b201
line 1why, one step back1First, 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 back2:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 3why, one step back3## Developing:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
lines 4–6why, one step back45If 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 back7### Virtual environment with `venv`:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 8why, one step back8:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 9why, one step back9You 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 back10:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 11–13why, one step back11```console12$ python -m venv env13```:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 14why, one step back14:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 15–22why, one step back15That 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 back23```24:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 25why, one step back25Or in Windows' PowerShell::memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 26why, one step back26:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 27–28why, one step back27```console28$ .\env\Scripts\Activate.ps1:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
lines 29–30why, one step back29```30:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 31why, one step back31Or 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 back32:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 33–35why, one step back33```console34$ source ./env/Scripts/activate35```:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 36why, one step back36:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 37why, one step back37To check it worked, use::memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 38why, one step back38:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 39–40why, one step back39```console40$ which pip:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 41why, one step back41:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 42–43why, one step back42some/directory/typer/env/bin/pip43```:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 44why, one step back44:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 45why, one step back45If 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 back46:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 47why, one step back47Or in Windows PowerShell::memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 48why, one step back48:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 49–50why, one step back49```console50$ Get-Command pip:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 51why, one step back51:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 52why, one step back52some/directory/typer/env/bin/pip:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
lines 53–54why, one step back53```54:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 55–56why, one step back55!!! tip56 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 back57:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 58why, one step back58 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 back59:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 60why, one step back60### Flit:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 61why, one step back61:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 62why, one step back62**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 back63:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 64why, one step back64After activating the environment as described above, install `flit`::memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 65why, one step back65:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 66–68why, one step back66```console67$ pip install flit68```:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 69why, one step back69:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 70why, one step back70Now 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 back71:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 72–87why, one step back72And 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 back88### Format8990There 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 back92```console93$ bash scripts/format.sh:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
lines 94–97why, one step back94```9596It will also auto-sort all your imports.97:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 98why, one step back98For 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 back99:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 100–101why, one step back100```console101$ flit install --symlink:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
lines 102–103why, one step back102```103:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 104why, one step back104### Format imports:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 105why, one step back105:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 106why, one step back106There 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 back107:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 108–110why, one step back108```console109$ bash scripts/format-imports.sh110```:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 111why, one step back111:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 112–117why, one step back112As 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 back118All 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 back128### Docs for tests:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
lines 129–135why, one step back129130Most 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 back136* 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 back137138During 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 back140```console141$ bash scripts/docs-live.sh:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
lines 142–143why, one step back142```143:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 144why, one step back144It 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 back145146That 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 back148## Tests:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 149why, one step back149:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 150why, one step back150There 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 back151:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 152–153why, one step back152```console153$ bash scripts/test-cov-html.sh:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
lines 154–155why, one step back154```155:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 156why, one step back156This 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 back157:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 158why, one step back158### Tests in your editor:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 159why, one step back159:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 160why, one step back160If 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 back161:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
line 162why, one step back162For 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 back163:memo: Add contributing guide (#61)Sebastián Ramírezbefore adoptiondd72411
lines 164–165why, one step back164```env165PYTHONPATH=./docs/src:memo: Add first version of docsSebastián Ramírezbefore adoptionc24269f
line 166why, one step back166```